01mf02 / jaq

A jq clone focussed on correctness, speed, and simplicity
MIT License
2.61k stars 63 forks source link

Problem on console without support of color. #177

Closed hellishvictor closed 3 weeks ago

hellishvictor commented 2 months ago

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 commented 2 months ago

This happens here: https://github.com/01mf02/jaq/blob/1699a7d1fc7ede6f728fcaa243f011137fcc220a/jaq/src/main.rs#L489-L500

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 commented 1 month ago

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 commented 4 weeks ago

@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 commented 4 weeks ago

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 commented 3 weeks ago

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 commented 3 weeks ago

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

Thank you very much!

01mf02 commented 3 weeks ago

Great, I'm happy to hear it! :)