-
-
Notifications
You must be signed in to change notification settings - Fork 151
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
[refactor] use termcolor crate instead of ansi #156
Comments
Is this refactor started? If not I'd like to take it |
Nope, it is not started. Happy to see you are interested but would you like to provide a high-level plan for the refactor? |
Sure, I'll look into it. |
After doing some research, I found that the usage of // the styles of header and message are different
writeln!(w, "{header} {message}"); should be firstly refactored into write!(w, header);
writeln!(w, " {message}"); So I think the refactor could be split into two steps:
The trade-off is that we would lose some intuitiveness when doing print stuff in the future. What do you think? |
Nice writeup! I wonder if we can test the huge refactor accordingly? If the end user is not impacted by the change, I would opt for termcolor since it also supports windows console API. |
Yeah, we can firstly improve the test coverage, which is currently 60% according to the badge at README, then do the refactor. |
Yeah! Sure! |
It seems that we already have tests, but there is no check for the color. For example ast-grep/crates/cli/src/error.rs Lines 254 to 289 in d9ebbe5
I guess we can use snapshot to avoid hard code such as Shall we use it or just do the hard code in test cases, what do you think? |
Would this also help with fixing color support on Windows? Currently
but I don't know what "console isn't available on Windows" means. I'm on Windows 11 and I always have to manually provide |
I do know if using termcolor should somehow fix Windows usage. Windows Terminal and VSCode terminal accepts ansi color so I believe termcolor supports Windows console API which supports color natively without using ANSI escape code. Unfortunately, I don't have Windows machine to test the behavior of termcolor :( I would try to refactor usage in future so external contributors can test termcolor. |
More specifically, it's accepted by Windows itself (in ConPTY component which other terminals build on) since Windows 10, not by individual apps. Unless you want to support old Windows versions (which hopefully shouldn't be necessary for developers), it makes just defaulting to ANSI colors a much easier cross-platform option. |
There is some Windows API you'll still need to check if colors are supported (e.g. to make sure it's not a redirect or something), but I believe one of these crates should already handle that for you. |
Sounds good. I will investigate it. Changing default color is tracked by #680 |
ansi color is the default color option in Windows since 0.13.1! |
Thanks! |
Using ansi will make some windows client unhappy because cygwin like terminals does not support ansi but using console api.
The text was updated successfully, but these errors were encountered: