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

Problem on console without support of color. #177

Closed
hellishvictor opened this issue May 5, 2024 · 7 comments
Closed

Problem on console without support of color. #177

hellishvictor opened this issue May 5, 2024 · 7 comments

Comments

@hellishvictor
Copy link

Hi, I'm a user of Win 7 x64 and with cmd I have to use the "--color never" option, but it get bypassed when there's an error and shows:

←[31mError:←[0m undefined filter ←[38;5;246m╭←[0m←[38;5;246m─←[0m←[38;5;246m[←[0m<unknown>:1:14←[38;5;246m]←[0m ←[38;5;246m│←[0m ←[38;5;246m1 │←[0m ←[38;5;249m.←[0m←[38;5;249m[←[0m←[38;5;249m]←[0m←[38;5;249m ←[0m←[38;5;249m|←[0m ←[38;5;249m ←[0m←[38;5;249m.←[0m←[38;5;249mn←[0m←[38;5;249ma←[0m←[38;5;249mm←[0m←[38;5;249me←[0m←[38 ;5;249m,←[0m←[38;5;249m ←[0m←[31me←[0m←[31mv←[0m←[31me←[0m←[31mn←[0m←[31mt←[0m←[31ms←[0m←[38;5;249m[ ←[0m←[38;5;249m]←[0m ←[38;5;240m │←[0m ←[31m─←[0m←[31m─←[0m←[31m─←[0m←[31m┬←[0m←[31m─←[0m←[31m─←[0m ←[38;5;240m │←[0m ←[31m╰←[0m←[31m─←[0m←[31m─←[0m←[31m─←[0m←[31m─←[0m undefined fil ter ←[38;5;246m───╯←[0m

Cheers.

@kklingenberg
Copy link
Contributor

This happens here:

jaq/jaq/src/main.rs

Lines 489 to 500 in 1699a7d

fn report<'a>(e: chumsky::error::Simple<String>) -> ariadne::Report<'a> {
use ariadne::{Color, Fmt, Label, Report, ReportKind};
use chumsky::error::SimpleReason;
// color error messages only if we are on a tty
let isatty = atty::is(atty::Stream::Stderr);
let (red, yellow) = if isatty {
(Color::Red, Color::Yellow)
} else {
(Color::Unset, Color::Unset)
};
let config = ariadne::Config::default().with_color(isatty);

Sadly this is part of a trait implementation for std::process::Termination and I can't find a neat way of propagating the --color cli option to this call. Making the cli options global would do it (as in using OnceCell) but that's a big change. Another path would be to try the supports_color crate.

@hellishvictor
Copy link
Author

Another path would be to try the supports_color crate.

That would be fine, I do have the NO_COLOR variable included on my environment, because a lot of CLI out there use it.

@01mf02
Copy link
Owner

01mf02 commented Jun 18, 2024

@hellishvictor, thanks for your bug report. This should be corrected by my latest PR.

@kklingenberg, the way I took to propagate color settings was to call yansi::enable.

@hellishvictor
Copy link
Author

I've compiled it and that fixes the #183, but when I added a plus sign by accident on the filter (curl -s http://programminghistorian.org/assets/jq_rkm.json | jaq --color never .[]+), it showed here:

←[31mError:←[0m Unexpected end of input, expected {, if, try, -, ", ., [, .., ( 3 8;5;246m╭←[0m←[38;5;246m─←[0m←[38;5;246m[←[0m<unknown>:1:5←[38;5;246m]←[0m ←[38;5;246m│←[0m ←[38;5;240m │←[0m ←[38;5;246m───╯←[0m

@01mf02
Copy link
Owner

01mf02 commented Jun 19, 2024

I've compiled it and that fixes the #183, but when I added a plus sign by accident on the filter (curl -s http://programminghistorian.org/assets/jq_rkm.json | jaq --color never .[]+), it showed here:

←[31mError:←[0m Unexpected end of input, expected {, if, try, -, ", ., [, .., ( 3 8;5;246m╭←[0m←[38;5;246m─←[0m←[38;5;246m[←[0m<unknown>:1:5←[38;5;246m]←[0m ←[38;5;246m│←[0m ←[38;5;240m │←[0m ←[38;5;246m───╯←[0m

I believe that you are not using the newest version on Git, because the newest version does never color the starting "Error:" string, yet in the output you posted, we can see ←[31mError:←[0m, which indicates that it is colored.
Can you confirm my hypothesis?

@hellishvictor
Copy link
Author

Ok, I've downloaded the master again and compiled it, and this time it works fine:
sshot-1

Thank you very much!

@01mf02
Copy link
Owner

01mf02 commented Jun 20, 2024

Great, I'm happy to hear 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

3 participants