diff --git a/libkabel/src/diagnostics/emitters/pretty.rs b/libkabel/src/diagnostics/emitters/pretty.rs index 5536ecf..0b1bed1 100644 --- a/libkabel/src/diagnostics/emitters/pretty.rs +++ b/libkabel/src/diagnostics/emitters/pretty.rs @@ -50,7 +50,7 @@ impl Emitter for PrettyEmitter { let line_hdr_padding = line.to_string().len() + 1; writeln!(output, "{}{}", " ".repeat(line_hdr_padding), "|".bright_blue().bold()).unwrap(); - writeln!(output, "{}{} {} {}", line.to_string().bright_blue().bold(), " ".repeat(line_no_padding - line.to_string().len()), "|".bright_blue().bold(), get_line(line, &source).unwrap_or("")).unwrap(); + writeln!(output, "{}{} {} {}", line.to_string().bright_blue().bold(), " ".repeat(line_no_padding - line.to_string().len()), "|".bright_blue().bold(), get_line(line-1, &source).unwrap_or("")).unwrap(); diff --git a/libkabel/src/diagnostics/emitters/util.rs b/libkabel/src/diagnostics/emitters/util.rs index b98e9e8..060a6e1 100644 --- a/libkabel/src/diagnostics/emitters/util.rs +++ b/libkabel/src/diagnostics/emitters/util.rs @@ -16,5 +16,5 @@ pub fn pos_to_line_col(pos: usize, source: &str) -> (usize, usize) { } pub fn get_line(line: usize, source: &str) -> Option<&str> { - source.lines().nth(line) + source.split('\n').nth(line) }