python / python/cpython

`set_term()` does not refresh `curses.LINES`, `COLS` or `COLORS`

オープン
#155,976 コメント 2 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

extension-modules topic-curses type-bug
主要言語
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

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

curses.set_term() と update_lines_cols() から始め、その後 Doc/library/curses.rst に記載されている LINES、COLS、COLORS、COLOR_PAIRS の動作を確認します。2 つの画面を使用して、提供されている pseudo-terminal reproducer を実行します。切り替え後にモジュールの値が現在の画面と一致し、サイズと色の上限も含まれていれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
python
領域
cli
issue の種類
バグ
難易度
3/5
見積もり時間
1〜2日
活発さ
停滞
明瞭さ
明確に書かれている
初心者へのやさしさ
35/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。