fix(graphical): wrap footers to same width as non-footers

This commit is contained in:
Brooks J Rady 2024-03-26 17:13:58 -07:00
parent a66713470c
commit 4426f9c8ed
2 changed files with 12 additions and 12 deletions

View File

@ -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(" ")
@ -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)

View File

@ -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 {
@ -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;
@ -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);