Skip to content

Commit 5876d8d

Browse files
cursoragentechobt
andcommitted
fix(tui): keep splash legend when version is longer
Ellipsize v{version} instead of dropping @ files · ! shell so 40x12 chrome stays complete for v0.1.10 and later. Co-authored-by: Mathis <echobt@users.noreply.github.com>
1 parent 582ff4b commit 5876d8d

2 files changed

Lines changed: 51 additions & 34 deletions

File tree

src/cortex-tui/src/lock_boards.rs

Lines changed: 38 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -785,26 +785,51 @@ fn bar(filled: u16, total: u16) -> String {
785785
s
786786
}
787787

788-
/// Splash hint row: full, 40-col, or short — picked by character budget.
789-
/// Uses the full area width (not [`inner_width`]) so `v0.1.10` still fits
790-
/// the 40-column mid form `v{version} · / commands · @ files · ! shell`.
788+
/// Join `v{version}` to a hint legend, ellipsizing the version — never the
789+
/// legend — when the pair is wider than `width`.
791790
pub(crate) fn splash_legend(version: &str, width: usize) -> String {
792-
let full_h = format!("v{version} · {LAUNCH_HINTS}");
793-
let mid_h = format!("v{version} · {LAUNCH_HINTS_NARROW}");
794-
if full_h.chars().count() <= width {
795-
full_h
796-
} else if mid_h.chars().count() <= width {
797-
mid_h
798-
} else {
799-
format!("v{version} · / commands")
791+
let ver = format!("v{version}");
792+
for legend in [LAUNCH_HINTS, LAUNCH_HINTS_NARROW] {
793+
let line = format!("{ver} · {legend}");
794+
if line.chars().count() <= width {
795+
return line;
796+
}
797+
}
798+
// Keep `/ commands · @ files · ! shell` (and `& cloud` when it fits).
799+
// A longer package version is shortened; the keystroke legend is not.
800+
for legend in [LAUNCH_HINTS, LAUNCH_HINTS_NARROW] {
801+
let suffix = format!(" · {legend}");
802+
let suffix_len = suffix.chars().count();
803+
if suffix_len >= width {
804+
continue;
805+
}
806+
let shown = ellipsis_prefix(&ver, width - suffix_len);
807+
if shown.is_empty() {
808+
continue;
809+
}
810+
return format!("{shown}{suffix}");
811+
}
812+
LAUNCH_HINTS_NARROW.to_string()
813+
}
814+
815+
fn ellipsis_prefix(text: &str, budget: usize) -> String {
816+
if text.chars().count() <= budget {
817+
return text.to_string();
818+
}
819+
if budget == 0 {
820+
return String::new();
821+
}
822+
if budget == 1 {
823+
return "…".to_string();
800824
}
825+
format!("{}…", text.chars().take(budget - 1).collect::<String>())
801826
}
802827

803828
/// Launch header: `Welcome to Cortex, the coding agent CLI` then
804829
/// `v{version} · / commands · …`. No fake `> cortex` or painted cwd.
805830
fn paint_launch_header(area: Rect, buf: &mut Buffer, full: bool) -> u16 {
806-
// Full terminal width: the 40-col lock is exactly the mid hint budget
807-
// once the package version is seven characters (`v0.1.10`).
831+
// Full terminal width so the 40-col lock can hold the mid legend; a
832+
// longer version is ellipsized instead of dropping `@ files · ! shell`.
808833
let w = area.width.max(1) as usize;
809834
let mut y = area.y;
810835
let dim = Style::default().fg(TEXT_DIM);

src/cortex-tui/src/lock_proof.rs

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2338,29 +2338,28 @@ mod tests {
23382338
}
23392339

23402340
#[test]
2341-
fn splash_legend_keeps_mid_hints_at_40_for_package_version() {
2342-
let version = env!("CARGO_PKG_VERSION");
2343-
let legend = crate::lock_boards::splash_legend(version, 40);
2344-
assert!(
2345-
legend.contains("/ commands · @ files · ! shell"),
2346-
"40-col splash must keep mid hints for v{version}: {legend}"
2347-
);
2348-
assert!(
2349-
!legend.contains("& cloud"),
2350-
"40-col splash shortens before & cloud: {legend}"
2351-
);
2341+
fn splash_legend_keeps_mid_hints_when_version_grows() {
2342+
for version in [env!("CARGO_PKG_VERSION"), "0.1.10", "10.20.30-rc.1"] {
2343+
let legend = crate::lock_boards::splash_legend(version, 40);
2344+
assert!(
2345+
legend.contains("/ commands · @ files · ! shell"),
2346+
"40-col splash must keep mid hints for v{version}: {legend}"
2347+
);
2348+
assert!(
2349+
!legend.contains("& cloud"),
2350+
"40-col splash shortens before & cloud: {legend}"
2351+
);
2352+
}
23522353
}
23532354

23542355
#[test]
23552356
fn splash_has_session_chrome() {
2356-
let version = env!("CARGO_PKG_VERSION");
2357-
let mid = format!("v{version} · / commands · @ files · ! shell");
23582357
for size in SIZES {
23592358
let frame = render_lock_scene("splash", size.0, size.1).expect("splash");
23602359
for needle in [
23612360
"Welcome to",
23622361
"the coding agent CLI",
2363-
"/ commands",
2362+
"/ commands · @ files · ! shell",
23642363
"Plan, search, build anything",
23652364
"Cortex Mini 1",
23662365
] {
@@ -2370,13 +2369,6 @@ mod tests {
23702369
frame.plain
23712370
);
23722371
}
2373-
if mid.chars().count() <= size.0 as usize {
2374-
assert!(
2375-
frame.plain.contains(&mid),
2376-
"splash missing mid chrome `{mid}` at {size:?}:\n{}",
2377-
frame.plain
2378-
);
2379-
}
23802372
assert!(!frame.plain.contains("▄█▀▀▀▀█▄"), "{}", frame.plain);
23812373
assert!(
23822374
!frame.plain.contains("> cortex"),

0 commit comments

Comments
 (0)