Skip to content

fix: scale progress bars based on terminal width#237

Open
wabalabudabdab wants to merge 5 commits intojarrodwatts:mainfrom
wabalabudabdab:fix/adaptive-bar-width
Open

fix: scale progress bars based on terminal width#237
wabalabudabdab wants to merge 5 commits intojarrodwatts:mainfrom
wabalabudabdab:fix/adaptive-bar-width

Conversation

@wabalabudabdab
Copy link

Problem

Progress bars (coloredBar/quotaBar) were hardcoded to width: 10 in session-line.ts, lines/identity.ts, and lines/usage.ts, causing line wrapping and broken layout in narrow terminals.

Closes #231

Solution

Added a getBarWidth() helper that reads process.stdout.columns and returns an appropriate width:

Terminal width Bar width
≥ 100 cols 10 (default)
60–99 cols 6
< 60 cols 4

Changes

  • src/render/session-line.ts — context bar + usage quota bars
  • src/render/lines/identity.ts — context bar in expanded layout
  • src/render/lines/usage.ts — quota bars in expanded layout

Build passes with npm run build

Resolves jarrodwatts#231

Progress bars (coloredBar/quotaBar) were hardcoded to width 10,
causing line wrapping in narrow terminals.

Now bars scale dynamically based on process.stdout.columns:
- Wide terminal (>=100 cols): width 10 (default)
- Medium terminal (60-99 cols): width 6
- Narrow terminal (<60 cols): width 4

Affected files:
- src/render/session-line.ts (context bar + usage bars)
- src/render/lines/identity.ts (context bar in expanded layout)
- src/render/lines/usage.ts (quota bars in expanded layout)
For cross-platform compatibility (zsh, macOS, Windows),
getBarWidth() now also checks process.env.COLUMNS when
process.stdout.columns is unavailable (non-TTY, piped output).
- Remove duplicated getBarWidth() from 3 render files
- Add src/utils/terminal.ts with exported getAdaptiveBarWidth()
- Add Math.floor() for consistency with getTerminalWidth()
- All 3 render files now import from shared utility (DRY)
Tests cover:
- Narrow terminal (<60 cols) → 4
- Medium terminal (60-99 cols) → 6
- Wide terminal (>=100 cols) → 10
- Boundary values (59, 60, 99, 100)
- Non-TTY/piped output (undefined columns) → 10 (default)
- Fallback to COLUMNS env var
- No terminal info at all → 10 (default)
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.

Feature: auto-scale progress bars based on terminal width

1 participant