|
| 1 | +--- |
| 2 | +title: "RexCLI TUI Refactor: Modern Terminal UI with React Ink" |
| 3 | +description: "RexCLI migrated its TUI installer from manual string rendering to a React Ink + Ink UI component architecture, improving both the interactive experience and code maintainability." |
| 4 | +date: 2026-04-02 |
| 5 | +tags: [RexCLI, TUI, Ink, React, Terminal, Onboarding] |
| 6 | +--- |
| 7 | + |
| 8 | +# RexCLI TUI Refactor: Modern Terminal UI with React Ink |
| 9 | + |
| 10 | +The previous TUI installer used manual string concatenation to render the interface — high maintenance cost and a basic interactive experience. This refactor migrates it to a **React Ink + Ink UI** component architecture, making terminal interaction more modern. |
| 11 | + |
| 12 | +## Why Refactor |
| 13 | + |
| 14 | +The old TUI implementation had several problems: |
| 15 | + |
| 16 | +- Manual ANSI string concatenation for colors and layout; changing one place easily broke others |
| 17 | +- No real component abstraction; state management scattered across the codebase |
| 18 | +- No routing concept; screen transitions written in a scattered way |
| 19 | + |
| 20 | +Ink is a React renderer designed specifically for the terminal, enabling React component patterns for CLI interaction UIs. Combined with Ink UI's built-in components (`Select`, `TextInput`, `ConfirmInput`), development is greatly simplified. |
| 21 | + |
| 22 | +## New Architecture |
| 23 | + |
| 24 | +``` |
| 25 | +scripts/lib/tui-ink/ |
| 26 | +├── App.tsx # MemoryRouter + Routes configuration |
| 27 | +├── index.tsx # render() entry point |
| 28 | +├── hooks/ |
| 29 | +│ └── useSetupOptions.ts # Shared configuration state |
| 30 | +├── screens/ |
| 31 | +│ ├── MainScreen.tsx # Main menu |
| 32 | +│ ├── SetupScreen.tsx # Setup configuration |
| 33 | +│ ├── UpdateScreen.tsx # Update configuration |
| 34 | +│ ├── UninstallScreen.tsx # Uninstall configuration |
| 35 | +│ ├── DoctorScreen.tsx # Doctor configuration |
| 36 | +│ ├── SkillPickerScreen.tsx # Skill picker |
| 37 | +│ └── ConfirmScreen.tsx # Execution confirmation |
| 38 | +├── components/ |
| 39 | +│ ├── Header.tsx # Top header bar |
| 40 | +│ ├── Footer.tsx # Bottom shortcut hints |
| 41 | +│ ├── Checkbox.tsx # Checkbox component |
| 42 | +│ └── ScrollableSelect.tsx # Scrollable selection list |
| 43 | +└── types.ts # Shared type definitions |
| 44 | +``` |
| 45 | + |
| 46 | +### Route Navigation |
| 47 | + |
| 48 | +Screen switching is managed via `react-router`'s `MemoryRouter`: |
| 49 | + |
| 50 | +``` |
| 51 | +/ (MainScreen) |
| 52 | + → /setup |
| 53 | + → /update |
| 54 | + → /uninstall |
| 55 | + → /doctor |
| 56 | +
|
| 57 | +/setup → /skill-picker?owner=setup |
| 58 | +/setup → /confirm?action=setup |
| 59 | +
|
| 60 | +/skill-picker → Return to previous screen |
| 61 | +/confirm → Execute → Show result → Return to main menu |
| 62 | +``` |
| 63 | + |
| 64 | +### State Management |
| 65 | + |
| 66 | +The `useSetupOptions` hook provides global configuration state shared across screens: |
| 67 | + |
| 68 | +```typescript |
| 69 | +interface SetupOptions { |
| 70 | + components: { |
| 71 | + browser: boolean; |
| 72 | + shell: boolean; |
| 73 | + skills: boolean; |
| 74 | + superpowers: boolean; |
| 75 | + }; |
| 76 | + wrapMode: 'all' | 'repo-only' | 'opt-in' | 'off'; |
| 77 | + scope: 'global' | 'project'; |
| 78 | + client: 'all' | 'codex' | 'claude' | 'gemini' | 'opencode'; |
| 79 | + selectedSkills: string[]; |
| 80 | +} |
| 81 | +``` |
| 82 | + |
| 83 | +### Custom Components |
| 84 | + |
| 85 | +Ink UI's `Select` does not support scrollable window mode, so `ScrollableSelect` was implemented: |
| 86 | + |
| 87 | +- Keyboard ↑/↓ navigation |
| 88 | +- Space to select |
| 89 | +- Grouped display (Core / Optional) |
| 90 | +- Skill descriptions and installed markers |
| 91 | + |
| 92 | +## Dependencies |
| 93 | + |
| 94 | +```bash |
| 95 | +npm install ink @inkjs/ui react react-router |
| 96 | +``` |
| 97 | + |
| 98 | +- `ink` 4.x — React renderer for terminal |
| 99 | +- `@inkjs/ui` — Built-in interactive components |
| 100 | +- `react` 18.x + `react-router` 7.x |
| 101 | + |
| 102 | +Node version: project requires `>=22 <23`; Ink 4.x supports Node 18+, fully compatible. |
| 103 | + |
| 104 | +## Visual Effects |
| 105 | + |
| 106 | +- Current item: bold + cyan color |
| 107 | +- Installed marker: green `(installed)` |
| 108 | +- Description text: gray `dimColor` |
| 109 | +- Group headings: yellow or inverse |
| 110 | +- Error/success: red/green |
| 111 | + |
| 112 | +## Compatibility |
| 113 | + |
| 114 | +Non-interactive mode (no TTY) maintains the original CLI argument mode: |
| 115 | + |
| 116 | +```bash |
| 117 | +aios setup --components browser,shell --scope global |
| 118 | +aios update --client codex |
| 119 | +aios doctor |
| 120 | +``` |
| 121 | + |
| 122 | +The entry point detects TTY and automatically invokes the Ink version. |
| 123 | + |
| 124 | +## Related Links |
| 125 | + |
| 126 | +- Ink docs: <https://github.com/vadimdemedes/ink> |
| 127 | +- Ink UI docs: <https://github.com/vadimdemedes/ink-ui> |
| 128 | +- Design doc: `docs/superpowers/specs/2026-04-02-ink-tui-design.md` |
| 129 | +- Implementation plan: `docs/superpowers/plans/2026-04-02-ink-tui-refactor.md` |
0 commit comments