Skip to content

gh-83395: Add curses.window.in_wch#17825

Closed
asottile wants to merge 1 commit into
python:mainfrom
asottile:bpo_39214
Closed

gh-83395: Add curses.window.in_wch#17825
asottile wants to merge 1 commit into
python:mainfrom
asottile:bpo_39214

Conversation

@asottile

@asottile asottile commented Jan 4, 2020

Copy link
Copy Markdown
Contributor

@asottile asottile changed the title bpo-39214: Add curses.windows.in_wch bpo-39214: Add curses.window.in_wch Jan 4, 2020
@asottile asottile force-pushed the bpo_39214 branch 2 times, most recently from 4a656ab to 1368b75 Compare January 8, 2020 03:13
@asottile asottile force-pushed the bpo_39214 branch 2 times, most recently from 90b1918 to 131a2f9 Compare November 2, 2021 23:56
@asottile asottile mannequin mentioned this pull request Apr 10, 2022
@krmaxson

Copy link
Copy Markdown

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!

@asottile

Copy link
Copy Markdown
Contributor Author

I've rebased this against 3.12 (I originally targeted 3.9!)

@asottile

Copy link
Copy Markdown
Contributor Author

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!

fwiw, I've seen even outside reviews move things forward -- if you want to review the code

@GiorgosXou

Copy link
Copy Markdown

I've been staring at this pull request for two years

@krmaxson me too, same thing, although at some point i got bored and I eventually diched the curses module and turned to the uni-curses module (which I recently started maintaning and made this with it)

@erlend-aasland erlend-aasland changed the title bpo-39214: Add curses.window.in_wch gh-83395: Add curses.window.in_wch Jun 27, 2023
@asottile asottile force-pushed the bpo_39214 branch 2 times, most recently from 3374b82 to f16f2b8 Compare July 2, 2023 01:09
@asottile

asottile commented Jul 2, 2023

Copy link
Copy Markdown
Contributor Author

aaaand rebased on 3.13

@asottile

Copy link
Copy Markdown
Contributor Author

sure why not, let's do our yearly rebase -- now onto 3.14

@picnixz picnixz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some comments for this (I'm currently refactoring the curses module). By the way, is the term "color pair" documented on the page?

Comment thread Doc/library/curses.rst
Comment on lines +1027 to +1028
Return the wide character at the given position in the window. The return
value is a 3-tuple ``(character, attributes, color_pair)``.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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)``.

Comment thread Doc/library/curses.rst
Comment on lines +1020 to +1023
.. note::

``inch`` only works for ASCII characters. Use :meth:`in_wch` instead
for unicode support.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.. 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.

Comment thread Doc/library/curses.rst
Comment on lines +1024 to +1025

.. method:: window.in_wch([x, y])

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.. 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).

Comment thread Doc/library/curses.rst
Comment on lines +1024 to +1025

.. method:: window.in_wch([x, y])

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.. method:: window.in_wch([x, y])
.. method:: window.in_wch([y, x])

Comment thread Lib/test/test_curses.py
Comment on lines +1113 to +1114
if not hasattr(stdscr, 'in_wch'):
raise unittest.SkipTest('requires curses.window.in_wch')

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.

Comment thread Modules/_cursesmodule.c
Comment on lines +1744 to +1748
y: int
Starting Y-coordinate.
x: int
Starting X-coordinate.
]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.

Comment thread Modules/_cursesmodule.c
]
/

Retrieve the wide character at the gven position in the window.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Retrieve the wide character at the gven position in the window.
Retrieve the Unicode character at the given position in the window.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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...)

Comment thread Modules/_cursesmodule.c
Comment on lines +1779 to +1781
if (PyCursesCheckERR(ret, "getcchar") == NULL) {
return NULL;
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (PyCursesCheckERR(ret, "getcchar") == NULL) {
return NULL;
}
if (ret == ERR) {
PyErr_SetString(PyCursesError, "getcchar() returned ERR");
return NULL;
}

Comment thread Modules/_cursesmodule.c
Comment on lines +1769 to +1776
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;
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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;
}
}

@asottile

Copy link
Copy Markdown
Contributor Author

nevermind. seriously not worth my time at this point

@asottile asottile closed this Sep 28, 2024

@picnixz picnixz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are also a bunch of tests that fail. I can't check them now but I'll have a look tomorrow.

Comment thread Modules/_cursesmodule.c
int y, int x)
/*[clinic end generated code: output=846ca8a82f2ecab4 input=5c20d96b592b0e0b]*/
{
int ret;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah maybe I should have said it in the other review, but I think we use rtn in general and not ret.

Comment thread Modules/_cursesmodule.c
]
/

Retrieve the wide character at the gven position in the window.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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...)

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.

7 participants