`set_term()` does not refresh `curses.LINES`, `COLS` or `COLORS`
还没有人认领这个 Issue。
- 主要语言
- Python
- 星标
- 77.2k
- 派生
- 35.9k
- PR 合并指标
- PR 指标待抓取
描述
Bug description:
curses.LINES, curses.COLS, curses.COLORS and curses.COLOR_PAIRS are copied into the module namespace when a terminal is initialized, and set_term() does not refresh them, so after a switch they describe a different terminal. curses.newwin(curses.LINES, curses.COLS) then sizes a window for the wrong screen, and a colour checked against curses.COLORS is rejected by init_pair(). screen.use() behaves the same way.
import curses, fcntl, os, struct, termios
def screen(kind, rows, cols):
slave = os.openpty()[1]
fcntl.ioctl(slave, termios.TIOCSWINSZ, struct.pack('HHHH', rows, cols, 0, 0))
return curses.newterm(kind, slave, slave)
small = screen('xterm', 18, 60) # 8 colours
curses.start_color()
big = screen('xterm-256color', 32, 120) # 256 colours
curses.start_color()
curses.set_term(small)
print('current screen', small.stdscr.getmaxyx(), curses.ncurses_version)
print('LINES, COLS ', (curses.LINES, curses.COLS))
print('COLORS ', curses.COLORS)
try:
curses.init_pair(1, curses.COLORS - 1, 0)
except ValueError as exc:
print('init_pair ', exc)
$ ./python repro.py
current screen (18, 60) curses.ncurses_version(major=6, minor=6, patch=20251231)
LINES, COLS (32, 120)
COLORS 256
init_pair Color number is greater than COLORS-1 (7).
Expected: (18, 60) and 8, the values of the screen that is current. Doc/library/curses.rst calls LINES "the height of the screen" and COLORS "the maximum number of colors the terminal can support", with nothing about them following one screen only.
set_term() does call the internal update_lines_cols(), but that helper re-reads the ncurses LINES/COLS globals, which set_term() leaves alone, and nothing copies COLORS/COLOR_PAIRS, whose C value did change.
CPython versions tested on:
CPython main branch
Operating systems tested on:
Linux
Linked PRs
- gh-155994
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从 curses.set_term() 和 update_lines_cols() 开始,然后查看 Doc/library/curses.rst 中对 LINES、COLS、COLORS 和 COLOR_PAIRS 行为的说明。使用两个屏幕运行提供的伪终端复现程序;完成标准是切换后模块值与当前屏幕匹配,包括尺寸和颜色限制。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- python
- 领域
- cli
- Issue 类型
- 缺陷
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 活跃度
- 停滞
- 描述清晰度
- 描述清楚
- 新手友好度
- 35/100