1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
use highlighting::Style;
use std::fmt::Write;
#[cfg(feature = "parsing")]
use parsing::ScopeStackOp;
pub fn as_24_bit_terminal_escaped(v: &[(Style, &str)], bg: bool) -> String {
let mut s: String = String::new();
for &(ref style, text) in v.iter() {
if bg {
write!(s,
"\x1b[48;2;{};{};{}m",
style.background.r,
style.background.g,
style.background.b)
.unwrap();
}
write!(s,
"\x1b[38;2;{};{};{}m{}",
style.foreground.r,
style.foreground.g,
style.foreground.b,
text)
.unwrap();
}
s
}
#[cfg(feature = "parsing")]
pub fn debug_print_ops(line: &str, ops: &[(usize, ScopeStackOp)]) {
for &(i, ref op) in ops.iter() {
println!("{}", line.trim_right());
print!("{: <1$}", "", i);
match *op {
ScopeStackOp::Push(s) => {
println!("^ +{}", s);
}
ScopeStackOp::Pop(count) => {
println!("^ pop {}", count);
}
ScopeStackOp::Clear(amount) => {
println!("^ clear {:?}", amount);
}
ScopeStackOp::Restore => println!("^ restore"),
ScopeStackOp::Noop => println!("noop"),
}
}
}