Skip to content

Commit

Permalink
feat(graphical): simplify graphical header and remove a dep
Browse files Browse the repository at this point in the history
  • Loading branch information
zkat committed Sep 21, 2021
1 parent dc2635e commit 9f36a4c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 31 deletions.
2 changes: 0 additions & 2 deletions Cargo.toml
Expand Up @@ -21,7 +21,6 @@ atty = { version = "0.2.14", optional = true }
ci_info = { version = "0.14.2", optional = true }
textwrap = { version = "0.14.2", optional = true }
term_size = { version = "0.3.2", optional = true }
unicode-width = { version = "0.1.8", optional = true }
supports-hyperlinks = { version = "1.1.0", optional = true }
supports-color = { version = "1.0.2", optional = true }
supports-unicode = { version = "1.0.0", optional = true }
Expand All @@ -46,7 +45,6 @@ fancy = [
"ci_info",
"textwrap",
"term_size",
"unicode-width",
"supports-hyperlinks",
"supports-color",
"supports-unicode",
Expand Down
33 changes: 4 additions & 29 deletions src/handlers/graphical.rs
Expand Up @@ -2,7 +2,6 @@ use std::fmt::{self, Write};

use itertools::Itertools;
use owo_colors::{OwoColorize, Style};
use unicode_width::UnicodeWidthStr;

use crate::chain::Chain;
use crate::handlers::theme::*;
Expand Down Expand Up @@ -126,13 +125,6 @@ impl GraphicalReportHandler {
Some(Severity::Advice) => self.theme.styles.advice,
};
let mut header = String::new();
let mut width = 0;
write!(
header,
"{}",
self.theme.characters.hbar.to_string().repeat(4)
)?;
width += 4;
if self.linkify_code && diagnostic.url().is_some() && diagnostic.code().is_some() {
let url = diagnostic.url().unwrap(); // safe
let code = format!(
Expand All @@ -141,7 +133,6 @@ impl GraphicalReportHandler {
.code()
.expect("MIETTE BUG: already got checked for None")
);
width += code[..].width();
let link = format!(
"\u{1b}]8;;{}\u{1b}\\{}\u{1b}]8;;\u{1b}\\",
url,
Expand All @@ -151,30 +142,14 @@ impl GraphicalReportHandler {
"(link)".style(self.theme.styles.link)
)
);
write!(header, "[{}]", link)?;
width += "(link)".width() + 3
write!(header, "{}", link)?;
} else if let Some(code) = diagnostic.code() {
write!(header, "[{}", code.style(severity_style),)?;
width += &code.to_string()[..].width() + 1;

write!(header, "{}", code.style(severity_style),)?;
if let Some(link) = diagnostic.url() {
write!(header, " ({})]", link.style(self.theme.styles.link))?;
width += &link.to_string()[..].width() + 4;
} else {
write!(header, "]")?;
width += 1;
write!(header, " ({})", link.style(self.theme.styles.link))?;
}
}
writeln!(
f,
"{}{}",
header,
self.theme.characters.hbar.to_string().repeat(
self.termwidth
.saturating_sub(width)
.saturating_sub("Error: ".width())
)
)?;
writeln!(f, "{}", header)?;
Ok(())
}

Expand Down

0 comments on commit 9f36a4c

Please sign in to comment.