fix: 3 bugs from peer code review
- justify: gate DIM/RESET separator coloring on color_enabled param; previously leaked ANSI escapes when --color=never or NO_COLOR was set - vcs: apply branch name truncation per config (truncate.enabled, truncate.max, truncate.style) for both git and jj renderers; previously ignored truncate config causing long branch names to overflow and trigger unnecessary priority drops - flex: account for prefix/suffix overhead when computing context_bar flex expansion width; previously double-applied apply_formatting causing line to overshoot term_width when prefix/suffix configured Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -44,12 +44,14 @@ pub fn flex_expand(active: &mut [ActiveSection], ctx: &RenderContext, separator:
|
|||||||
ansi: padding,
|
ansi: padding,
|
||||||
};
|
};
|
||||||
} else if active[idx].id == "context_bar" {
|
} else if active[idx].id == "context_bar" {
|
||||||
// Rebuild context_bar with wider bar_width
|
// Rebuild context_bar with wider bar_width.
|
||||||
|
// Account for prefix/suffix that apply_formatting will add,
|
||||||
|
// so the final width doesn't overshoot term_width.
|
||||||
|
let base = &ctx.config.sections.context_bar.base;
|
||||||
|
let fmt_overhead = formatting_overhead(base);
|
||||||
let cur_bar_width = ctx.config.sections.context_bar.bar_width;
|
let cur_bar_width = ctx.config.sections.context_bar.bar_width;
|
||||||
let new_bar_width = cur_bar_width + extra as u16;
|
let new_bar_width = cur_bar_width + extra.saturating_sub(fmt_overhead) as u16;
|
||||||
if let Some(mut output) = section::context_bar::render_at_width(ctx, new_bar_width) {
|
if let Some(mut output) = section::context_bar::render_at_width(ctx, new_bar_width) {
|
||||||
// Re-apply formatting after flex rebuild
|
|
||||||
let base = &ctx.config.sections.context_bar.base;
|
|
||||||
format::apply_formatting(
|
format::apply_formatting(
|
||||||
&mut output.raw,
|
&mut output.raw,
|
||||||
&mut output.ansi,
|
&mut output.ansi,
|
||||||
@@ -66,6 +68,13 @@ pub fn flex_expand(active: &mut [ActiveSection], ctx: &RenderContext, separator:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Calculate display width of prefix + suffix that apply_formatting will add.
|
||||||
|
fn formatting_overhead(base: &crate::config::SectionBase) -> usize {
|
||||||
|
let pfx = base.prefix.as_deref().map_or(0, format::display_width);
|
||||||
|
let sfx = base.suffix.as_deref().map_or(0, format::display_width);
|
||||||
|
pfx + sfx
|
||||||
|
}
|
||||||
|
|
||||||
fn line_width(active: &[ActiveSection], separator: &str) -> usize {
|
fn line_width(active: &[ActiveSection], separator: &str) -> usize {
|
||||||
let sep_w = format::display_width(separator);
|
let sep_w = format::display_width(separator);
|
||||||
let mut total = 0;
|
let mut total = 0;
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ pub fn justify(
|
|||||||
term_width: u16,
|
term_width: u16,
|
||||||
separator: &str,
|
separator: &str,
|
||||||
_mode: JustifyMode,
|
_mode: JustifyMode,
|
||||||
|
color_enabled: bool,
|
||||||
) -> String {
|
) -> String {
|
||||||
let content_width: usize = active
|
let content_width: usize = active
|
||||||
.iter()
|
.iter()
|
||||||
@@ -37,11 +38,15 @@ pub fn justify(
|
|||||||
if i > 0 {
|
if i > 0 {
|
||||||
let this_gap = gap_width + usize::from(i - 1 < gap_remainder);
|
let this_gap = gap_width + usize::from(i - 1 < gap_remainder);
|
||||||
let gap_str = build_gap(sep_core, sep_core_len, this_gap);
|
let gap_str = build_gap(sep_core, sep_core_len, this_gap);
|
||||||
output.push_str(&format!(
|
if color_enabled {
|
||||||
"{}{gap_str}{}",
|
output.push_str(&format!(
|
||||||
crate::color::DIM,
|
"{}{gap_str}{}",
|
||||||
crate::color::RESET
|
crate::color::DIM,
|
||||||
));
|
crate::color::RESET
|
||||||
|
));
|
||||||
|
} else {
|
||||||
|
output.push_str(&gap_str);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
output.push_str(&sec.output.ansi);
|
output.push_str(&sec.output.ansi);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -109,6 +109,7 @@ fn render_line(section_ids: &[String], ctx: &RenderContext, separator: &str) ->
|
|||||||
ctx.term_width,
|
ctx.term_width,
|
||||||
separator,
|
separator,
|
||||||
ctx.config.global.justify,
|
ctx.config.global.justify,
|
||||||
|
ctx.color_enabled,
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
flex::flex_expand(&mut active, ctx, separator);
|
flex::flex_expand(&mut active, ctx, separator);
|
||||||
|
|||||||
@@ -82,7 +82,13 @@ fn render_git(
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let branch = status.branch.as_deref().unwrap_or("?");
|
let branch_raw = status.branch.as_deref().unwrap_or("?");
|
||||||
|
let trunc = &ctx.config.sections.vcs.truncate;
|
||||||
|
let branch = if trunc.enabled && trunc.max > 0 {
|
||||||
|
crate::format::truncate(branch_raw, trunc.max, &trunc.style)
|
||||||
|
} else {
|
||||||
|
branch_raw.to_string()
|
||||||
|
};
|
||||||
let branch_glyph = glyph::glyph("branch", glyphs);
|
let branch_glyph = glyph::glyph("branch", glyphs);
|
||||||
let dirty_glyph = if status.is_dirty && ctx.config.sections.vcs.show_dirty {
|
let dirty_glyph = if status.is_dirty && ctx.config.sections.vcs.show_dirty {
|
||||||
glyph::glyph("dirty", glyphs)
|
glyph::glyph("dirty", glyphs)
|
||||||
@@ -154,6 +160,13 @@ fn render_jj(
|
|||||||
Some(out)
|
Some(out)
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
|
let trunc = &ctx.config.sections.vcs.truncate;
|
||||||
|
let branch = if trunc.enabled && trunc.max > 0 {
|
||||||
|
crate::format::truncate(&branch, trunc.max, &trunc.style)
|
||||||
|
} else {
|
||||||
|
branch
|
||||||
|
};
|
||||||
|
|
||||||
let branch_glyph = glyph::glyph("branch", glyphs);
|
let branch_glyph = glyph::glyph("branch", glyphs);
|
||||||
let raw = format!("{branch_glyph}{branch}");
|
let raw = format!("{branch_glyph}{branch}");
|
||||||
let ansi = if ctx.color_enabled {
|
let ansi = if ctx.color_enabled {
|
||||||
|
|||||||
Reference in New Issue
Block a user