use highlighting::Style;
use std::fmt::Write;
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
}
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"),
}
}
}