yzhong52 / ascii_tree

A command line tool for drawing tree structures with ascii characters.
https://crates.io/crates/astree
18 stars 1 forks source link

horizontal layout without boxes #23

Open nkh opened 1 year ago

nkh commented 1 year ago

Any chance to have a --style none which would not add boxes? even on a 200 characters wide terminal it's difficult to print anything that more than a few elements wide

yzhong52 commented 1 year ago

Is this what you are thinking about?

     Root Node  
    ╭────┴─────╮
  Child      Child  
   (1)        (2)   
nkh commented 1 year ago

yes, a tree but without boxes

yzhong52 commented 1 year ago

So what we need to change is this file:

https://github.com/yzhong52/ascii_tree/blob/main/src/tree/vertical.rs#L144

Either pass in another variable:

pub fn render(&self, style: &BoxDrawings, boxless: bool) -> String {

or make BoxDrawings Optional:

pub fn render(&self, style: Optinal<BoxDrawings>) -> String {

And based on that, change some measuring code such as:

https://github.com/yzhong52/ascii_tree/blob/main/src/tree/vertical.rs#L62


On top of that, if you looking to minimize horizontal space, there is this constant that is set to 2, meaning the space between children is two white spaces. We can make that a argument for the CLI as well --spacing=0 will make the output chart very tight.

https://github.com/yzhong52/ascii_tree/blob/main/src/tree/vertical.rs#L8


Would you be interested in giving those a try?

nkh commented 1 year ago

No, I'm not interested ... but the reason is that I don't program in rust (yet) :)

I'm working on https://github.com/nkh/P5-App-Asciio where I'm planning to list a set of utilities that can be use to generate elements. There are plenty utilities generating vertical layout but few generating horizontal layout.

Here you can see why the larger ooutput is not very usable for more than a handful of nodes.

screenshot_2023-03-02_15-00-26

yzhong52 commented 1 year ago

Cool, thanks for sharing the motivations :)

I can work on that. But it won't fully solve your problem though.

With you example, it will only save 10 chars (|), and that won't be enough to draw the entire tree. I can add another option to wrap text automatically maybe.

Could you c/p me your input? I can use that for testing later.

nkh commented 1 year ago

true it won't save much in this example (https://github.com/nkh/P5-App-Asciio/blob/master/README.md) but people can tweak their input, and having the boxes or not is a good option.

it would be interesting to look at other algorithms that pack the horizontal tree better by using free space (nothing under 'interface' and 'Exporting to ASCII) https://cs.brown.edu/people/rtamassi/gdhandbook/chapters/trees.pdf, http://llimllib.github.io/pymag-trees/ and a million other ...

I did notice that GUI, TUI, SYNOPSIS, DESCRIPTION are not part of the tree, IE: level one entries are not under a virtual root which makes the graph ... vertical too

yzhong52 commented 1 year ago

true it won't save much in this example (https://github.com/nkh/P5-App-Asciio/blob/master/README.md) but people can tweak their input, and having the boxes or not is a good option.

Oh, I didn't realize that it is from the readme lol.

it would be interesting to look at other algorithms that pack the horizontal tree better by using free space (nothing under 'interface' and 'Exporting to ASCII) https://cs.brown.edu/people/rtamassi/gdhandbook/chapters/trees.pdf, http://llimllib.github.io/pymag-trees/ and a million other ...

Yep, absolutely. There are certainly more ways to compact this :)

I did notice that GUI, TUI, SYNOPSIS, DESCRIPTION are not part of the tree, IE: level one entries are not under a virtual root which makes the graph ... vertical too

Yep, for vertical - it is using a dot for root. For horizontal, I don't really want to create an artificial root.

yzhong52 commented 1 year ago

This is what I have for now. With your input, the width of the output is 169 chars.

cargo run -- vertical --input examples/readme.md --width 10

Screen Shot 2023-03-02 at 9 05 07 PM

Edit: https://github.com/yzhong52/ascii_tree/pull/24

yzhong52 commented 1 year ago

I also removed the horizontal spacing, since that's trivial to do:

cargo run -- vertical --input examples/readme.md --width 10 --spacing 0

Screen Shot 2023-03-02 at 9 31 44 PM

That makes it 149 chars.

Edit: https://github.com/yzhong52/ascii_tree/pull/25

nkh commented 1 year ago

great, 20 chars is already a lot. removing the bozes should remove another 40 chars, so a total of around 30%