fix(report): Align text when tabs are used

Ideally we would provide for more than a space per tab but this at least
gets us better alignment.

Fixes #11
This commit is contained in:
Ed Page 2019-06-22 09:18:03 -06:00
parent a082207283
commit 80aeed1b43

View file

@ -35,6 +35,9 @@ pub fn print_long(msg: Message) {
let hl_indent: String = itertools::repeat_n(" ", msg.col_num).collect(); let hl_indent: String = itertools::repeat_n(" ", msg.col_num).collect();
let hl: String = itertools::repeat_n("^", msg.word.len()).collect(); let hl: String = itertools::repeat_n("^", msg.word.len()).collect();
let line = String::from_utf8_lossy(msg.line);
let line = line.replace("\t", " ");
let stdout = io::stdout(); let stdout = io::stdout();
let mut handle = stdout.lock(); let mut handle = stdout.lock();
@ -53,13 +56,7 @@ pub fn print_long(msg: Message) {
) )
.unwrap(); .unwrap();
writeln!(handle, "{} |", line_indent).unwrap(); writeln!(handle, "{} |", line_indent).unwrap();
writeln!( writeln!(handle, "{} | {}", msg.line_num, line.trim_end()).unwrap();
handle,
"{} | {}",
msg.line_num,
String::from_utf8_lossy(msg.line).trim_end()
)
.unwrap();
writeln!(handle, "{} | {}{}", line_indent, hl_indent, hl).unwrap(); writeln!(handle, "{} | {}{}", line_indent, hl_indent, hl).unwrap();
writeln!(handle, "{} |", line_indent).unwrap(); writeln!(handle, "{} |", line_indent).unwrap();
} }