ruby-cli-tree
A command line printer of tree structures (e.g. directory tree) written in Ruby.
This library can be used to build a tree structure, and render or print it like an ASCII graph.
e.g. it can be used to implement a directory tree printer just like the Linux utility tree. See bin/tree.rb
Installation
gem install cli-tree
Usage
require 'cli-tree'- Create a TreeNode:
tree = TreeNode.new(node_name, children = []) - Add more TreeNode objects to
children:tree.children << child_node - Add more TreeNode objects to
child_node, and so on. - Call
puts tree.renderortree.printto print the tree.
Example
require 'cli-tree'
tree = TreeNode.new("root", [
TreeNode.new("foo", [
TreeNode.new("bar"),
TreeNode.new("baz")
])
])
puts tree.render
# or simply
tree.print
Output:
root
└── foo
├──
└── baz