From 80aeed1b43a9ccd1a36267163d6a4d27a99badba Mon Sep 17 00:00:00 2001 From: Ed Page Date: Sat, 22 Jun 2019 09:18:03 -0600 Subject: [PATCH] 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 --- src/report.rs | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/report.rs b/src/report.rs index d3cc8e3..f501f64 100644 --- a/src/report.rs +++ b/src/report.rs @@ -35,6 +35,9 @@ pub fn print_long(msg: Message) { let hl_indent: String = itertools::repeat_n(" ", msg.col_num).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 mut handle = stdout.lock(); @@ -53,13 +56,7 @@ pub fn print_long(msg: Message) { ) .unwrap(); writeln!(handle, "{} |", line_indent).unwrap(); - writeln!( - handle, - "{} | {}", - msg.line_num, - String::from_utf8_lossy(msg.line).trim_end() - ) - .unwrap(); + writeln!(handle, "{} | {}", msg.line_num, line.trim_end()).unwrap(); writeln!(handle, "{} | {}{}", line_indent, hl_indent, hl).unwrap(); writeln!(handle, "{} |", line_indent).unwrap(); }