Skip to content

feat(hud): adaptive layout engine (Wave 1-D) #1472

@JeremyDev87

Description

@JeremyDev87

Problem

StatusBar overflows in narrow terminals (<80 cols). Current inline segment assembly in format_status_line has no width awareness — long model names like Opus 4.6 (1M context) and trailing segments (RL, worktree) get cut mid-word.

Fix (Wave 1-D)

New lib/hud_layout.py module with adaptive rendering primitives:

  • SEGMENT_PRIORITY — canonical drop order (9 slots: face_version, mode_health, cost, duration, ctx, cache, model, rate_limits, worktree)
  • SACRED_PRIORITY = 1 — face_version and mode_health are never dropped
  • visible_len(s) — width-aware column count (emoji/CJK count as 2)
  • terminal_width(*, fallback) — shutil-backed detection with safe fallback
  • shorten_model_label(name, *, compact=False) — "Opus 4.6 (1M context)" → "Opus 4.6" (normal) or "Opus(1M)" (compact)
  • fit_segments(segments, width, *, separator) — priority-based drop-until-fit with hard-truncate fallback

Tests

33 new tests in test_hud_layout.py:

  • visible_len: ASCII, CJK, emoji, mixed, empty
  • terminal_width: zero/fallback/custom/real
  • shorten_model_label: strip/keep/compact/empty/case-insensitive
  • fit_segments: all-fit, drop-low, sacred-preserved, empty-skip, hard-truncate, order preservation, highest-priority-first, custom separator, width=0/1, empty list
  • SEGMENT_PRIORITY: sacred entries, non-decreasing, full slot coverage

188/188 tests pass

Wave 3 integration

Wave 1-D only ships the layout helpers. Wave 3 integrator will wire fit_segments into format_status_line replacing the inline " | ".join(segments).

Part of #1464 (Wave 0 statusbar refactor)

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