Skip to content

Commit

Permalink
fix(graphical): wrap footers to same width as non-footers
Browse files Browse the repository at this point in the history
  • Loading branch information
TheLostLambda committed Mar 27, 2024
1 parent a667134 commit 4426f9c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/handlers/graphical.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ impl GraphicalReportHandler {
self.render_related(f, diagnostic, src)?;
if let Some(footer) = &self.footer {
writeln!(f)?;
let width = self.termwidth.saturating_sub(4);
let width = self.termwidth.saturating_sub(2);
let mut opts = textwrap::Options::new(width)
.initial_indent(" ")
.subsequent_indent(" ")
Expand Down Expand Up @@ -372,7 +372,7 @@ impl GraphicalReportHandler {

fn render_footer(&self, f: &mut impl fmt::Write, diagnostic: &(dyn Diagnostic)) -> fmt::Result {
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 mut opts = textwrap::Options::new(width)
.initial_indent(&initial_indent)
Expand Down
20 changes: 10 additions & 10 deletions tests/graphical.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,11 +267,11 @@ fn wrap_option() -> Result<(), MietteError> {
#[test]
fn wrapping_nested_errors() -> Result<(), MietteError> {
#[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(
code(mama::error),
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 {
Expand All @@ -280,11 +280,11 @@ fn wrapping_nested_errors() -> Result<(), MietteError> {
}

#[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(
code(baby::error),
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;
Expand All @@ -293,21 +293,21 @@ fn wrapping_nested_errors() -> Result<(), MietteError> {
let out = fmt_report_with_settings(err.into(), |handler| handler.with_width(50));
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
│ so on...
╰─▶ baby::error
× 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,
│ buddo!
help: it cannot be helped... would
youuuu really want to get rid of
an error that's so cute?
help: it cannot be helped... woulddddddd
you really want to get rid of an
error that's so cute?
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?
"#;
assert_eq!(expected, out);
Expand Down

0 comments on commit 4426f9c

Please sign in to comment.