fmt
This commit is contained in:
parent
51c0ab6012
commit
e1a46d5fb5
@ -44,24 +44,25 @@ pub fn pos_raw() -> io::Result<(u16, u16)> {
|
||||
}
|
||||
|
||||
// Read rows and cols through a ad-hoc integer parsing function
|
||||
let read_num: fn() -> Result<(i32, char), Error> = || -> Result<(i32, char), Error> {
|
||||
let mut num = 0;
|
||||
let mut c: char;
|
||||
let read_num: fn() -> Result<(i32, char) -> Result<(i32, char), Error> =
|
||||
|| -> Result<(i32, char), Error> {
|
||||
let mut num = 0;
|
||||
let mut c: char;
|
||||
|
||||
loop {
|
||||
let mut buf = [0u8; 1];
|
||||
io::stdin().read_exact(&mut buf)?;
|
||||
c = buf[0] as char;
|
||||
if let Some(d) = c.to_digit(10) {
|
||||
num = if num == 0 { 0 } else { num * 10 };
|
||||
num += d as i32;
|
||||
} else {
|
||||
break;
|
||||
loop {
|
||||
let mut buf = [0u8; 1];
|
||||
io::stdin().read_exact(&mut buf)?;
|
||||
c = buf[0] as char;
|
||||
if let Some(d) = c.to_digit(10) {
|
||||
num = if num == 0 { 0 } else { num * 10 };
|
||||
num += d as i32;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ok((num, c))
|
||||
};
|
||||
Ok((num, c))
|
||||
};
|
||||
|
||||
// Read rows and expect `;`
|
||||
let (rows, c) = read_num()?;
|
||||
|
@ -48,7 +48,7 @@ impl ITerminalColor for AnsiColor {
|
||||
if new_color == Color::Reset {
|
||||
ansi_value.push_str("39");
|
||||
return ansi_value;
|
||||
}else {
|
||||
} else {
|
||||
ansi_value.push_str("38;");
|
||||
color = new_color;
|
||||
}
|
||||
@ -57,7 +57,7 @@ impl ITerminalColor for AnsiColor {
|
||||
if new_color == Color::Reset {
|
||||
ansi_value.push_str("49");
|
||||
return ansi_value;
|
||||
}else {
|
||||
} else {
|
||||
ansi_value.push_str("48;");
|
||||
color = new_color;
|
||||
}
|
||||
@ -91,7 +91,7 @@ impl ITerminalColor for AnsiColor {
|
||||
rgb_val = format!("5;{}", val);
|
||||
rgb_val.as_str()
|
||||
}
|
||||
_ => ""
|
||||
_ => "",
|
||||
};
|
||||
|
||||
ansi_value.push_str(color_val);
|
||||
|
@ -31,17 +31,16 @@ pub struct TerminalColor {
|
||||
impl TerminalColor {
|
||||
/// Create new instance whereon color related actions can be performed.
|
||||
pub fn new() -> TerminalColor {
|
||||
// #[cfg(windows)]
|
||||
// let color = if supports_ansi() {
|
||||
// Box::from(AnsiColor::new()) as Box<(dyn ITerminalColor + Sync + Send)>
|
||||
// } else {
|
||||
// WinApiColor::new() as Box<(dyn ITerminalColor + Sync + Send)>
|
||||
// };
|
||||
//
|
||||
// #[cfg(unix)]
|
||||
// let color = AnsiColor::new();
|
||||
#[cfg(windows)]
|
||||
let color = if supports_ansi() {
|
||||
Box::from(AnsiColor::new()) as Box<(dyn ITerminalColor + Sync + Send)>
|
||||
} else {
|
||||
WinApiColor::new() as Box<(dyn ITerminalColor + Sync + Send)>
|
||||
};
|
||||
|
||||
#[cfg(unix)]
|
||||
let color = AnsiColor::new();
|
||||
|
||||
let color = WinApiColor::new() as Box<(dyn ITerminalColor + Sync + Send)>;
|
||||
TerminalColor { color }
|
||||
}
|
||||
|
||||
|
@ -156,7 +156,7 @@ impl ITerminalColor for WinApiColor {
|
||||
const mask: u16 = FG_INTENSITY | FG_RED | FG_GREEN | FG_BLUE;
|
||||
original_color &= !(mask);
|
||||
original_color
|
||||
},
|
||||
}
|
||||
/* WinApi will be used for systems that do not support ANSI, those are windows version less then 10. RGB and 255 (AnsiBValue) colors are not supported in that case.*/
|
||||
Color::Rgb { r: _, g: _, b: _ } => 0,
|
||||
Color::AnsiValue(_val) => 0,
|
||||
|
Loading…
Reference in New Issue
Block a user