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

Decrease dependencies and maintenance burden #1306

Closed
pksunkara opened this issue Oct 11, 2020 · 9 comments
Closed

Decrease dependencies and maintenance burden #1306

pksunkara opened this issue Oct 11, 2020 · 9 comments
Labels
feature-request New feature or request

Comments

@pksunkara
Copy link

You can reduce the dependency list by removing ansi_term and ansi_colours since console has the same capability (and more since it handles old windows too).

I haven't looked at other dependencies though.

@pksunkara pksunkara added the feature-request New feature or request label Oct 11, 2020
@sharkdp
Copy link
Owner

sharkdp commented Oct 14, 2020

Thank you for the feedback.

The 24-bit => 8-bit color interpolation code comes from bat originally. At some point, we moved it out to a separate ansi_colours crate. Does console really have the same kind of "high quality" 8-bit color interpolation? Or is it some kind of approximation?

@pksunkara
Copy link
Author

We have 256 color support, console-rs/console#72. Is it what you mean?

@sharkdp
Copy link
Owner

sharkdp commented Oct 16, 2020

No. This is what the ansi_colours crate does for us:

ansi_colours is a library which converts between 24-bit sRGB colours and 8-bit colour palette used by ANSI terminals such as xterm on rxvt-unicode in 256-colour mode.

The most common use case is when using 24-bit colours in a terminal emulator which only support 8-bit colour palette. This package allows true-colours to be approximated by values supported by the terminal.

When mapping true-colour into available 256-colour palette (of which only 240 are actually usable), this package tries to balance accuracy and performance. It doesn’t implement the fastest algorithm nor is it the most accurate, instead it uses a formula which should be fast enough and accurate enough for most use-cases.

Or in code:

    // Approximate true-colour by colour in the palette:
    let rgb = (100, 200, 150);
    let index = ansi256_from_rgb(rgb);
    println!("{:?} ~ {:-3} {:?}", rgb, index, rgb_from_ansi256(index));

@pksunkara
Copy link
Author

My bad then, I got confused with the name. ansi_colours probably can't be replaced.

@sharkdp sharkdp closed this as completed Dec 29, 2020
@sharkdp
Copy link
Owner

sharkdp commented Dec 29, 2020

And ansi_term is also a dependency of clap, so switching to console wouldn't really help.

@pksunkara
Copy link
Author

Yeah. Want to note that clap moves to https://github.com/BurntSushi/termcolor in v3.

@sharkdp
Copy link
Owner

sharkdp commented Dec 29, 2020

Thank you for the note. I guess there is a ticket somewhere documenting that decision and the reasons behind it? I'd be interested to read that.

@pksunkara
Copy link
Author

clap-rs/clap#836

@pksunkara
Copy link
Author

I also want to note that it needed quite a bit of architecture refactor in clap since the philosophy on how the output is constructed is a bit different compared to console or ansi_term.

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

No branches or pull requests

2 participants