Detection Strategy
Terminal capabilities are detected at backend initialization:- Read environment variables (
TERM,COLORTERM,TERM_PROGRAM, etc.) - Parse terminal profile from detected values
- Apply overrides from explicit environment variables
- Negotiate with engine to enable supported features
packages/node/src/backend/terminalProfile.ts
Environment Variables
Core Variables
| Variable | Purpose | Example Values |
|---|---|---|
TERM | Terminal type | xterm-256color, screen-256color, dumb |
COLORTERM | Color support | truecolor, 24bit |
TERM_PROGRAM | Terminal emulator | iTerm.app, vscode, Apple_Terminal |
TERM_PROGRAM_VERSION | Emulator version | 3.4.0 |
CI Detection
| Variable | Meaning |
|---|---|
CI | Generic CI environment |
GITHUB_ACTIONS | GitHub Actions |
GITLAB_CI | GitLab CI |
CIRCLECI | CircleCI |
TRAVIS | Travis CI |
JENKINS_URL | Jenkins |
Explicit Overrides
| Variable | Purpose | Values |
|---|---|---|
ZRUI_TRUECOLOR | Force truecolor | 1 (enable) / 0 (disable) |
ZRUI_MOUSE | Force mouse events | 1 (enable) / 0 (disable) |
ZRUI_UNICODE | Force Unicode | 1 (enable) / 0 (disable) |
ZRUI_EMOJI_WIDTH | Emoji width policy | wide / narrow |
ZRUI_EMOJI_WIDTH_PROBE | Enable probing | 1 (enable) |
Terminal Capabilities
Truecolor Detection
Enabled when:COLORTERM=truecolororCOLORTERM=24bitTERM_PROGRAMis a known truecolor emulator (iTerm2, VS Code, Hyper, Alacritty, Kitty, WezTerm)TERMcontainstruecoloror24bit
TERM=dumbZRUI_TRUECOLOR=0
Unicode Detection
Enabled when:LANGorLC_ALLcontainsUTF-8orutf8TERMis notdumb
TERM=dumbZRUI_UNICODE=0
Mouse Detection
Enabled when:- Terminal is interactive (isatty)
- Not in CI environment
TERMis notdumb
CI=true(any CI)TERM=dumbZRUI_MOUSE=0
- SGR mouse encoding (preferred)
- UTF-8 mouse encoding (fallback)
- X10 mouse encoding (legacy)
Focus Tracking Detection
Enabled when:- Mouse events enabled
- Terminal supports focus events (most modern emulators)
- Mouse disabled
- CI environment
Known Terminal Profiles
iTerm2 (macOS)
Detected by:TERM_PROGRAM=iTerm.app
Capabilities:
- Truecolor: Yes
- Unicode: Yes
- Mouse: Yes
- Focus: Yes
VS Code Integrated Terminal
Detected by:TERM_PROGRAM=vscode
Capabilities:
- Truecolor: Yes
- Unicode: Yes
- Mouse: Yes
- Focus: Yes
Alacritty
Detected by:TERM=alacritty or TERM_PROGRAM=Alacritty
Capabilities:
- Truecolor: Yes
- Unicode: Yes
- Mouse: Yes
- Focus: Yes
Kitty
Detected by:TERM=xterm-kitty
Capabilities:
- Truecolor: Yes
- Unicode: Yes
- Mouse: Yes
- Focus: Yes
WezTerm
Detected by:TERM_PROGRAM=WezTerm
Capabilities:
- Truecolor: Yes
- Unicode: Yes
- Mouse: Yes
- Focus: Yes
Linux Console
Detected by:TERM=linux
Capabilities:
- Truecolor: No (256 colors)
- Unicode: Limited
- Mouse: No
- Focus: No
tmux/screen
Detected by:TERM=screen* or TERM=tmux*
Capabilities:
- Truecolor: Depends on
COLORTERM - Unicode: Yes (if parent terminal supports)
- Mouse: Yes (if parent terminal supports)
- Focus: Yes (if parent terminal supports)
CI Environments
Detected by:CI=true
Capabilities:
- Truecolor: No (256 colors for safety)
- Unicode: Yes
- Mouse: No
- Focus: No
Capability Negotiation
The backend negotiates capabilities with the engine:- User config (explicit overrides)
- Environment variable overrides (
ZRUI_*) - Detected capabilities
- Safe defaults
Emoji Width Policy
Emoji width detection aligns TypeScript layout with native rendering:Detection Strategy
packages/node/src/backend/emojiWidthPolicy.ts
Probing (Experimental)
WhenZRUI_EMOJI_WIDTH_PROBE=1:
- Write test emoji to terminal
- Query cursor position
- Measure cell width consumed
- Return
"wide"if 2 cells,"narrow"if 1 cell
- Requires interactive terminal
- Adds ~10-50ms latency to startup
- May not work in all emulators
Default Capabilities
When detection fails or no terminal is attached:Testing Terminal Detection
Test different profiles:Related Documentation
- Node.js Backend — Backend implementation
- Native Addon — Engine integration
- Terminal I/O Contract — Terminal interaction guarantees