Skip to content

Commit a06f78d

Browse files
max-sixtyclaude
andauthored
refactor: simplify escape code handling in wt select (#558)
- Replace verbose anstyle::Style API with cformat! macros in render_preview_tabs - Use write!() macro instead of multiple push_str() calls in process_log_with_dimming - Removes intermediate String allocations from .to_string() calls Co-authored-by: Claude <noreply@anthropic.com>
1 parent 03f9118 commit a06f78d

File tree

1 file changed

+13
-22
lines changed

1 file changed

+13
-22
lines changed

src/commands/select.rs

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -407,16 +407,13 @@ impl WorktreeSkimItem {
407407
/// and unselected modes dimmed. Controls shown below in normal text
408408
/// for visual distinction from inactive tabs.
409409
fn render_preview_tabs(mode: PreviewMode) -> String {
410-
use anstyle::Style;
411-
412410
/// Format a tab label with bold (active) or dimmed (inactive) styling
413411
fn format_tab(label: &str, is_active: bool) -> String {
414-
let style = if is_active {
415-
Style::new().bold()
412+
if is_active {
413+
cformat!("<bold>{}</>", label)
416414
} else {
417-
Style::new().dimmed()
418-
};
419-
format!("{}{}{}", style.render(), label, style.render_reset())
415+
cformat!("<dim>{}</>", label)
416+
}
420417
}
421418

422419
let tab1 = format_tab("1: HEAD±", mode == PreviewMode::WorkingTree);
@@ -425,14 +422,8 @@ impl WorktreeSkimItem {
425422
let tab4 = format_tab("4: remote⇅", mode == PreviewMode::UpstreamDiff);
426423

427424
// Controls use dim yellow to distinguish from dimmed (white) tabs
428-
// while remaining subdued
429-
let controls_style = Style::new()
430-
.dimmed()
431-
.fg_color(Some(anstyle::Color::Ansi(anstyle::AnsiColor::Yellow)));
432-
let controls = format!(
433-
"{}Enter: switch | Esc: cancel | ctrl-u/d: scroll | alt-p: toggle{}",
434-
controls_style.render(),
435-
controls_style.render_reset()
425+
let controls = cformat!(
426+
"<dim,yellow>Enter: switch | Esc: cancel | ctrl-u/d: scroll | alt-p: toggle</>"
436427
);
437428

438429
format!(
@@ -799,6 +790,7 @@ fn process_log_with_dimming(
799790
unique_commits: Option<&HashSet<String>>,
800791
) -> (String, Vec<String>) {
801792
use ansi_str::AnsiStr;
793+
use std::fmt::Write;
802794

803795
let dim = anstyle::Style::new().dimmed();
804796
let reset = anstyle::Reset;
@@ -838,13 +830,12 @@ fn process_log_with_dimming(
838830
result.push_str(display);
839831
} else {
840832
// Dim: strip colors and wrap in dim style, but keep hash markers
841-
result.push_str(graph_prefix);
842-
result.push(HASH_START);
843-
result.push_str(full_hash);
844-
result.push(HASH_END);
845-
result.push_str(&dim.to_string());
846-
result.push_str(&display.ansi_strip());
847-
result.push_str(&reset.to_string());
833+
let _ = write!(
834+
result,
835+
"{}{HASH_START}{full_hash}{HASH_END}{dim}{}{reset}",
836+
graph_prefix,
837+
display.ansi_strip()
838+
);
848839
}
849840
continue;
850841
}

0 commit comments

Comments
 (0)