-
-
Notifications
You must be signed in to change notification settings - Fork 31.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
curses.addch('a', curses.color_pair(1)) ignores the color information #81919
Comments
curses.addch() ignores color information if I pass it a string of length one. Color works fine if I pass it a byte string or an int. Here's a reproducer: ### start of example ###
import curses
def main(stdscr):
curses.start_color()
curses.use_default_colors()
curses.init_pair(1, curses.COLOR_RED, -1)
curses.init_pair(2, curses.COLOR_GREEN, -1)
curses.curs_set(0)
stdscr.addch("a", curses.color_pair(1))
stdscr.addch("b", curses.color_pair(2) | curses.A_BOLD)
stdscr.addch(b"c", curses.color_pair(1))
stdscr.addch(b"d", curses.color_pair(2) | curses.A_BOLD)
stdscr.addch(ord("e"), curses.color_pair(1))
stdscr.addch(ord("f"), curses.color_pair(2) | curses.A_BOLD)
stdscr.refresh()
stdscr.getch()
curses.wrapper(main)
### end of example ### On Python 2.7 this prints 'abcdef' in alternating red and green. On Python 3.5 through 3.8 this prints 'ab' in white and the rest in red/green. Note that only color pair information is lost -- the bold attribute is correctly set on the 'b'. |
stdscr.addch(str, color_pair) is implemented with: setcchar(&wcval, wstr, attr, 0, NULL); whereas stdscr.addch(bytes, color_pair) is implemented with: rtn = waddch(self->win, cch | (attr_t) attr); The 4th argument of setcchar() is "short color_pair": Python always pass 0. It seems to be your bug. Attached PR 15071 fix this bug. Note: Python 3.5 and 3.6 don't accept bugfixes anymore, only security fixes. |
I'm able to reproduce the issue on Fedora 30: Python 3.7.4 with ncurses-libs-6.1-10.20180923.fc30.x86_64. vstinner@apu$ cat /etc/fedora-release |
On my Fedora 30 with libncursesw, A_COLOR = 0xff00. After my change, _curses uses:
If someone gets troubles with attr passed "directly" as the 3rd argument of setcchar(), we can try to pass (attr & ~A_COLOR) instead. On my Linux, it would mean: only pass the low 8 bits of attr. But since it "just" works on my Linux, I prefer to only make minimum changes to fix this issue on Linux. |
I fixed the bug in 3.7, 3.8 and master (future 3.9) branches. Thanks Marius Gedminas for the bug report. In the meanwhile, you have to pass bytes strings to addch() :-( |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: