Skip to content

fix(tput): TERM-aware capability table, setaf/setab/cup, raw output path (#1258) - #1269

Merged
caomengxuan666 merged 1 commit into
mainfrom
fix/1258
Oct 20, 2026
Merged

caomengxuan666 merged 1 commit into
mainfrom
fix/1258

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Summary

tput now resolves capabilities from the TERM-named terminfo entry instead of a hardcoded TERM-agnostic table (WinuxCmd side of the rubash#884 inline whitelist arm; same oracle data).

  • setaf/setab implemented — plus civis/cnorm/el/ed/smcup/rmcup/cup with operands; the no-param cap strings are the oracle-verified per-TERM table (xterm/xterm-256color/screen/screen-256color/tmux-256color/linux/vt100). Numeric operands parse with strtol(arg, NULL, 0) like ncurses, so octal/hex spellings stay byte-equal (setaf 010 → \e[38m, cup 010 010 → \e[9;9H).
  • TERM honored — xterm-256color/xterm answer their respective families; dumb reports every capability absent (silent rc 1, ncurses contract); unset/empty TERM prints tput: No value for $TERM and no -T specified and exits 2 (GNU usage error); -T overrides $TERM. An unlisted TERM keeps the historical xterm-family answers.
  • ~17 ms per-call cost — root-caused to the i18n path: the first safePrint pays the lazy catalog() read+JSON-parse once per process when WINUX_LANG selects an installed catalog (measured on this host: zh-CN + zh-CN catalog → +20 ms for every output-emitting command; true never pays because it never prints). Capability bytes are terminal protocol data, not natural language, so they now go through a raw WriteFile that bypasses translation entirely. Post-fix in-process time for tput bold is ~0.4 ms, identical to true; the residual per-invocation wall time (~17-19 ms on this host) is process spawn + CRT/registry init shared by every command.
  • GNU consumes argv as a capname stream (tput cup 5 10 clear emits both), and absent capabilities stay silent rc 1.

Oracle verification

  • Replay of the rubash#884 differential matrix artifact (matrix_gnu.txt, WSL ncurses 6.4) against this binary: 3208 rows, 0 byte mismatches — includes the strtol base-0 operand family the CR found divergent in the sibling arm (here the same libc call answers them directly, no narrowing needed since there is no fallback binary).

Test plan

  • matrix_gnu.txt replay: 3208/3208 byte-identical
  • Manual smoke: TERM=xterm/dumb/unset/-T, setaf/setab/cup/absent-rc1
  • tput unit tests (updated cases pin TERM explicitly; CI will exercise them)

i18n companion: unixwin/winuxcmd-i18n@main (catalogs/zh-CN + VERSION 0.6.19) already pushed.

Fixes #1258

Generated with Devin

…ath (#1258)

- Answer capabilities from the TERM-named terminfo entry instead of
  ignoring TERM: verified byte-for-byte table for xterm/xterm-256color/
  screen/screen-256color/tmux-256color/linux/vt100 (same oracle data as
  the rubash#884 inline arm), dumb answers the all-absent surface, and
  an unlisted TERM keeps the historical xterm-family fallback.
- setaf/setab/cup implemented; numeric operands go through
  strtol(base 0) like ncurses so octal/hex spellings stay byte-equal
  (setaf 010 -> \e[38m, cup 010 010 -> \e[9;9H). Missing/empty TERM
  reports GNU's "tput: No value for $TERM and no -T specified" rc 2 and
  -T is honored.
- Capability bytes are terminal protocol data: write them with a raw
  WriteFile that bypasses the i18n translate path. The first safePrint
  used to pay the lazy catalog read+parse once per process, which is
  the ~17 ms per-invocation overhead reported on catalog-installed
  hosts (measured: tput bold zh-CN+catalog ~0.4ms in-process after the
  change vs ~18ms before, spawn floor unchanged).
- GNU consumes argv as a capname stream, so `tput cup 5 10 clear`
  emits both strings; absent capabilities stay silent rc 1.

Fixes #1258

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@caomengxuan666
caomengxuan666 merged commit 784cca9 into main Oct 20, 2026
8 checks passed
@caomengxuan666
caomengxuan666 deleted the fix/1258 branch October 21, 2026 08:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

tput 未实现 setaf/setab 颜色能力且忽略 TERM 环境变量,单次调用 ~17ms 开销——#800 修复代理跨仓发现

1 participant