Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Colouring the tree lines #18

Open
jonathanj opened this issue Jan 7, 2020 · 0 comments
Open

Colouring the tree lines #18

jonathanj opened this issue Jan 7, 2020 · 0 comments

Comments

@jonathanj
Copy link
Collaborator

jonathanj commented Jan 7, 2020

In jonathanj/eliottree#76, a suggestion has been made to color the tree lines. I've tried implementing a hacky solution via Options (on master) without modifying tree_format but it turns out to be quite tricky to guess when to change the colour.

I've tried a couple of modifications and would like some advice on whether any of them seem like things that would fit into this package.

1. Options factory

Instead of format_tree accepting an Options instance, rather accept a function (taking the current tree depth) that returns an Options instance. My factory implementation uses the depth to pick a colour from a smaller set and wraps all line drawing characters in properties that are decorated with that colour.

This keeps the concept of colour outside of this package's knowledge.

2. Introduce a Options.next_color method

Fetches the next colour on each call to _format_tree and wraps all line drawing characters with it.

The problem with this method is that sub-trees of siblings will be different colours, and thus the colours do not form clear columns, maybe this is useful in same cases but in eliottree's case it's more useful to have colours run strictly vertically.

3. Introduce a format_prefix argument

format_node formats the node, format_prefix would format the prefix, likely only accepting input describing the kind of prefix such as fork, last and probably depth.

This actually obviates the need for Options (at least as an argument to format_tree) because format_prefix is wholly in charge of returning the prefix string based on what kind of branch to draw.

This option is also hypothetical because I didn't actually get around to implementing it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant