From 6c6484633ed1580047fb3dc820486f3264fb6a19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kat=20March=C3=A1n?= Date: Tue, 21 Sep 2021 13:15:05 -0700 Subject: [PATCH] feat(graphical): simplify graphical header and remove a dep --- Cargo.toml | 2 -- src/handlers/graphical.rs | 33 ++++----------------------------- 2 files changed, 4 insertions(+), 31 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index d5b84bb..3ae8ca6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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 } @@ -46,7 +45,6 @@ fancy = [ "ci_info", "textwrap", "term_size", - "unicode-width", "supports-hyperlinks", "supports-color", "supports-unicode", diff --git a/src/handlers/graphical.rs b/src/handlers/graphical.rs index dbe41bc..b6cd42e 100644 --- a/src/handlers/graphical.rs +++ b/src/handlers/graphical.rs @@ -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::*; @@ -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!( @@ -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, @@ -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(()) }