Skip to content

Add auto-wrap to statusline for narrow terminals - #9

Draft
Jn-Huang wants to merge 1 commit into
mainfrom
feature/statusline-autowrap
Draft

Add auto-wrap to statusline for narrow terminals#9
Jn-Huang wants to merge 1 commit into
mainfrom
feature/statusline-autowrap

Conversation

@Jn-Huang

@Jn-Huang Jn-Huang commented Apr 6, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Auto-wrap statusline into two lines when content exceeds available terminal width
  • Line 1: user, path, git branch/status
  • Line 2: lambda, model name, context usage
  • Detect real terminal width by walking parent process tree to find the TTY (technique from claude-powerline), reserves 30% for Claude Code's right-side UI
  • Trim deep paths to at most 2 trailing components (e.g. ~/.../parent/dir)
  • Fix $HOME substitution in piped subprocess context

Test plan

  • Short path stays on 1 line
  • Long path + model + context wraps to 2 lines
  • Deep paths trimmed correctly (~/.../parent/dir)
  • TTY width detection works via parent process walk
  • Confirm rendering in Claude Code UI

🤖 Generated with Claude Code

@Jn-Huang

Jn-Huang commented Apr 6, 2026

Copy link
Copy Markdown
Contributor Author

@claude review this pr

@claude

claude Bot commented Apr 6, 2026

Copy link
Copy Markdown

Claude finished @Jn-Huang's task in 1m 5s —— View job


PR Review

  • Read changed files and diff
  • Review code for correctness, style, and edge cases
  • Post review feedback

Overall this is a clean, well-structured implementation. The approach of pre-building both line parts and measuring visible length is sound. A few things worth noting:

Correctness

  • wc -m (line 60) is the right choice over wc -c — it counts characters rather than bytes, which correctly handles the multi-byte λ character. However, wc -m depends on the locale being UTF-8 aware. If LANG or LC_ALL is unset or set to C, it may count bytes instead of characters and produce an off-by-one for λ. This is unlikely to matter in practice but worth knowing.
  • sed 's/\x1b\[[0-9;]*m//g' (line 60) — the \x1b hex escape works in GNU sed (Linux) but not BSD sed (macOS). Since this is a bash script targeting Linux cluster environments, this is fine, but if portability to macOS ever matters, the safer form is $'\033' or using printf '\033' as a separator.

Edge case: non-numeric $COLUMNS

cols=${COLUMNS:-$(tput cols 2>/dev/null || echo 120)}

If COLUMNS is set but contains a non-numeric value (e.g., it was exported with garbage), the [ "$visible_len" -gt "$cols" ] comparison on line 65 will error with integer expression expected and the script will fall through to printing $full_line (since the if branch won't execute). This is a reasonable degradation behavior, but you could guard against it: Fix this →

Style

  • The two-line wrapped output has no leading space before λ on line 2, while the single-line version has a space separator (${line1} ${line2}). This is intentional and looks correct per the PR description.
  • Comment on line 59 ("Measure visible length") is clear and useful — good.

Minor nit

wc -m output can include leading whitespace (e.g., " 42"). Bash's [ builtin handles this correctly in arithmetic comparisons, so no issue in practice — just worth being aware of if this logic is ever ported elsewhere.

Verdict: Looks good to merge. The fallback chain ($COLUMNStput cols120) is well-thought-out, and the logic is clean. The non-numeric $COLUMNS edge case is the only thing worth addressing.

Detect real terminal width by walking the parent process tree to find
the TTY, then reserve 30% for Claude Code's right-side UI elements.

Layout adapts progressively to fit:
  1. Wide: everything on a single line
  2. Medium: 2 lines — full path + full branch / model + context
  3. Narrow: 2 lines — basename path + full branch
  4. Very narrow: 2 lines — basename + truncated branch (12 chars)

Also:
- Trim deep paths to 2 trailing components (~/.../parent/dir)
- Strip parenthetical suffixes from model name (e.g. "(1M context)")

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@Jn-Huang
Jn-Huang force-pushed the feature/statusline-autowrap branch from dd6aed3 to 5939c12 Compare April 6, 2026 17:54
@Jn-Huang
Jn-Huang marked this pull request as draft April 6, 2026 17:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant