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