Jump to content
  • Sky
  • Blueberry
  • Slate
  • Blackcurrant
  • Watermelon
  • Strawberry
  • Orange
  • Banana
  • Apple
  • Emerald
  • Chocolate
  • Charcoal
Vinilux

Tree command program

Recommended Posts

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

post-2747-0-91683800-1462113460_thumb.png

Link to post
Share on other sites

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
Link to post
Share on other sites

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.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use and Privacy Policy.