Skip to content

WIP: fix(stty): size/speed output-style queries, -a promotion, rows/cols validation (#1430) - #1431

Merged
caomengxuan666 merged 1 commit into
mainfrom
fix/1430-stty
Oct 28, 2026
Merged

caomengxuan666 merged 1 commit into
mainfrom
fix/1430-stty

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Fixes #1430

三症状根因(均为 src/commands/stty.cpp)

  1. stty size 空输出 rc=0:size 被放进 is_known_noarg_setting 当 apply-mode 无参 setting,apply_setting 走到兜底分支返回 true——整条查询路径不存在,静默成功。speed 同形(GNU 里同为输出型请求)。另外 -a 输出里的 rows 50; columns 120 是硬编码假几何。
  2. stty -a 被拒 "invalid argument '-a'":框架解析层对已注册的 -a 本可正确解析,但经转发层以 positional 形态到达时,build_config 把它当 setting 送进 validate_settings 拒收。GNU getopt 永不把已注册选项当操作数交付——到达 positional 的输出型旗标仍应按其本义生效。
  3. stty rows 40 cols 120 值形式被拒:值形式在验证层须完整对齐 GNU 文法;同时整数型值设置(rows/cols/columns/line/min/time/ispeed/ospeed)此前不校验值本身,stty rows abc 会被静默接受。

修法

  • size/speed 从 setting 名单摘除,新增 extract_query_settings 把两者从设置列表中按输出型请求提取(值设置的参数是数据、永不匹配,如 stty intr size 的 CHAR);与 mode 设置或第二个输出型并用时沿用既有两条 GNU 式互斥/冲突报错。
  • size 查询走目标句柄(stdin 或 -F 设备句柄,从不查 stdout,故 stty size > file 成立)上的 GetConsoleScreenBufferInfo 可见窗口几何,打印 " ";取不到几何时带 Win32 错误文本非零退出——绝不空输出 rc=0。-a 的 rows/columns 同源改真值。
  • speed 打印 -a 列表所称的名义值 38400(控制台无波特率)。
  • build_config 提升以 positional 形态到达的 -a/--all/-g/--save 为旗标(与 GNU 的选项置换语义一致)。
  • validate_settings 对整数型值设置校验值为十进制整数,否则按既有 "invalid argument ''" 形状报错。

测试与验证分层

  • 新增单元钉 6 条(tests/unit/stty):size 需终端、size 是输出型(与 sane 并用报错)、size 与 -a 互斥、speed 是输出型、rows/cols 值形式过验证到达终端检查(非 "invalid argument")、rows 非整数值被拒。本机 Linux 无 MSVC,构建与 ctest 以本 PR 的 Windows CI 为门。
  • 待真机烟测格(CI 覆盖不到,不冒充已验):真 ConPTY(120x30)下 stty size > file 文件内容应为 "30 120";stty -a 输出 rows/columns 与窗口实际几何一致;经 niubash 宿主调用 stty -a 不再报 invalid argument;stty rows 40 cols 120 rc=0(Windows 侧语义为校验后接受,几何由宿主拥有,不承诺改窗——与帮助中既有口径一致)。
  • rows/cols 的"设置生效"在 ConPTY 下无对应面(几何归宿主),本 PR 保持仓内既定口径:验证后接受、不改窗;期望帖中"设置生效 rc=0"按此解读,几何查询面以 size 为准。

I18N 同步(AGENTS.md 强制)

帮助文本变更(新增 size 行、speed 去掉"(accepted only)"、结尾注记补 size/speed):英文目录已用 scripts/i18n_batch.py extract 重新生成核对;zh-CN 目录在 winuxcmd-i18n 仓同步 command.stty.description 并 bump VERSION 0.6.21 → 0.6.22(单独 PR)。i18n_batch.py validate 报告的其余 key 漂移(cmp/hexdump/join/ls/patch/legacy.* 等)为两仓既存增量漂移,与 stty 无关,未在本批处理;stty 键集两边一致。

…1430)

`stty size` was listed as a known no-argument setting, so the apply path
accepted it silently: on a real console it printed nothing and returned
0, where GNU prints "<rows> <cols>". `stty speed` had the same shape.
Both are output-style requests in GNU stty: extract them from the
settings list (a value setting's argument is data, never a request),
reject combinations with mode settings or a second output style, and
answer them from the target device handle:

- size prints the visible geometry from GetConsoleScreenBufferInfo on
  the stdin/-F handle (never stdout, so `stty size > file` works), and
  fails with an error when the geometry cannot be obtained - never an
  empty success.
- speed prints the nominal 38400 the -a listing claims.
- -a now prints the real rows/columns instead of hardcoded 50/120.

Also for #1430: promote -a/--all/-g/--save tokens that arrive in the
positional list through a forwarding layer (GNU getopt never delivers a
registered option as an operand; `stty -a` was rejected with
"invalid argument '-a'") and validate that integer value settings
(rows/cols/columns/line/min/time/ispeed/ospeed) actually receive an
integer, so `stty rows abc` is diagnosed instead of silently accepted.

Help text updated for size/speed; zh-CN catalog synced in
winuxcmd-i18n (command.stty.description) with a VERSION bump.
@caomengxuan666
caomengxuan666 marked this pull request as ready for review October 28, 2026 16:28
@caomengxuan666
caomengxuan666 merged commit 58613c2 into main Oct 28, 2026
8 checks passed
@caomengxuan666
caomengxuan666 deleted the fix/1430-stty branch October 30, 2026 01:42
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.

[bug] stty size 真控制台输出空且 rc=0;-a/rows/cols 值形式被拒(invalid argument)

1 participant