mirror of https://github.com/zkat/miette.git
fix(graphical): wrap footers to same width as non-footers
This commit is contained in:
parent
a66713470c
commit
4426f9c8ed
|
|
@ -225,7 +225,7 @@ impl GraphicalReportHandler {
|
||||||
self.render_related(f, diagnostic, src)?;
|
self.render_related(f, diagnostic, src)?;
|
||||||
if let Some(footer) = &self.footer {
|
if let Some(footer) = &self.footer {
|
||||||
writeln!(f)?;
|
writeln!(f)?;
|
||||||
let width = self.termwidth.saturating_sub(4);
|
let width = self.termwidth.saturating_sub(2);
|
||||||
let mut opts = textwrap::Options::new(width)
|
let mut opts = textwrap::Options::new(width)
|
||||||
.initial_indent(" ")
|
.initial_indent(" ")
|
||||||
.subsequent_indent(" ")
|
.subsequent_indent(" ")
|
||||||
|
|
@ -372,7 +372,7 @@ impl GraphicalReportHandler {
|
||||||
|
|
||||||
fn render_footer(&self, f: &mut impl fmt::Write, diagnostic: &(dyn Diagnostic)) -> fmt::Result {
|
fn render_footer(&self, f: &mut impl fmt::Write, diagnostic: &(dyn Diagnostic)) -> fmt::Result {
|
||||||
if let Some(help) = diagnostic.help() {
|
if let Some(help) = diagnostic.help() {
|
||||||
let width = self.termwidth.saturating_sub(4);
|
let width = self.termwidth.saturating_sub(2);
|
||||||
let initial_indent = " help: ".style(self.theme.styles.help).to_string();
|
let initial_indent = " help: ".style(self.theme.styles.help).to_string();
|
||||||
let mut opts = textwrap::Options::new(width)
|
let mut opts = textwrap::Options::new(width)
|
||||||
.initial_indent(&initial_indent)
|
.initial_indent(&initial_indent)
|
||||||
|
|
|
||||||
|
|
@ -267,11 +267,11 @@ fn wrap_option() -> Result<(), MietteError> {
|
||||||
#[test]
|
#[test]
|
||||||
fn wrapping_nested_errors() -> Result<(), MietteError> {
|
fn wrapping_nested_errors() -> Result<(), MietteError> {
|
||||||
#[derive(Debug, Diagnostic, Error)]
|
#[derive(Debug, Diagnostic, Error)]
|
||||||
#[error("This is the parent error, the error with the children, kiddos, pups, as it were, and so on...")]
|
#[error("This is the parent error, the error withhhhh the children, kiddos, pups, as it were, and so on...")]
|
||||||
#[diagnostic(
|
#[diagnostic(
|
||||||
code(mama::error),
|
code(mama::error),
|
||||||
help(
|
help(
|
||||||
"try doing it better next time? I mean, you could have also done better this time, but no?"
|
"try doing it better next time? I mean, you could have also done better thisssss time, but no?"
|
||||||
)
|
)
|
||||||
)]
|
)]
|
||||||
struct MamaError {
|
struct MamaError {
|
||||||
|
|
@ -280,11 +280,11 @@ fn wrapping_nested_errors() -> Result<(), MietteError> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Diagnostic, Error)]
|
#[derive(Debug, Diagnostic, Error)]
|
||||||
#[error("Wah wah: I may be small, but I'll cause a proper bout of trouble — just try wrapping this mess of a line, buddo!")]
|
#[error("Wah wah: I may be small, but I'll cause a proper bout of trouble — justt try wrapping this mess of a line, buddo!")]
|
||||||
#[diagnostic(
|
#[diagnostic(
|
||||||
code(baby::error),
|
code(baby::error),
|
||||||
help(
|
help(
|
||||||
"it cannot be helped... would youuuu really want to get rid of an error that's so cute?"
|
"it cannot be helped... woulddddddd you really want to get rid of an error that's so cute?"
|
||||||
)
|
)
|
||||||
)]
|
)]
|
||||||
struct BabyError;
|
struct BabyError;
|
||||||
|
|
@ -293,21 +293,21 @@ fn wrapping_nested_errors() -> Result<(), MietteError> {
|
||||||
let out = fmt_report_with_settings(err.into(), |handler| handler.with_width(50));
|
let out = fmt_report_with_settings(err.into(), |handler| handler.with_width(50));
|
||||||
let expected = r#"mama::error
|
let expected = r#"mama::error
|
||||||
|
|
||||||
× This is the parent error, the error with
|
× This is the parent error, the error withhhhh
|
||||||
│ the children, kiddos, pups, as it were, and
|
│ the children, kiddos, pups, as it were, and
|
||||||
│ so on...
|
│ so on...
|
||||||
╰─▶ baby::error
|
╰─▶ baby::error
|
||||||
|
|
||||||
× Wah wah: I may be small, but I'll
|
× Wah wah: I may be small, but I'll
|
||||||
│ cause a proper bout of trouble — just
|
│ cause a proper bout of trouble — justt
|
||||||
│ try wrapping this mess of a line,
|
│ try wrapping this mess of a line,
|
||||||
│ buddo!
|
│ buddo!
|
||||||
help: it cannot be helped... would
|
help: it cannot be helped... woulddddddd
|
||||||
youuuu really want to get rid of
|
you really want to get rid of an
|
||||||
an error that's so cute?
|
error that's so cute?
|
||||||
|
|
||||||
help: try doing it better next time? I mean,
|
help: try doing it better next time? I mean,
|
||||||
you could have also done better this
|
you could have also done better thisssss
|
||||||
time, but no?
|
time, but no?
|
||||||
"#;
|
"#;
|
||||||
assert_eq!(expected, out);
|
assert_eq!(expected, out);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue