Repository navigation
fix(motd): detect terminal width outside command substitution - #110
Merged
Merged
Conversation
motd_columns ran inside $(...), where stdout is a pipe, so [[ -t 1 ]] was always false and a real 32-column terminal fell back to 40 columns. Capture the stdout TTY state before the substitution and pass it to the function, keeping explicit COLUMNS priority and the PAM 40-column fallback. Cover the real PTY path with a regression test whose payload stderr is redirected inside the script child, so a fd 2 based implementation cannot pass.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
MOTD 欢迎页在真实 32 列终端里仍按 40 列渲染,最宽行 38 列并折行。原因是
COLS=$(motd_columns)在命令替换内执行,motd_columns中的[[ -t 1 ]]看到的是捕获管道而不是终端,tput cols从未运行。本次在命令替换外先记录 stdout 是否为终端,再交给
motd_columns使用;tools/setup-motd.sh与modules/system-customize.sh的相同 heredoc 欢迎 payload 同步修改,哈希一致。Scope
tools/setup-motd.sh:payload 内新增motd_stdout_is_tty,motd_columns改用它判断是否调用tput;更新 payload 哈希。modules/system-customize.sh:同一 payload 的等价修改与哈希更新。tests/test-motd.sh:更新 payload 哈希;新增真实 32 列 PTY 回归,无COLUMNS,验证宽度不超过 32 且欢迎行、CPU 行保留。payload 自身 stderr 在script -c子命令内单独重定向,wrapper stderr 另用文件,两处分别断言,改用 fd 2 的错误实现会回退 40 列并失败。保持不变:显式
COLUMNS优先、PAM/非 TTY 的 40 列兜底、不把 stderr 终端状态当作 stdout。Validation
git diff --check:通过。bash -n:tools/setup-motd.sh、modules/system-customize.sh、tests/test-motd.sh均通过。1e1a2987751cbaa3fca0697e20f5bb9c16dad13fb28a61bf1540807fc67ac2b8。COLUMNS的 32 列 PTY 输出最宽 38 列;修复后为 32 列,欢迎行与 CPU 行均在。Risks
tput,显式COLUMNS与 40 列兜底仍优先/保留。script提供的伪终端,不等同目标机登录链。Rollback
还原本 PR 提交即可;payload 与哈希一并回到旧值,无数据或配置迁移。