Representing a tree with ASCII or Unicode characters
Representing trees with text and a monospaced font is something I need often need to do (documentation, raising issues, …).
If your tree consists of folders and files on the filesystem, there are utilities to do it (check the tree
command).
Different sets of characters can be used to represent the tree.
Unicode characters
mySite
├──css
│ └──page.css
├──images
│ └──img.svg
├──index.html
├──js
│ └──empty.js
├──other
│ └──folder
│ └──page.html
├──page1.html
└──sub
└──page2.html
- A node is using:
├
(Box Drawings Light Vertical) combined with two─
(Box Drawings Light Horizontal) - The last node is using:
└
(Box Drawings Light Up and Right) combined with two─
(Box Drawings Light Horizontal) - To indent lines, if more nodes are coming:
│
(Box Drawings Light Vertical)
ASCII characters
mySite
+---css
| \---page.css
+---images
| \---img.svg
+---index.html
+---js
| \---empty.js
+---other
| \---folder
| \---page.html
+---page1.html
\---sub
\---page2.html
- A node is using:
+---
- The last node is using:
\---
- To indent lines, if more nodes are coming:
|
See also
- Generate ASCII folder structures on Windows with Tree
- If you are looking for a Java implementation, the code in this StackOverflow answer helped me to start.