clicolors-control
clicolors-control copied to clipboard
Colors render incorrectly after running command
Submitted the same issue in mitsuhiko/console#47, but clicolors-control is upstream and experiences it to. So the issue is probably to be fixed here.
As mentioned in the other issue, running a command using std::process::Command
, affects any colors rendered after.
- In Git Bash the
\u{1b}[2m
(.dim()
in console) renders as if no color was applied. However, after runninggit diff
usingstd::process::Command
, then the color is rendered correctly. - On the other hand, in CMD and Powershell, then after running
git diff
then the ANSI codes appear literally in the output.
Git Bash
CMD
Renders the same in PowerShell.
Minimal, Reproducible Example
use std::process::Command;
// clicolors-control = "1.0.1"
fn main() {
assert!(clicolors_control::colors_enabled());
println!("Foo \u{1b}[36mBar\u{1b}[0m Baz"); // Cyan
println!("Foo \u{1b}[2mBar\u{1b}[0m Baz"); // Dim
println!();
// Colors render incorrectly if git diff is executed
Command::new("git").arg("diff").status().unwrap();
assert!(clicolors_control::colors_enabled());
println!("Foo \u{1b}[36mBar\u{1b}[0m Baz"); // Cyan
println!("Foo \u{1b}[2mBar\u{1b}[0m Baz"); // Dim
println!();
}
Manually calling configure_terminal()
after having executed a command, fixes the CMD and PowerShell issue.
Command::new("git").arg("diff").status().unwrap();
clicolors_control::configure_terminal();
I'm not sure if this is fixable. This seems to be a limitation in how the ANSI terminal support on windows works :(
Maybe just a note in the docs mentioning child processes and how it can affect the state of the console. Thus needing to call configure_terminal()
after having executed a process.