Skip to content

gh-155976: Refresh COLORS and COLOR_PAIRS in curses set_term - #155994

Open
pranavchoudhary-tech wants to merge 5 commits into
python:mainfrom
pranavchoudhary-tech:fix-curses-set-term-155976
Open

pranavchoudhary-tech wants to merge 5 commits into
python:mainfrom
pranavchoudhary-tech:fix-curses-set-term-155976

Conversation

@pranavchoudhary-tech

Copy link
Copy Markdown
Contributor

gh-155976: Update update_lines_cols() in Modules/_cursesmodule.c to refresh COLORS and COLOR_PAIRS on module dictionaries when switching terminal screens via set_term() if start_color() is active. Also add unit test in Lib/test/test_curses.py.

@pranavchoudhary-tech

Copy link
Copy Markdown
Contributor Author

@alex Ready for review

@serhiy-storchaka
serhiy-storchaka self-requested a review September 15, 2026 07:19
@serhiy-storchaka

Copy link
Copy Markdown
Member

This does not fix the issue: after set_term(), LINES and COLS are still those of the other screen; only COLORS and COLOR_PAIRS are now correct. The ncurses set_term() updates the latter two globals, but not LINES and COLS, which are set only when a screen is created, so they have to be taken from the current stdscr.

The test passes without the change in Modules/_cursesmodule.c: both screens have the same default size, and the COLORS checks compare two equally stale values. Use screens of different sizes and compare with screen.stdscr.getmaxyx() and the known number of colors.

@serhiy-storchaka

Copy link
Copy Markdown
Member

This fixes it now: LINES, COLS, COLORS and COLOR_PAIRS follow the current screen after every set_term(), also for a screen with soft labels, and the test fails without the change in Modules/_cursesmodule.c.

Remaining:

  • set_term() is new in 3.16, so no NEWS entry is needed; please remove the file.
  • There is trailing whitespace on the two blank lines in the with block; the pre-commit check fails on it.
  • Move from test.support import os_helper to the imports at the top of the file.
  • newterm('xterm-256color', ...) should skip the test if the terminfo entry does not exist, as TermAttrsTests does.
  • The hasattr(curses, 'start_color') checks are not needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants