mirror of https://github.com/zkat/miette.git
feat(report): nicer, non-overlapping same-line highlights
This commit is contained in:
parent
084e1cdca9
commit
338c885a30
|
|
@ -576,23 +576,39 @@ impl GraphicalReportHandler {
|
||||||
}
|
}
|
||||||
writeln!(f, "{}", underlines)?;
|
writeln!(f, "{}", underlines)?;
|
||||||
|
|
||||||
for hl in single_liners {
|
let vbar_offsets: Vec<_> = single_liners
|
||||||
|
.iter()
|
||||||
|
.map(|hl| {
|
||||||
|
(
|
||||||
|
hl,
|
||||||
|
(hl.offset() - line.offset) + (std::cmp::max(1, hl.len()) / 2),
|
||||||
|
)
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
for hl in single_liners.iter().rev() {
|
||||||
if let Some(label) = hl.label() {
|
if let Some(label) = hl.label() {
|
||||||
self.write_no_linum(f, linum_width)?;
|
self.write_no_linum(f, linum_width)?;
|
||||||
self.render_highlight_gutter(f, max_gutter, line, all_highlights)?;
|
self.render_highlight_gutter(f, max_gutter, line, all_highlights)?;
|
||||||
let hl_len = std::cmp::max(1, hl.len());
|
let mut curr_offset = 1usize;
|
||||||
let local_offset = hl.offset() - line.offset;
|
for (offset_hl, vbar_offset) in &vbar_offsets {
|
||||||
let vbar_offset = local_offset + (hl_len / 2);
|
while curr_offset < *vbar_offset + 1 {
|
||||||
let num_right = local_offset + hl_len - vbar_offset - 1;
|
write!(f, " ")?;
|
||||||
let lines = format!(
|
curr_offset += 1;
|
||||||
"{:width$}{}{} {}",
|
}
|
||||||
"",
|
if *offset_hl != hl {
|
||||||
chars.lbot,
|
write!(f, "{}", chars.vbar.to_string().style(offset_hl.style))?;
|
||||||
chars.hbar.to_string().repeat(num_right + 1),
|
curr_offset += 1;
|
||||||
label,
|
} else {
|
||||||
width = vbar_offset
|
let lines = format!(
|
||||||
);
|
"{}{} {}",
|
||||||
writeln!(f, "{}", lines.style(hl.style))?;
|
chars.lbot,
|
||||||
|
chars.hbar.to_string().repeat(2),
|
||||||
|
label,
|
||||||
|
);
|
||||||
|
writeln!(f, "{}", lines.style(hl.style))?;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
@ -729,12 +745,19 @@ impl Line {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
struct FancySpan {
|
struct FancySpan {
|
||||||
label: Option<String>,
|
label: Option<String>,
|
||||||
span: SourceSpan,
|
span: SourceSpan,
|
||||||
style: Style,
|
style: Style,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl PartialEq for FancySpan {
|
||||||
|
fn eq(&self, other: &Self) -> bool {
|
||||||
|
self.label == other.label && self.span == other.span
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl FancySpan {
|
impl FancySpan {
|
||||||
fn new(label: Option<String>, span: SourceSpan, style: Style) -> Self {
|
fn new(label: Option<String>, span: SourceSpan, style: Style) -> Self {
|
||||||
FancySpan { label, span, style }
|
FancySpan { label, span, style }
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue