Skip to content

Commit

Permalink
fix(reporter): improve color situation and style things a little nicer
Browse files Browse the repository at this point in the history
  • Loading branch information
zkat committed Sep 9, 2021
1 parent 00ebb13 commit 533ff5f
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 21 deletions.
20 changes: 17 additions & 3 deletions src/handlers/graphical.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
Expand All @@ -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)
Expand Down Expand Up @@ -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(())
}

Expand Down
13 changes: 5 additions & 8 deletions src/handlers/theme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>(),
],
}
}
Expand Down
32 changes: 22 additions & 10 deletions tests/printer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,15 @@ 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
2 │ text
· ──┬─
· ╰── this bit here
3 │ here
╰───
‽ try doing it better next time?
"#
Expand Down Expand Up @@ -90,14 +91,15 @@ 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
· ▲
· ╰─ this bit here
2 │ text
3 │ here
╰───
‽ try doing it better next time?
"#
Expand Down Expand Up @@ -132,14 +134,15 @@ 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
2 │ text
· ▲
· ╰─ this bit here
3 │ here
╰───
‽ try doing it better next time?
"#
Expand Down Expand Up @@ -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?
"#
Expand Down Expand Up @@ -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
Expand All @@ -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?
"#
Expand Down Expand Up @@ -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?
"#
Expand Down Expand Up @@ -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
Expand All @@ -321,6 +327,7 @@ line5
· │╰──── block 2
5 │ ├──▶ line5
· ╰───── block 1
╰───
‽ try doing it better next time?
"#
Expand Down Expand Up @@ -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
Expand All @@ -384,6 +393,7 @@ line5
4 │ │╰─▶ line4
5 │ ├──▶ line5
· ╰───── block 1
╰───
‽ try doing it better next time?
"#
Expand Down Expand Up @@ -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
Expand All @@ -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?
"#
Expand Down Expand Up @@ -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?
"#
Expand Down

0 comments on commit 533ff5f

Please sign in to comment.