Skip to content

Narrow terminal crash: rendered powerline line exceeds terminal width #4

Description

@davidmoshal

Summary

pi-powerline can render a footer/status line wider than the terminal, causing pi's TUI to crash with an uncaught render-width exception in narrow terminals.

Error

pi exiting due to uncaughtException:
Error: Rendered line 10422 exceeds terminal width (45 > 31).

This is likely caused by a custom TUI component not truncating its output.
Use visibleWidth() to measure and truncateToWidth() to truncate lines.

Debug log written to: /Users/davem/.pi/agent/pi-crash.log
    at TUI.doRender (.../@earendil-works/pi-tui/dist/tui.js:1252:23)

A later crash log from a 27-column terminal showed the offending line:

Terminal width: 27
Line 2815 visible width: 45

[2815] (w=45)  ─── ◈ pi / dm ──────────────────────────────
[2816] (w=27)  ─ Kimi K2.7 Code / pi ─────

The over-wide line appears to be the powerline breadcrumb/status segment containing project/branch info (pi / dm) plus a fixed-width separator.

Expected behavior

All rendered lines should fit within the width passed to the component renderer. On narrow terminals, the statusline should truncate or drop segments rather than emitting a line wider than the terminal.

Actual behavior

A rendered footer line exceeded terminal width, and pi exited due to the TUI invariant violation.

Environment

  • Package: pi-powerline 0.8.0
  • pi: 0.79.10
  • Terminal width in crash log: 27 columns
  • Model/session at time: Fireworks Kimi, branch dm

Suggested fix

Ensure every rendered line uses pi-tui width helpers before returning:

  • visibleWidth() to measure rendered ANSI strings
  • truncateToWidth() or equivalent segment-dropping logic before return

For powerline-style bars, a robust approach is:

  1. reserve prompt/editor width first;
  2. render segments in priority order;
  3. drop low-priority segments as width shrinks;
  4. truncate the final segment/separator to the exact remaining width;
  5. assert every returned line is <= width in tests, including widths under 30 columns.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions