mirror of https://github.com/zkat/miette.git
feat(report): wrap multiline messages to keep formatting
Fixes: https://github.com/zkat/miette/issues/51
This commit is contained in:
parent
1ba3f2f5d2
commit
f482dcec6a
|
|
@ -18,6 +18,7 @@ once_cell = "1.8.0"
|
||||||
owo-colors = "2.0.0"
|
owo-colors = "2.0.0"
|
||||||
atty = "0.2.14"
|
atty = "0.2.14"
|
||||||
ci_info = "0.14.2"
|
ci_info = "0.14.2"
|
||||||
|
textwrap = "0.14.2"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
semver = "1.0.4"
|
semver = "1.0.4"
|
||||||
|
|
|
||||||
|
|
@ -101,8 +101,13 @@ impl GraphicalReportHandler {
|
||||||
}
|
}
|
||||||
writeln!(f, "{}", self.theme.characters.hbar.to_string().repeat(20),)?;
|
writeln!(f, "{}", self.theme.characters.hbar.to_string().repeat(20),)?;
|
||||||
writeln!(f)?;
|
writeln!(f)?;
|
||||||
write!(f, " {} ", severity_icon.style(severity_style))?;
|
// TODO: terminal width support
|
||||||
writeln!(f, "{}", diagnostic,)?;
|
let initial_indent = format!(" {} ", severity_icon.style(severity_style));
|
||||||
|
let rest_indent = format!(" {} ", self.theme.characters.vbar.style(severity_style));
|
||||||
|
let opts = textwrap::Options::new(80)
|
||||||
|
.initial_indent(&initial_indent)
|
||||||
|
.subsequent_indent(&rest_indent);
|
||||||
|
writeln!(f, "{}", textwrap::fill(&diagnostic.to_string(), opts))?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -121,13 +126,19 @@ impl GraphicalReportHandler {
|
||||||
} else {
|
} else {
|
||||||
self.theme.characters.lbot
|
self.theme.characters.lbot
|
||||||
};
|
};
|
||||||
let prefix = format!(
|
let initial_indent = format!(
|
||||||
" {}{}{}",
|
" {}{}{} ",
|
||||||
char, self.theme.characters.hbar, self.theme.characters.rarrow
|
char, self.theme.characters.hbar, self.theme.characters.rarrow
|
||||||
)
|
)
|
||||||
.style(severity_style)
|
.style(severity_style)
|
||||||
.to_string();
|
.to_string();
|
||||||
writeln!(f, "{} {}", prefix, error)?;
|
let rest_indent = format!(" {} ", self.theme.characters.vbar)
|
||||||
|
.style(severity_style)
|
||||||
|
.to_string();
|
||||||
|
let opts = textwrap::Options::new(80)
|
||||||
|
.initial_indent(&initial_indent)
|
||||||
|
.subsequent_indent(&rest_indent);
|
||||||
|
writeln!(f, "{}", textwrap::fill(&error.to_string(), opts))?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -340,7 +340,7 @@ line5
|
||||||
#[test]
|
#[test]
|
||||||
fn multiline_highlight_no_label() -> Result<(), MietteError> {
|
fn multiline_highlight_no_label() -> Result<(), MietteError> {
|
||||||
#[derive(Debug, Diagnostic, Error)]
|
#[derive(Debug, Diagnostic, Error)]
|
||||||
#[error("wtf?!")]
|
#[error("wtf?!\nit broke :(")]
|
||||||
#[diagnostic(code(oops::my::bad), help("try doing it better next time?"))]
|
#[diagnostic(code(oops::my::bad), help("try doing it better next time?"))]
|
||||||
struct MyBad {
|
struct MyBad {
|
||||||
#[source]
|
#[source]
|
||||||
|
|
@ -355,7 +355,7 @@ fn multiline_highlight_no_label() -> Result<(), MietteError> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Error)]
|
#[derive(Debug, Error)]
|
||||||
#[error("something went wrong")]
|
#[error("something went wrong\n\nHere's a more detailed explanation of everything that actually went wrong because it's actually important.\n")]
|
||||||
struct Inner(#[source] InnerInner);
|
struct Inner(#[source] InnerInner);
|
||||||
|
|
||||||
#[derive(Debug, Error)]
|
#[derive(Debug, Error)]
|
||||||
|
|
@ -379,11 +379,16 @@ line5
|
||||||
};
|
};
|
||||||
let out = fmt_report(err.into());
|
let out = fmt_report(err.into());
|
||||||
println!("{}", out);
|
println!("{}", out);
|
||||||
let expected = r#"
|
let expected = "
|
||||||
────[oops::my::bad]────────────────────
|
────[oops::my::bad]────────────────────
|
||||||
|
|
||||||
× wtf?!
|
× wtf?!
|
||||||
|
│ it broke :(
|
||||||
├─▶ something went wrong
|
├─▶ something went wrong
|
||||||
|
│\u{20}\u{20}\u{20}
|
||||||
|
│ Here's a more detailed explanation of everything that actually went
|
||||||
|
│ wrong because it's actually important.
|
||||||
|
│\u{20}\u{20}\u{20}
|
||||||
╰─▶ very much went wrong
|
╰─▶ very much went wrong
|
||||||
|
|
||||||
╭───[bad_file.rs:1:1] This is the part that broke:
|
╭───[bad_file.rs:1:1] This is the part that broke:
|
||||||
|
|
@ -396,7 +401,7 @@ line5
|
||||||
╰───
|
╰───
|
||||||
|
|
||||||
‽ try doing it better next time?
|
‽ try doing it better next time?
|
||||||
"#
|
"
|
||||||
.trim_start()
|
.trim_start()
|
||||||
.to_string();
|
.to_string();
|
||||||
assert_eq!(expected, out);
|
assert_eq!(expected, out);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue