|
|
|
@ -17,33 +17,7 @@ fn main() {
|
|
|
|
|
stream.write("\r\n".as_ref()).unwrap();
|
|
|
|
|
let mut buf = String::new();
|
|
|
|
|
stream.read_to_string(&mut buf);
|
|
|
|
|
let mut start = true;
|
|
|
|
|
let mut skip_to_end = false;
|
|
|
|
|
for c in buf.chars() {
|
|
|
|
|
if start {
|
|
|
|
|
match c {
|
|
|
|
|
'i' => print!("\x1B[93m"),
|
|
|
|
|
'h' => print!("\x1B[94m"),
|
|
|
|
|
'0' => print!("\x1B[95m"),
|
|
|
|
|
'1' => print!("\x1B[96m"),
|
|
|
|
|
_ => print!("\x1B[0m"),
|
|
|
|
|
}
|
|
|
|
|
start = false
|
|
|
|
|
} else if skip_to_end {
|
|
|
|
|
if c == '\n' {
|
|
|
|
|
println!("");
|
|
|
|
|
start = true;
|
|
|
|
|
skip_to_end = false;
|
|
|
|
|
}
|
|
|
|
|
} else if c == '\t' {
|
|
|
|
|
skip_to_end = true;
|
|
|
|
|
} else {
|
|
|
|
|
print!("{}", c);
|
|
|
|
|
if c == '\n' {
|
|
|
|
|
start = true
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
render(&buf);
|
|
|
|
|
|
|
|
|
|
for c in stdin.keys() {
|
|
|
|
|
// Clear the current line.
|
|
|
|
@ -82,3 +56,33 @@ fn main() {
|
|
|
|
|
eprintln!("err: {}", err);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn render(buf: &str) {
|
|
|
|
|
let mut start = true;
|
|
|
|
|
let mut skip_to_end = false;
|
|
|
|
|
for c in buf.chars() {
|
|
|
|
|
if start {
|
|
|
|
|
match c {
|
|
|
|
|
'i' => print!("\x1B[93m"),
|
|
|
|
|
'h' => print!("\x1B[94m"),
|
|
|
|
|
'0' => print!("\x1B[95m"),
|
|
|
|
|
'1' => print!("\x1B[96m"),
|
|
|
|
|
_ => print!("\x1B[0m"),
|
|
|
|
|
}
|
|
|
|
|
start = false
|
|
|
|
|
} else if skip_to_end {
|
|
|
|
|
if c == '\n' {
|
|
|
|
|
println!("\r");
|
|
|
|
|
start = true;
|
|
|
|
|
skip_to_end = false;
|
|
|
|
|
}
|
|
|
|
|
} else if c == '\t' {
|
|
|
|
|
skip_to_end = true;
|
|
|
|
|
} else {
|
|
|
|
|
print!("{}", c);
|
|
|
|
|
if c == '\n' {
|
|
|
|
|
start = true
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|