Skip to content

feat(render) 03 - Migrate src/render/team-pick.ts to use src/render/terminal.ts #143

Description

@shouze

EPIC: #140
Branch: feat/bun14-terminal
Depends on: #141
Parallelizable with: #142
Blocks: #144


Context / Problem

renderTeamPickHeader() in src/render/team-pick.ts computes the sliding window width using text.length (UTF-16 code units) and truncates with .slice().

A team name containing a wide character produces an overflow or a misaligned truncation. Concrete example: "[ squad-\u{1F916} ]" (a team name with a robot emoji) has .length === 13 but occupies 14 terminal columns. The sliding window overflows by one column. A team name with two CJK characters (e.g. "\u524D\u7AEF") similarly miscounts.

Solution

Two targeted replacements in renderTeamPickHeader():

  1. widths[i] = texts[i].length -> widths[i] = visibleWidth(texts[i])
  2. texts[safeIndex].slice(0, maxWidth - 1) + "..." -> clipToWidth(texts[safeIndex], maxWidth - 1) + "..."

The remaining windowing calculations (addCost, totalWidth, EL_LEFT, EL_RIGHT) already read from widths[i] and require no further changes once the width values are correct.

src/render/team-pick.ts imports from src/render/terminal.ts only. It does not call Bun.stringWidth, Bun.sliceAnsi, or Bun.stripANSI directly.

Acceptance Criteria

  • src/render/team-pick.ts no longer uses .length to compute candidate text widths.
  • src/render/team-pick.ts does not call Bun.stringWidth, Bun.sliceAnsi, or Bun.stripANSI directly.
  • src/render/team-pick.test.ts - new test cases:
    • Candidate with a wide character in the name (e.g. "squad-\u{1F916}") and a constrained maxWidth: visibleWidth(stripAnsi(output)) <= maxWidth.
    • Candidates with CJK characters (e.g. "\u524D\u7AEF-team") and a constrained maxWidth: same assertion.
    • A candidate long enough to require truncation at a grapheme cluster boundary: the cut does not split a multi-code-point sequence.
    • Unconstrained bar with Unicode team names: rendered output does not overflow.
  • All existing tests in src/render/team-pick.test.ts still pass.
  • bun test src/render/team-pick.test.ts passes.
  • bun run lint and bun run format:check are clean.

Definition of Done

  • PR reviewed and merged into feat/bun14-terminal.
  • Zero lint errors, zero format diff, test suite green.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions