Vinilux 0 Posted April 29, 2016 Share Posted April 29, 2016 TREE command Updated Added a new rewritten file called tree2.lua. You can test both tree.lua and tree2.lua. tree2.lua is a bit slower version but it shows the tree properly unlike the other version (tree.lua). At the moment the command does not sopport parameters. You can help to add things to the command if you like. Even though this is a little program, you could give some ideas for display or parameters. @GreaseMonkey Thank you for your comment There is still one problem with piping even thouth I changed to io library from "term". I thought "tree | more" or "tree | less" would work here but in OC it says the command is "more <filename>" but if you do that obviously it prints the file, not the output. I thinkinf if it's possible to make the program create a file with the output instead of outputting the result directly and then more the file and once finished destroy the file maybe. Instructions Everyone knows this, but just in case, you have to copy the tree.lua or tree2.lua in /bin/ in order for the program to work from every directory. Download https://github.com/Vinilux/OpenComputers---tree Quote Link to post Share on other sites
GreaseMonkey 7 Posted April 29, 2016 Share Posted April 29, 2016 If you want it to be pipable, use io.write() instead of term.write(). Otherwise, pretty solid first Lua program. How long have you been programming for? EDIT: Also, consider using sublevel as an optional argument to list_tree, e.g. local function list_tree(path, sublevel) sublevel = sublevel or 1 Quote Link to post Share on other sites
Vinilux 0 Posted April 29, 2016 Author Share Posted April 29, 2016 If you want it to be pipable, use io.write() instead of term.write(). Otherwise, pretty solid first Lua program. How long have you been programming for? EDIT: Also, consider using sublevel as an optional argument to list_tree, e.g. local function list_tree(path, sublevel) sublevel = sublevel or 1 Lua not much. Programming in general counting since I started learning, for 4 years more or less, but I've never done anything too big yet. By passing the sublevel as an optional parameter, with the purpse of not using it as a closure, right? Also I noticed that when there are no more items in one parent, and childrens are displayed, lines for those parents continue to be displayed even though they have no more direct items. I don't know how to explain it. For example I create this structure, and you'll see what i meen folder1 -> item1, item2, item3 folder2 - item1 If displayed in order, line for folder 1 will continue to be drawn even though all items will have been printed, while folder 2 items draw, and that line will have no connection, I don't know if this matters a lot. Quote Link to post Share on other sites