From 533ff5f348324132044bd2782a17fd6c81c08259 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kat=20March=C3=A1n?= Date: Wed, 8 Sep 2021 19:57:09 -0700 Subject: [PATCH] fix(reporter): improve color situation and style things a little nicer --- src/handlers/graphical.rs | 20 +++++++++++++++++--- src/handlers/theme.rs | 13 +++++-------- tests/printer.rs | 32 ++++++++++++++++++++++---------- 3 files changed, 44 insertions(+), 21 deletions(-) diff --git a/src/handlers/graphical.rs b/src/handlers/graphical.rs index 4c8724c..ac6bb53 100644 --- a/src/handlers/graphical.rs +++ b/src/handlers/graphical.rs @@ -101,10 +101,17 @@ impl GraphicalReportHandler { } writeln!(f, "{}", self.theme.characters.hbar.to_string().repeat(20),)?; writeln!(f)?; + write!(f, " {} ", severity_icon.style(severity_style))?; + if diagnostic.source().is_some() { + write!(f, "{}", self.theme.characters.mtop.style(severity_style))?; + } else { + write!(f, "{}", self.theme.characters.hbar.style(severity_style))?; + } writeln!( f, - " {} {}", - severity_icon.style(severity_style), + "{}{} {}", + self.theme.characters.hbar.style(severity_style), + self.theme.characters.rarrow.style(severity_style), diagnostic, )?; Ok(()) @@ -126,7 +133,7 @@ impl GraphicalReportHandler { self.theme.characters.lbot }; let prefix = format!( - " {}{}{}", + " {}{}{}", char, self.theme.characters.hbar, self.theme.characters.rarrow ) .style(severity_style) @@ -255,6 +262,13 @@ impl GraphicalReportHandler { } } } + writeln!( + f, + "{}{}{}", + " ".repeat(linum_width + 2), + self.theme.characters.lbot, + self.theme.characters.hbar.to_string().repeat(3), + )?; Ok(()) } diff --git a/src/handlers/theme.rs b/src/handlers/theme.rs index bd744f0..77b7d82 100644 --- a/src/handlers/theme.rs +++ b/src/handlers/theme.rs @@ -98,19 +98,16 @@ impl ThemeStyles { /// Credit: http://terminal.sexy/#FRUV0NDQFRUVrEFCkKlZ9L91ap-1qnWfdbWq0NDQUFBQrEFCkKlZ9L91ap-1qnWfdbWq9fX1 pub fn rgb() -> Self { Self { - error: style().fg_rgb::<172, 65, 66>(), + error: style().fg_rgb::<255, 0, 20>(), warning: style().fg_rgb::<244, 191, 117>(), advice: style().fg_rgb::<106, 159, 181>(), code: style().fg_rgb::<170, 117, 159>(), - help: style().fg_rgb::<106, 159, 181>(), + help: style().fg_rgb::<117, 181, 170>().bold(), filename: style().fg_rgb::<117, 181, 170>().underline().bold(), highlights: vec![ - style().fg_rgb::<255, 135, 162>(), - style().fg_rgb::<150, 232, 133>(), - style().fg_rgb::<62, 238, 210>(), - style().fg_rgb::<234, 207, 182>(), - style().fg_rgb::<130, 221, 255>(), - style().fg_rgb::<255, 188, 242>(), + style().fg_rgb::<246, 87, 248>(), + style().fg_rgb::<30, 201, 212>(), + style().fg_rgb::<145, 246, 111>(), ], } } diff --git a/tests/printer.rs b/tests/printer.rs index 9b24c0f..3b349b5 100644 --- a/tests/printer.rs +++ b/tests/printer.rs @@ -48,7 +48,7 @@ fn single_line_highlight() -> Result<(), MietteError> { let expected = r#" ────[oops::my::bad]──────────────────── - × oops! + × ──▶ oops! ╭───[bad_file.rs:1:1] This is the part that broke: 1 │ source @@ -56,6 +56,7 @@ fn single_line_highlight() -> Result<(), MietteError> { · ──┬─ · ╰── this bit here 3 │ here + ╰─── ‽ try doing it better next time? "# @@ -90,7 +91,7 @@ fn single_line_highlight_offset_zero() -> Result<(), MietteError> { let expected = r#" ────[oops::my::bad]──────────────────── - × oops! + × ──▶ oops! ╭───[bad_file.rs:1:1] This is the part that broke: 1 │ source @@ -98,6 +99,7 @@ fn single_line_highlight_offset_zero() -> Result<(), MietteError> { · ╰─ this bit here 2 │ text 3 │ here + ╰─── ‽ try doing it better next time? "# @@ -132,7 +134,7 @@ fn single_line_highlight_with_empty_span() -> Result<(), MietteError> { let expected = r#" ────[oops::my::bad]──────────────────── - × oops! + × ──▶ oops! ╭───[bad_file.rs:1:1] This is the part that broke: 1 │ source @@ -140,6 +142,7 @@ fn single_line_highlight_with_empty_span() -> Result<(), MietteError> { · ▲ · ╰─ this bit here 3 │ here + ╰─── ‽ try doing it better next time? "# @@ -174,13 +177,14 @@ fn single_line_highlight_no_label() -> Result<(), MietteError> { let expected = r#" ────[oops::my::bad]──────────────────── - × oops! + × ──▶ oops! ╭───[bad_file.rs:1:1] This is the part that broke: 1 │ source 2 │ text · ──── 3 │ here + ╰─── ‽ try doing it better next time? "# @@ -218,7 +222,7 @@ fn multiple_same_line_highlights() -> Result<(), MietteError> { let expected = r#" ────[oops::my::bad]──────────────────── - × oops! + × ──▶ oops! ╭───[bad_file.rs:1:1] This is the part that broke: 1 │ source @@ -227,6 +231,7 @@ fn multiple_same_line_highlights() -> Result<(), MietteError> { · ╰── this bit here · ╰── also this bit 3 │ here + ╰─── ‽ try doing it better next time? "# @@ -261,13 +266,14 @@ fn multiline_highlight_adjacent() -> Result<(), MietteError> { let expected = r#" ────[oops::my::bad]──────────────────── - × oops! + × ──▶ oops! ╭───[bad_file.rs:1:1] This is the part that broke: 1 │ source 2 │ ╭─▶ text 3 │ ├─▶ here · ╰──── these two lines + ╰─── ‽ try doing it better next time? "# @@ -311,7 +317,7 @@ line5 let expected = r#" ────[oops::my::bad]──────────────────── - × oops! + × ──▶ oops! ╭───[bad_file.rs:1:1] This is the part that broke: 1 │ ╭──▶ line1 @@ -321,6 +327,7 @@ line5 · │╰──── block 2 5 │ ├──▶ line5 · ╰───── block 1 + ╰─── ‽ try doing it better next time? "# @@ -375,7 +382,9 @@ line5 let expected = r#" ────[oops::my::bad]──────────────────── - × oops! + × ┬─▶ wtf?! + ├─▶ something went wrong + ╰─▶ very much went wrong ╭───[bad_file.rs:1:1] This is the part that broke: 1 │ ╭──▶ line1 @@ -384,6 +393,7 @@ line5 4 │ │╰─▶ line4 5 │ ├──▶ line5 · ╰───── block 1 + ╰─── ‽ try doing it better next time? "# @@ -421,7 +431,7 @@ fn multiple_multiline_highlights_adjacent() -> Result<(), MietteError> { let expected = r#" ────[oops::my::bad]──────────────────── - × oops! + × ──▶ oops! ╭───[bad_file.rs:1:1] This is the part that broke: 1 │ ╭─▶ source @@ -430,6 +440,7 @@ fn multiple_multiline_highlights_adjacent() -> Result<(), MietteError> { 3 │ ╭─▶ here 4 │ ├─▶ more here · ╰──── also this bit + ╰─── ‽ try doing it better next time? "# @@ -566,10 +577,11 @@ fn unnamed_snippet_shows_message() { let expected = r#" ────[oops::my::bad]──────────────────── - × oops! + × ──▶ oops! ╭───[1:1] This is the part that broke: 1 │ source_text_here + ╰─── ‽ try doing it better next time? "#