Repository navigation
feat(terminal): Migrate to Bun 1.4 native terminal APIs and add live TUI resize [EPIC] #140
Copy link
Copy link
Closed
Feature
5 / 55 of 5 issues completed
Copy link
Labels
enhancementNew feature or requestNew feature or request
Description
Context / Problem
The TUI relies on three fragile in-house helpers in src/render.ts:
stripAnsi(str): a regex limited to SGR codes that misses OSC 8 terminal hyperlinks and cursor movement sequences (ESC[A,ESC[H...).clipAnsi(str, maxVisible): a manual character loop that treats every code point as exactly 1 column wide. Emoji, CJK characters, and multi-code-point grapheme clusters (flags, skin tone modifiers) are miscounted, causing line overflow or premature truncation.src/render/team-pick.tsuses.lengthdirectly to measure team name widths in the sliding window, with the same measurement flaw.
Additionally, termHeight is captured once at startup (const termHeight = process.stdout.rows ?? 40). Resizing the terminal window has no effect until the process is restarted.
Bun 1.4 ships Bun.stringWidth(), Bun.stripANSI(), Bun.sliceAnsi(), and Bun.wrapAnsi() as native built-in APIs, covering exactly these needs with SIMD-backed implementations (more than 6,000x faster than the equivalent npm packages according to the Bun 1.4 release notes). Bun 1.4 also adds SIGWINCH support on Windows, where it was previously unavailable.
Solution and Architecture Principles
- Pure module
src/render/terminal.ts: a single facade between application code and Bun 1.4 native APIs. No other source file callsBun.stringWidth,Bun.sliceAnsi, orBun.stripANSIdirectly. - Remove in-house helpers:
stripAnsiandclipAnsiinsrc/render.tsare deleted after migration. No parallel implementations are kept. - Mutable terminal dimensions in
tui.ts:termHeightandtermWidthbecomeletvariables refreshed fromprocess.stdout.rowsandprocess.stdout.columns; aSIGWINCHhandler triggers an immediate redraw. Bun.Terminalis out of scope: this API attaches a PTY to a child process. It does not represent the current interactive terminal. It may be used in a future integration test.Bun.wrapAnsifor multi-line content only: TUI rows must remain single-line;Bun.sliceAnsiis the right tool for truncation.Bun.wrapAnsiis only relevant if the help overlay is made responsive (not in this EPIC).- Bun 1.4+ required: these APIs are called without a fallback. The minimum runtime version is documented in
README.mdandAGENTS.md. - Existing layering preserved:
src/render/terminal.tsis a pure module (no I/O), consumed through the existingsrc/render.tsfacade.
Sub-issue Dependency Graph
flowchart LR
I01["01 - terminal.ts\nno dependencies"]
I02["02 - render.ts\nmigration"]
I03["03 - team-pick.ts\nmigration"]
I04["04 - SIGWINCH\nlive resize"]
I05["05 - Documentation"]
I01 --> I02
I01 --> I03
I02 --> I04
I03 --> I04
I04 --> I05
02 and 03 can be worked in parallel once 01 is merged.
Acceptance Criteria
-
Bun.stringWidth,Bun.stripANSI, andBun.sliceAnsiare called exclusively fromsrc/render/terminal.ts. - The
stripAnsiandclipAnsihelpers are deleted fromsrc/render.ts. -
src/render/team-pick.tsno longer uses.lengthto measure team name widths. - Resizing the terminal window during a TUI session triggers an immediate redraw without any keypress.
-
bun test,bun run lint,bun run format:check,bun run knip, andbun run build.tsall pass. -
docs/architecture/andAGENTS.mdreflect the newterminal.tslayer. -
README.mdexplicitly states Bun 1.4+ as the minimum runtime requirement.
Definition of Done
- All sub-issues 01 through 05 are merged into branch
feat/bun14-terminal. - The feature branch is merged into
mainvia a reviewed PR. - A minor release is published following
AGENTS.md - Release process.
Sub-issues (execution order)
- feat(terminal) 01 - Create src/render/terminal.ts - Bun 1.4 native API facade #141 - 01:
src/render/terminal.tsBun 1.4 native API facade (no dependencies, start here) - feat(render) 02 - Migrate src/render.ts to use src/render/terminal.ts #142 - 02: Migrate
src/render.ts(depends on 01) - feat(render) 03 - Migrate src/render/team-pick.ts to use src/render/terminal.ts #143 - 03: Migrate
src/render/team-pick.ts(depends on 01, parallelizable with 02) - feat(tui) 04 - Live TUI resize via SIGWINCH #144 - 04: Live resize via
SIGWINCH(depends on 02 and 03) - docs 05 - Update architecture documentation and runtime requirements (Bun 1.4+) #145 - 05: Architecture documentation and runtime requirements (depends on 01 to 04)
Branch
feat/bun14-terminal
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request
Activity
[-]feat(terminal): Migration vers les APIs natives Bun 1.4 + redimensionnement live du TUI [EPIC][/-][+]feat(terminal): Migrate to Bun 1.4 native terminal APIs and add live TUI resize [EPIC][/+]