Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
fix(statusline): treat COLUMNS=0 as no width, not a zero budget (#3318)
Worktrunk Bot1d2b834eccb1
diff --git a/src/styling/mod.rs b/src/styling/mod.rsindex 11eb13b08..be8287531 100644--- a/src/styling/mod.rs+++ b/src/styling/mod.rs@@ -79,7 +79,8 @@ pub fn verbosity() -> u8 {/// 2. The `COLUMNS` env var, for scripts and piped contexts where detection/// fails. `COLUMNS` carries a width but has no height counterpart, so the/// height comes back `None`; callers that need a height supply their own-/// fallback.+/// fallback. A `COLUMNS` of `0` is treated as no width at all (returns+/// `None`), so absurd values fall through to untruncated rendering.////// Under Claude Code the statusline subprocess inherits no TTY, so direct/// detection fails and the `COLUMNS` fallback supplies the width — Claude Code@@ -97,8 +98,16 @@ pub fn terminal_dimensions() -> Option<(usize, Option<usize>)> {}// Fall back to COLUMNS (width only — there is no height equivalent) for- // scripts, piped contexts, or when detection fails.- let columns = std::env::var("COLUMNS").ok()?.parse::<usize>().ok()?;+ // scripts, piped contexts, or when detection fails. A zero width is as+ // undetectable as no `COLUMNS` at all, so treat it as absent — otherwise+ // callers that subtract a margin (e.g. the statusline) collapse the+ // content budget to zero and drop every segment instead of falling+ // through to an untruncated render.+ let columns = std::env::var("COLUMNS")+ .ok()?+ .parse::<usize>()+ .ok()+ .filter(|c| *c > 0)?;Some((columns, None))}diff --git a/tests/integration_tests/statusline.rs b/tests/integration_tests/statusline.rsindex 992c00a39..9877f51cb 100644--- a/tests/integration_tests/statusline.rs+++ b/tests/integration_tests/statusline.rs@@ -894,3 +894,29 @@ fn test_statusline_rate_limit_drops_at_narrow_width(repo: TestRepo) {assert_snapshot!("rate_limit_drops_at_narrow_width", out);});}++#[rstest]+fn test_statusline_zero_columns_renders_untruncated(repo: TestRepo) {+ // Regression: `COLUMNS=0` is an absurd width. It must be treated as "no+ // detectable width" and fall through to the untruncated render — not+ // collapse the content budget to zero (after the statusline subtracts its+ // UI margin) and drop every segment. Compare against a wide terminal,+ // which also renders untruncated: the two must be identical and non-empty.+ let json = build_claude_code_json(+ repo.root_path(),+ Some("Opus"),+ Some(42.0),+ TEST_NOW_THU_1PM,+ &[("five_hour", 80.0, 2 * 3600)],+ );+ let zero = run_statusline_at_time(&repo, &json, TEST_NOW_THU_1PM, Some(0));+ let wide = run_statusline_at_time(&repo, &json, TEST_NOW_THU_1PM, Some(500));+ assert!(+ !zero.trim().is_empty(),+ "COLUMNS=0 must not collapse the statusline to empty"+ );+ assert_eq!(+ zero, wide,+ "COLUMNS=0 should render untruncated, identical to a wide terminal"+ );+}