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

feat(tree): Color the output #15242

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

feat(tree): Color the output #15242

wants to merge 4 commits into from

Conversation

epage
Copy link
Contributor

@epage epage commented Feb 27, 2025

What does this PR try to resolve?

This is an experiment to find ways to make cargo tree output easier to grok. I find too many details are hard to spot because everything looks the same.

image

The goal is to make it easier to scan the output for relevant details. So far, this approach seems the most viable. Knowing what type of edges led to where you are provides useful context for scrolling through large lists of dependencies.

How should we test and review this PR?

I had considered styling normal dependency edges but there isn't a header to clarify what they mean, so I decided to match the package name as that is the header. So this didn't buy as much as I had hoped, especially since dimmed lines aren't obvious with my terminal. Maybe if we used different unicode graph characters.

Instead of coloring the "this is elided" (*), I had considered using a unicode character that looks like its pointing from that item up. I only found one that looked close to that but the origin for the arrow was bottom aligned, rather than center aligned and it looked off.

Alternatives considered

  • Once an edge is marked with dev or build dependencies, all future edges inherit it
    • While this makes it clear what section you are in, so does the outer most line
  • Feature edges are the color of the edges that led to them
    • Unsure of value either way
    • This might get weird with --invert
  • Style local nodes different than non-local
    • With the format string being user customizable, I'm concerned with styling over or within user styling
  • Rainbow packages: For every package in the same namespace (.split_once("::").0) or prefix (.split_once(['-','_']).0), assign a color (maybe only for the top N packages to reduce duplicate colors)
    • Would help a lot with gix-* and similar other cases
    • If we cap the number of participating packages, would need care to work with --depth

(of course,. these could be mixed)

Additional information

@rustbot
Copy link
Collaborator

rustbot commented Feb 27, 2025

r? @ehuss

rustbot has assigned @ehuss.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@epage epage marked this pull request as draft February 27, 2025 22:35
@rustbot rustbot added Command-tree S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Feb 27, 2025
@rustbot

This comment has been minimized.

@epage epage force-pushed the tree-color branch 2 times, most recently from 7bdabca to 61eb729 Compare February 28, 2025 14:57
@epage epage marked this pull request as ready for review February 28, 2025 15:07
@epage epage force-pushed the tree-color branch 2 times, most recently from d8eb809 to 14a72df Compare February 28, 2025 15:38
@weihanglo
Copy link
Member

  • Once an edge is marked with dev or build dependencies, all future edges inherit it
    • While this makes it clear what section you are in, so does the outer most line
  • Feature edges are the color of the edges that led to them
    • Unsure of value either way
    • This might get weird with --invert

Also need to think about artifact dependencies, which make the color choice more chaos 😬. Maybe, the color should follow on the package being inspected via -p, not its direct dependant.

As for features, what about give (feature-name) a color, instead of coloring the tree.

And yeah, --invert is tricky, We can also color the tree invert, but then I am not sure which color the --invert <root> node shall be, if there are multiple dependant.

Copy link
Member

@weihanglo weihanglo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, though I'm not sure if everyone agrees. Should we start with nightly only first so we can iterate on the design?
So after some time, we'll have multiple nightly toolchains to compare different colorschemes all at once.

@epage
Copy link
Contributor Author

epage commented Mar 1, 2025

Also need to think about artifact dependencies, which make the color choice more chaos 😬. Maybe, the color should follow on the package being inspected via -p, not its direct dependant.

I assume those are regular edges. However, it might be interesting to draw those as dashed or something.

As for features, what about give (feature-name) a color, instead of coloring the tree.

That is part of the user-templated string and the user could be adding their own coloring which could make things messy. We could possibly detect user colors and make our own conditioned on that. I decided to just punt on any styling of user-formatted text for now.

Looks good to me, though I'm not sure if everyone agrees. Should we start with nightly only first so we can iterate on the design?

Nightly only is a bit annoying with some of the compile-time constants being done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Command-tree S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants