gh-83395: Add curses.window.in_wch#17825
Conversation
4a656ab to
1368b75
Compare
90b1918 to
131a2f9
Compare
|
Providing this wide character method in the Python binding would let me ditch a soup of custom code. It is aggravating to have to duplicate the curses backing store to print non-ASCII! I've been staring at this pull request for two years -- I really hope it eventually gets merged. Thanks for tackling this! |
|
I've rebased this against 3.12 (I originally targeted 3.9!) |
fwiw, I've seen even outside reviews move things forward -- if you want to review the code |
@krmaxson me too, same thing, although at some point i got bored and I eventually diched the curses module and turned to the |
3374b82 to
f16f2b8
Compare
|
aaaand rebased on 3.13 |
|
sure why not, let's do our yearly rebase -- now onto 3.14 |
picnixz
left a comment
There was a problem hiding this comment.
Some comments for this (I'm currently refactoring the curses module). By the way, is the term "color pair" documented on the page?
| Return the wide character at the given position in the window. The return | ||
| value is a 3-tuple ``(character, attributes, color_pair)``. |
There was a problem hiding this comment.
| Return the wide character at the given position in the window. The return | |
| value is a 3-tuple ``(character, attributes, color_pair)``. | |
| Return the wide character at the given position in the window as | |
| a triplet ``(character, attributes, color_pair)``. |
| .. note:: | ||
|
|
||
| ``inch`` only works for ASCII characters. Use :meth:`in_wch` instead | ||
| for unicode support. |
There was a problem hiding this comment.
| .. note:: | |
| ``inch`` only works for ASCII characters. Use :meth:`in_wch` instead | |
| for unicode support. | |
| .. note:: | |
| This method only works for ASCII characters. Use :meth:`in_wch` | |
| instead to retrieve the Unicode character at a given position. |
|
|
||
| .. method:: window.in_wch([x, y]) |
There was a problem hiding this comment.
| .. method:: window.in_wch([x, y]) | |
| .. method:: window.in_wch([x, y]) |
We separate methods by 2 blank lines (just check that my suggestion is correct before committing it).
|
|
||
| .. method:: window.in_wch([x, y]) |
There was a problem hiding this comment.
| .. method:: window.in_wch([x, y]) | |
| .. method:: window.in_wch([y, x]) |
| if not hasattr(stdscr, 'in_wch'): | ||
| raise unittest.SkipTest('requires curses.window.in_wch') |
There was a problem hiding this comment.
Do you need this kind of check or can you use @requires_curses_window_meth('in_wch')?
| @@ -0,0 +1 @@ | |||
| Add :func:`curses.window.in_wch` function - by Anthony Sottile. | |||
There was a problem hiding this comment.
| Add :func:`curses.window.in_wch` function - by Anthony Sottile. | |
| Add :func:`curses.window.in_wch` function to get the Unicode character | |
| at a given position. Patch by Anthony Sottile. |
| y: int | ||
| Starting Y-coordinate. | ||
| x: int | ||
| Starting X-coordinate. | ||
| ] |
There was a problem hiding this comment.
| y: int | |
| Starting Y-coordinate. | |
| x: int | |
| Starting X-coordinate. | |
| ] | |
| y: int | |
| Y-coordinate. | |
| x: int | |
| X-coordinate. | |
| ] |
Let's use the same wording as for inch.
| ] | ||
| / | ||
|
|
||
| Retrieve the wide character at the gven position in the window. |
There was a problem hiding this comment.
| Retrieve the wide character at the gven position in the window. | |
| Retrieve the Unicode character at the given position in the window. |
There was a problem hiding this comment.
Ah, wait, should we say wide character or Unicode character here (it's a wchar_t but we use it to indicate "Unicode" range so...)
| if (PyCursesCheckERR(ret, "getcchar") == NULL) { | ||
| return NULL; | ||
| } |
There was a problem hiding this comment.
| if (PyCursesCheckERR(ret, "getcchar") == NULL) { | |
| return NULL; | |
| } | |
| if (ret == ERR) { | |
| PyErr_SetString(PyCursesError, "getcchar() returned ERR"); | |
| return NULL; | |
| } |
| if (group_right_1) { | ||
| ret = mvwin_wch(self->win, y, x, &wcval); | ||
| } else { | ||
| ret = win_wch(self->win, &wcval); | ||
| } | ||
| if (PyCursesCheckERR(ret, "in_wch") == NULL) { | ||
| return NULL; | ||
| } |
There was a problem hiding this comment.
| if (group_right_1) { | |
| ret = mvwin_wch(self->win, y, x, &wcval); | |
| } else { | |
| ret = win_wch(self->win, &wcval); | |
| } | |
| if (PyCursesCheckERR(ret, "in_wch") == NULL) { | |
| return NULL; | |
| } | |
| if (group_right_1) { | |
| ret = mvwin_wch(self->win, y, x, &wcval); | |
| if (ret == ERR) { | |
| PyErr_SetString(PyCursesError, "mvwin_wch() returned ERR"); | |
| return NULL; | |
| } | |
| } | |
| else { | |
| ret = win_wch(self->win, &wcval); | |
| if (ret == ERR) { | |
| PyErr_SetString(PyCursesError, "win_wch() returned ERR"); | |
| return NULL; | |
| } | |
| } |
|
nevermind. seriously not worth my time at this point |
picnixz
left a comment
There was a problem hiding this comment.
There are also a bunch of tests that fail. I can't check them now but I'll have a look tomorrow.
| int y, int x) | ||
| /*[clinic end generated code: output=846ca8a82f2ecab4 input=5c20d96b592b0e0b]*/ | ||
| { | ||
| int ret; |
There was a problem hiding this comment.
Ah maybe I should have said it in the other review, but I think we use rtn in general and not ret.
| ] | ||
| / | ||
|
|
||
| Retrieve the wide character at the gven position in the window. |
There was a problem hiding this comment.
Ah, wait, should we say wide character or Unicode character here (it's a wchar_t but we use it to indicate "Unicode" range so...)
https://bugs.python.org/issue39214