fix: continuation line on multiline labels

This commit is contained in:
beeb 2026-02-06 12:52:24 +01:00
parent df7bcfa17d
commit d696bf3316
No known key found for this signature in database
GPG Key ID: 3C74CF4793150A13
1 changed files with 49 additions and 36 deletions

View File

@ -740,7 +740,7 @@ impl GraphicalReportHandler {
max_gutter, max_gutter,
line, line,
&labels, &labels,
LabelRenderMode::SingleLine, LabelRenderMode::MultiLineEndPending,
)?; )?;
self.render_single_line_highlights( self.render_single_line_highlights(
f, f,
@ -930,32 +930,41 @@ impl GraphicalReportHandler {
let applicable = highlights.iter().filter(|hl| line.span_applies_gutter(hl)); let applicable = highlights.iter().filter(|hl| line.span_applies_gutter(hl));
for (i, hl) in applicable.enumerate() { for (i, hl) in applicable.enumerate() {
if !line.span_line_only(hl) && line.span_ends(hl) { if !line.span_line_only(hl) && line.span_ends(hl) {
if render_mode == LabelRenderMode::MultiLineRest { match render_mode {
// this is to make multiline labels work. We want to make the right amount LabelRenderMode::MultiLineRest => {
// of horizontal space for them, but not actually draw the lines // this is to make multiline labels work. We want to make the right amount
let horizontal_space = max_gutter.saturating_sub(i) + 2; // of horizontal space for them, but not actually draw the lines
for _ in 0..horizontal_space { let horizontal_space = max_gutter.saturating_sub(i) + 2;
gutter.push(' '); for _ in 0..horizontal_space {
gutter.push(' ');
}
// account for one more horizontal space, since in multiline mode
// we also add in the vertical line before the label like this:
// 2 │ ╭─▶ text
// 3 │ ├─▶ here
// · ╰──┤ these two lines
// · │ are the problem
// ^this
gutter_cols += horizontal_space + 1;
} }
// account for one more horizontal space, since in multiline mode LabelRenderMode::MultiLineEndPending => {
// we also add in the vertical line before the label like this: // we're rendering continuation lines for single-line highlights on a line
// 2 │ ╭─▶ text // where a multiline span ends
// 3 │ ├─▶ here // render │ to show the span is still visually "open" until we render its own label with ╰──
// · ╰──┤ these two lines gutter.push_str(&chars.vbar.style(hl.style).to_string());
// · │ are the problem gutter_cols += 1;
// ^this }
gutter_cols += horizontal_space + 1; LabelRenderMode::SingleLine | LabelRenderMode::MultiLineFirst => {
} else { let num_repeat = max_gutter.saturating_sub(i) + 2;
let num_repeat = max_gutter.saturating_sub(i) + 2;
gutter.push_str(&chars.lbot.style(hl.style).to_string()); gutter.push_str(&chars.lbot.style(hl.style).to_string());
gutter.push_str( gutter.push_str(
&chars &chars
.hbar .hbar
.to_string() .to_string()
.repeat( .repeat(
num_repeat num_repeat
// if we are rendering a multiline label, then leave a bit of space for the // if we are rendering a multiline label, then leave a bit of space for the
// rcross character // rcross character
- if render_mode == LabelRenderMode::MultiLineFirst { - if render_mode == LabelRenderMode::MultiLineFirst {
@ -963,16 +972,17 @@ impl GraphicalReportHandler {
} else { } else {
0 0
}, },
) )
.style(hl.style) .style(hl.style)
.to_string(), .to_string(),
); );
// we count 1 for the lbot char, and then a few more, the same number // we count 1 for the lbot char, and then a few more, the same number
// as we just repeated for. For each repeat we only add 1, even though // as we just repeated for. For each repeat we only add 1, even though
// due to ansi escape codes the number of bytes in the string could grow // due to ansi escape codes the number of bytes in the string could grow
// a lot each time. // a lot each time.
gutter_cols += num_repeat + 1; gutter_cols += num_repeat + 1;
}
} }
break; break;
} else { } else {
@ -1244,7 +1254,7 @@ impl GraphicalReportHandler {
max_gutter, max_gutter,
line, line,
all_highlights, all_highlights,
LabelRenderMode::SingleLine, LabelRenderMode::MultiLineEndPending,
)?; )?;
let mut curr_offset = 1usize; let mut curr_offset = 1usize;
for (offset_hl, vbar_offset) in vbar_offsets { for (offset_hl, vbar_offset) in vbar_offsets {
@ -1257,7 +1267,7 @@ impl GraphicalReportHandler {
curr_offset += 1; curr_offset += 1;
} else { } else {
let lines = match render_mode { let lines = match render_mode {
LabelRenderMode::SingleLine => format!( LabelRenderMode::SingleLine | LabelRenderMode::MultiLineEndPending => format!(
"{}{} {}", "{}{} {}",
chars.lbot, chars.lbot,
chars.hbar.to_string().repeat(2), chars.hbar.to_string().repeat(2),
@ -1285,7 +1295,7 @@ impl GraphicalReportHandler {
render_mode: LabelRenderMode, render_mode: LabelRenderMode,
) -> fmt::Result { ) -> fmt::Result {
match render_mode { match render_mode {
LabelRenderMode::SingleLine => { LabelRenderMode::SingleLine | LabelRenderMode::MultiLineEndPending => {
writeln!(f, "{} {}", self.theme.characters.hbar.style(style), label)?; writeln!(f, "{} {}", self.theme.characters.hbar.style(style), label)?;
} }
LabelRenderMode::MultiLineFirst => { LabelRenderMode::MultiLineFirst => {
@ -1382,6 +1392,9 @@ enum LabelRenderMode {
MultiLineFirst, MultiLineFirst,
/// we're rendering the rest of a multiline label /// we're rendering the rest of a multiline label
MultiLineRest, MultiLineRest,
/// we're rendering continuation lines for single-line highlights on a line where
/// a multi-line span ends - render │ instead of ╰── for ending spans
MultiLineEndPending,
} }
#[derive(Debug)] #[derive(Debug)]