Skip to content

fix(tput): numeric capabilities (colors/pairs/cols/lines) + ncurses-6.4 error contract (#1460) - #1461

Merged
caomengxuan666 merged 1 commit into
mainfrom
fix/tput-numeric-capabilities-1460
Oct 31, 2026
Merged

caomengxuan666 merged 1 commit into
mainfrom
fix/tput-numeric-capabilities-1460

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Closes #1460. Root cause: nvm.sh:99 runs tput -T "$TERM" colors on every source, so every nvm ls/alias under rubash/niubash printed 1–6 lines of tput: unknown capability 'colors' noise.

Implemented against the WSL GNU oracle (Ubuntu 24.04, ncurses 6.4), verified byte-for-byte on both stdout and stderr across the matrix {xterm, xterm-256color, screen, screen-256color, tmux-256color, linux, vt100, dumb} × {colors, pairs, cols, lines} plus setaf/setab/cup/string/error paths (script-file probe, no wsl -c quoting):

  • Numeric capabilities colors/pairs/cols/lines: value + newline, exit 0; an absent capability prints -1 and still exits 0. cols/lines use GetConsoleScreenBufferInfo when stdout is a real console, else the terminfo constants — matching ncurses' ioctl-then-terminfo fallback.
  • Parameterized caps (setaf/setab/cup): missing operand → raw terminfo template (rc 0); non-numeric operand → format with 0 and continue the argv loop; raw templates byte-equal to oracle.
  • Unknown capname: ncurses wording tput: unknown terminfo capability 'X', exit 4 (was rc 1, different wording).
  • No capname: usage on stderr, exit 2 (was rc 1 one-liner).

Tests: tput.* 28/28 green (8 new #1460 cases); two stale tests re-pinned to the oracle (tput lines on xterm now succeeds in GNU — numeric capability — so the #1166 stdin arm moved to an unknown capname).

nvm replay after rebuild: source nvm.sh; nvm alias; nvm ls under rubash is clean, exit 0.

#1460)

Root cause: nvm.sh:99 runs `tput -T "$TERM" colors` on every source; the
WinuxCmd tput had no numeric capability family, so every nvm ls/alias
printed 1-6 lines of `tput: unknown capability 'colors'` noise under both
rubash and niubash.

Implemented against the WSL GNU oracle (Ubuntu 24.04, ncurses 6.4),
byte-for-byte on both streams (tput -T {8 terms} x {colors,pairs,cols,
lines} + setaf/setab/cup/string/error matrix, script-file probe):

- Numeric capabilities colors/pairs/cols/lines: value + "\n", exit 0;
  an absent capability prints "-1" and still exits 0 (vt100 colors,
  linux cols/lines, dumb lines). cols/lines come from
  GetConsoleScreenBufferInfo when stdout is a real console, else the
  terminfo constants (80/24), matching ncurses' ioctl-then-terminfo
  fallback.
- Parameterized capabilities (setaf/setab/cup): missing operand
  entirely prints the raw terminfo template (rc 0); a non-numeric
  operand formats with 0 and the argv continues as the next capname.
  Raw templates carried byte-equal to the oracle.
- Unknown capname: ncurses wording `tput: unknown terminfo capability
  'X'` and exit 4 (was rc 1 with different wording).
- No capname: usage on stderr, exit 2 (was rc 1 one-liner).

Tests: 28/28 tput.* green (8 new cases for the #1460 family); two stale
tests updated to the oracle (`tput lines` on xterm succeeds in GNU since
lines is a numeric capability, so the #1166 stdin arm now uses an
unknown capname; empty-argv and unknown-capname expectations moved to
the attested rc 2 / rc 4).

nvm replay with the rebuilt binary: `source nvm.sh; nvm alias; nvm ls`
under rubash is now clean (zero tput noise), exit 0.

Fixes #1460.
@caomengxuan666
caomengxuan666 merged commit 7c49696 into main Oct 31, 2026
12 of 15 checks passed
@caomengxuan666
caomengxuan666 deleted the fix/tput-numeric-capabilities-1460 branch November 2, 2026 01:13
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] 未实现标准 capability colors:nvm.sh 每次 source 打印 unknown capability 噪声

1 participant