-
Notifications
You must be signed in to change notification settings - Fork 3
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
"reset" doesn't seem to work #1
Comments
I only can access Linux and Windows 10, can it be reproduced there? I'm wondering if calling Lines 156 to 160 in 08466a4
|
#[test]
fn reset_test() {
let mut collector = ColorCollector(Vec::new());
write_ansi(&mut collector, b"\x1b[38;5;14mI am colored\x1b[0mI am reset\n").unwrap();
let mut cs = ColorSpec::new();
cs.set_fg(Some(Color::Ansi256(14)));
assert_eq!(collector.0, &[
Element::ColorSpec(cs),
Element::Text(b"I am colored".to_vec()),
Element::Reset,
Element::Text(b"I am reset\n".to_vec()),
]);
}
#[derive(Debug)]
struct ColorCollector(Vec<Element>);
impl WriteColor for ColorCollector {
fn supports_color(&self) -> bool { true }
fn set_color(&mut self, spec: &ColorSpec) -> std::io::Result<()> {
self.0.push(Element::ColorSpec(spec.clone()));
Ok(())
}
fn reset(&mut self) -> std::io::Result<()> {
self.0.push(Element::Reset);
Ok(())
}
}
impl std::io::Write for ColorCollector {
fn write(&mut self, buf: &[u8]) -> std::io::Result<usize> {
let len = buf.len();
self.0.push(Element::Text(Vec::from(buf)));
Ok(len)
}
fn flush(&mut self) -> std::io::Result<()> {
Ok(())
}
} What's interesting is that the cc @BurntSushi, is this maybe a bug in use termcolor::*;
use std::io::Write;
let mut stdout = StandardStream::stdout(ColorChoice::Always);
stdout.set_color(ColorSpec::new().set_fg(Some(Color::Green))).unwrap();
writeln!(&mut stdout, "green text!").unwrap();
stdout.set_color(ColorSpec::new().set_bg(Some(Color::Green))).unwrap();
writeln!(&mut stdout, "green back").unwrap();
stdout.reset().unwrap(); Results in the ANSI: Whereas on Windows console, it is: Notice that on ANSI, the green background has white text, but in Windows it is green on green. Should this function be more careful about resetting the fg/bg? |
AFAIK, there is no way to reset the console like there is in ANSI. In any case, on modern versions of Windows, the console writer isn't used. ANSI is used instead. |
For context, this is trying to fix it so that Windows 7/8 continues to work with Cargo/rustc, since those are still technically tier 1 platforms. I'm not sure what you mean by not being able to reset the console. If I call |
The caveat I'm referring to is here, where there is no actual "reset" API in the console APIs. Resetting is a library implemented feature: https://docs.rs/wincolor/1.0.2/x86_64-pc-windows-msvc/wincolor/struct.Console.html#method.reset I will be AFK for the next few days so I won't be able to look into this in detail. |
Ping @BurntSushi were you able to look at this issue? |
No. I have a pretty big backlog right now, and this is pretty low on my list. I would recommend that someone else investigate. |
The reset sequence
ESC [ 0 m
doesn't seem to do anything.Given this string:
Results in just a single color on win7/8:
I would submit a PR, but I can't quite figure out what the reset code is trying to do. It sets
self.reset
, but then does nothing with it. It also doesn't resetexpected
if it is already reset, which I don't understand.The text was updated successfully, but these errors were encountered: