mirror of https://github.com/zkat/miette.git
feat(theme): more styling changes
This commit is contained in:
parent
c5c0576ec6
commit
2c43740346
|
|
@ -131,17 +131,21 @@ impl GraphicalReportHandler {
|
|||
let link = format!(
|
||||
"\u{1b}]8;;{}\u{1b}\\{}\u{1b}]8;;\u{1b}\\",
|
||||
url,
|
||||
"(link)".style(self.theme.styles.filename)
|
||||
format!(
|
||||
"{} {}",
|
||||
code.style(severity_style),
|
||||
"(link)".style(self.theme.styles.link)
|
||||
)
|
||||
);
|
||||
write!(header, "[{} {}]", code.style(severity_style), link,)?;
|
||||
write!(header, "[{}]", link)?;
|
||||
width += "(link)".width() + 3
|
||||
} else if let Some(code) = diagnostic.code() {
|
||||
write!(header, "[{}", code.style(severity_style),)?;
|
||||
width += &code.to_string()[..].width() + 1;
|
||||
|
||||
if let Some(link) = diagnostic.url() {
|
||||
write!(header, " ({})]", link.style(self.theme.styles.filename))?;
|
||||
width += &link.to_string()[..].width() + 3;
|
||||
write!(header, " ({})]", link.style(self.theme.styles.link))?;
|
||||
width += &link.to_string()[..].width() + 4;
|
||||
} else {
|
||||
write!(header, "]")?;
|
||||
width += 1;
|
||||
|
|
@ -162,9 +166,9 @@ impl GraphicalReportHandler {
|
|||
|
||||
fn render_causes(&self, f: &mut impl fmt::Write, diagnostic: &(dyn Diagnostic)) -> fmt::Result {
|
||||
let (severity_style, severity_icon) = match diagnostic.severity() {
|
||||
Some(Severity::Error) | None => (self.theme.styles.error, self.theme.characters.error),
|
||||
Some(Severity::Warning) => (self.theme.styles.warning, self.theme.characters.warning),
|
||||
Some(Severity::Advice) => (self.theme.styles.advice, self.theme.characters.advice),
|
||||
Some(Severity::Error) | None => (self.theme.styles.error, &self.theme.characters.error),
|
||||
Some(Severity::Warning) => (self.theme.styles.warning, &self.theme.characters.warning),
|
||||
Some(Severity::Advice) => (self.theme.styles.advice, &self.theme.characters.advice),
|
||||
};
|
||||
|
||||
let initial_indent = format!(" {} ", severity_icon.style(severity_style));
|
||||
|
|
@ -294,7 +298,7 @@ impl GraphicalReportHandler {
|
|||
self.theme.characters.hbar,
|
||||
)?;
|
||||
if let Some(source_name) = snippet.source.name() {
|
||||
let source_name = source_name.style(self.theme.styles.filename);
|
||||
let source_name = source_name.style(self.theme.styles.link);
|
||||
writeln!(
|
||||
f,
|
||||
"[{}:{}:{}]",
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ pub trait Diagnostic: std::error::Error {
|
|||
None
|
||||
}
|
||||
|
||||
/// URL to visit for a more details explanation/help about this Diagnostic.
|
||||
/// URL to visit for a more detailed explanation/help about this Diagnostic.
|
||||
fn url<'a>(&'a self) -> Option<Box<dyn Display + 'a>> {
|
||||
None
|
||||
}
|
||||
|
|
|
|||
|
|
@ -629,6 +629,20 @@ fn url_links() -> Result<(), MietteError> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn url_links_no_code() -> Result<(), MietteError> {
|
||||
#[derive(Debug, Diagnostic, Error)]
|
||||
#[error("oops!")]
|
||||
#[diagnostic(help("try doing it better next time?"), url("https://example.com"))]
|
||||
struct MyBad;
|
||||
let err = MyBad;
|
||||
let out = fmt_report(err.into());
|
||||
println!("{}", out);
|
||||
assert!(out.contains("https://example.com"));
|
||||
assert!(out.contains("click for details"));
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn disable_url_links() -> Result<(), MietteError> {
|
||||
#[derive(Debug, Diagnostic, Error)]
|
||||
|
|
@ -646,7 +660,7 @@ fn disable_url_links() -> Result<(), MietteError> {
|
|||
.render_report(&mut out, &err)
|
||||
.unwrap();
|
||||
println!("{}", out);
|
||||
assert!(!out.contains("https://example.com"));
|
||||
assert!(out.contains("url: https://example.com"));
|
||||
assert!(!out.contains("click for details"));
|
||||
assert!(out.contains("oops::my::bad"));
|
||||
Ok(())
|
||||
|
|
|
|||
Loading…
Reference in New Issue