From a66713470c20694f9d694746669478015bf399e3 Mon Sep 17 00:00:00 2001 From: Brooks J Rady Date: Tue, 26 Mar 2024 15:23:06 -0700 Subject: [PATCH] fix(graphical): fix nested error wrapping --- src/handlers/graphical.rs | 4 +++- tests/graphical.rs | 12 +++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/handlers/graphical.rs b/src/handlers/graphical.rs index a4474f9..d3ba7ab 100644 --- a/src/handlers/graphical.rs +++ b/src/handlers/graphical.rs @@ -1,7 +1,7 @@ use std::fmt::{self, Write}; use owo_colors::{OwoColorize, Style, StyledList}; -use unicode_width::UnicodeWidthChar; +use unicode_width::{UnicodeWidthChar, UnicodeWidthStr}; use crate::diagnostic_chain::{DiagnosticChain, ErrorKind}; use crate::handlers::theme::*; @@ -354,6 +354,8 @@ impl GraphicalReportHandler { inner_renderer.footer = None; // Cause chains are already flattened, so don't double-print the nested error inner_renderer.with_cause_chain = false; + // Since everything from here on is indented, shrink the virtual terminal + inner_renderer.termwidth -= rest_indent.width(); inner_renderer.render_report(&mut inner, diag)?; writeln!(f, "{}", self.wrap(&inner, opts))?; diff --git a/tests/graphical.rs b/tests/graphical.rs index b2a5f93..558eb5f 100644 --- a/tests/graphical.rs +++ b/tests/graphical.rs @@ -299,14 +299,12 @@ fn wrapping_nested_errors() -> Result<(), MietteError> { ╰─▶ baby::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! + │ cause a proper bout of trouble — just + │ 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? + youuuu 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