From 186844aef36823f5378c30b2442319b243efcaad Mon Sep 17 00:00:00 2001 From: Override-6 Date: Fri, 9 Jun 2023 11:55:48 +0200 Subject: [PATCH 1/2] remove empty lines for any label with no message in report --- examples/simple.rs | 16 +++++++++++++++- src/write.rs | 5 ++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/examples/simple.rs b/examples/simple.rs index 66e108c..7ad8eb6 100644 --- a/examples/simple.rs +++ b/examples/simple.rs @@ -1,4 +1,5 @@ -use ariadne::{Report, ReportKind, Label, Source}; +use yansi::Color; +use ariadne::{Report, ReportKind, Label, Source, Config}; fn main() { Report::build(ReportKind::Error, (), 34) @@ -8,4 +9,17 @@ fn main() { .finish() .print(Source::from(include_str!("sample.tao"))) .unwrap(); + + const SOURCE: &str = "a b c d e f"; + // also supports labels with no messages to only emphasis on some areas + Report::build(ReportKind::Error, (), 34) + .with_message("Incompatible types") + .with_config(Config::default().with_compact(true)) + .with_label(Label::new(0..1).with_color(Color::Red)) + .with_label(Label::new(2..3).with_color(Color::Blue).with_message("This is another test").with_order(1)) + .with_label(Label::new(4..5).with_color(Color::Green)) + .with_label(Label::new(7..9).with_color(Color::Cyan).with_message("This is a test")) + .finish() + .print(Source::from(SOURCE)) + .unwrap(); } diff --git a/src/write.rs b/src/write.rs index 1002fe1..1ddf4d0 100644 --- a/src/write.rs +++ b/src/write.rs @@ -608,7 +608,10 @@ impl Report<'_, S> { // Arrows for row in 0..line_labels.len() { let line_label = &line_labels[row]; - + //No message to draw thus no arrow to draw + if line_label.label.msg.is_none() { + continue + } if !self.config.compact { // Margin alternate write_margin( From bc91c834245048f8ee9529fc36c551c76980bbdc Mon Sep 17 00:00:00 2001 From: Override-6 Date: Fri, 9 Jun 2023 12:30:16 +0200 Subject: [PATCH 2/2] change labels messages in new simple example --- examples/simple.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/simple.rs b/examples/simple.rs index 7ad8eb6..5f2002c 100644 --- a/examples/simple.rs +++ b/examples/simple.rs @@ -16,9 +16,9 @@ fn main() { .with_message("Incompatible types") .with_config(Config::default().with_compact(true)) .with_label(Label::new(0..1).with_color(Color::Red)) - .with_label(Label::new(2..3).with_color(Color::Blue).with_message("This is another test").with_order(1)) + .with_label(Label::new(2..3).with_color(Color::Blue).with_message("`b` for banana").with_order(1)) .with_label(Label::new(4..5).with_color(Color::Green)) - .with_label(Label::new(7..9).with_color(Color::Cyan).with_message("This is a test")) + .with_label(Label::new(7..9).with_color(Color::Cyan).with_message("`e` for emerald")) .finish() .print(Source::from(SOURCE)) .unwrap();