From 795e67c984a786c9cece800a0d2d18da319bf134 Mon Sep 17 00:00:00 2001 From: core Date: Wed, 17 Jan 2024 20:28:13 -0500 Subject: [PATCH] fix lines --- libkabel/src/diagnostics/emitters/pretty.rs | 2 +- libkabel/src/diagnostics/emitters/util.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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) }