Skip to content

Commit 1ed98a6

Browse files
[3.14] gh-151623: Add missing curses docstrings and document intrflush() (GH-151632) (GH-151642)
(cherry picked from commit 12add38)
1 parent 1ba9952 commit 1ed98a6

3 files changed

Lines changed: 147 additions & 42 deletions

File tree

Doc/library/curses.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,13 @@ The module :mod:`!curses` defines the following functions:
333333
cause the interpreter to exit.
334334

335335

336+
.. function:: intrflush(flag)
337+
338+
If *flag* is ``True``, pressing an interrupt key (interrupt, break, or quit)
339+
will flush all output in the terminal driver queue. If *flag* is ``False``,
340+
no flushing is done.
341+
342+
336343
.. function:: is_term_resized(nlines, ncols)
337344

338345
Return ``True`` if :func:`resize_term` would modify the window structure,

Modules/_cursesmodule.c

Lines changed: 122 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2688,80 +2688,150 @@ static PyMethodDef PyCursesWindow_methods[] = {
26882688
_CURSES_WINDOW_BKGDSET_METHODDEF
26892689
_CURSES_WINDOW_BORDER_METHODDEF
26902690
_CURSES_WINDOW_BOX_METHODDEF
2691-
{"clear", PyCursesWindow_wclear, METH_NOARGS},
2692-
{"clearok", PyCursesWindow_clearok, METH_VARARGS},
2693-
{"clrtobot", PyCursesWindow_wclrtobot, METH_NOARGS},
2694-
{"clrtoeol", PyCursesWindow_wclrtoeol, METH_NOARGS},
2695-
{"cursyncup", PyCursesWindow_wcursyncup, METH_NOARGS},
2691+
{"clear", PyCursesWindow_wclear, METH_NOARGS,
2692+
"clear($self, /)\n--\n\n"
2693+
"Clear the window and repaint it completely on the next refresh()."},
2694+
{"clearok", PyCursesWindow_clearok, METH_VARARGS,
2695+
"clearok($self, flag, /)\n--\n\n"
2696+
"Clear the window on the next refresh() if flag is true."},
2697+
{"clrtobot", PyCursesWindow_wclrtobot, METH_NOARGS,
2698+
"clrtobot($self, /)\n--\n\n"
2699+
"Erase from the cursor to the end of the window."},
2700+
{"clrtoeol", PyCursesWindow_wclrtoeol, METH_NOARGS,
2701+
"clrtoeol($self, /)\n--\n\n"
2702+
"Erase from the cursor to the end of the line."},
2703+
{"cursyncup", PyCursesWindow_wcursyncup, METH_NOARGS,
2704+
"cursyncup($self, /)\n--\n\n"
2705+
"Update the cursor position of all ancestor windows to match."},
26962706
_CURSES_WINDOW_DELCH_METHODDEF
2697-
{"deleteln", PyCursesWindow_wdeleteln, METH_NOARGS},
2707+
{"deleteln", PyCursesWindow_wdeleteln, METH_NOARGS,
2708+
"deleteln($self, /)\n--\n\n"
2709+
"Delete the line under the cursor; move following lines up by one."},
26982710
_CURSES_WINDOW_DERWIN_METHODDEF
26992711
_CURSES_WINDOW_ECHOCHAR_METHODDEF
27002712
_CURSES_WINDOW_ENCLOSE_METHODDEF
2701-
{"erase", PyCursesWindow_werase, METH_NOARGS},
2702-
{"getbegyx", PyCursesWindow_getbegyx, METH_NOARGS},
2713+
{"erase", PyCursesWindow_werase, METH_NOARGS,
2714+
"erase($self, /)\n--\n\n"
2715+
"Clear the window."},
2716+
{"getbegyx", PyCursesWindow_getbegyx, METH_NOARGS,
2717+
"getbegyx($self, /)\n--\n\n"
2718+
"Return a tuple (y, x) of the upper-left corner coordinates."},
27032719
_CURSES_WINDOW_GETBKGD_METHODDEF
27042720
_CURSES_WINDOW_GETCH_METHODDEF
27052721
_CURSES_WINDOW_GETKEY_METHODDEF
27062722
_CURSES_WINDOW_GET_WCH_METHODDEF
2707-
{"getmaxyx", PyCursesWindow_getmaxyx, METH_NOARGS},
2708-
{"getparyx", PyCursesWindow_getparyx, METH_NOARGS},
2723+
{"getmaxyx", PyCursesWindow_getmaxyx, METH_NOARGS,
2724+
"getmaxyx($self, /)\n--\n\n"
2725+
"Return a tuple (y, x) of the window height and width."},
2726+
{"getparyx", PyCursesWindow_getparyx, METH_NOARGS,
2727+
"getparyx($self, /)\n--\n\n"
2728+
"Return (y, x) relative to the parent window, or (-1, -1) if none."},
27092729
{
27102730
"getstr", PyCursesWindow_getstr, METH_VARARGS,
27112731
_curses_window_getstr__doc__
27122732
},
2713-
{"getyx", PyCursesWindow_getyx, METH_NOARGS},
2733+
{"getyx", PyCursesWindow_getyx, METH_NOARGS,
2734+
"getyx($self, /)\n--\n\n"
2735+
"Return a tuple (y, x) of the current cursor position."},
27142736
_CURSES_WINDOW_HLINE_METHODDEF
2715-
{"idcok", PyCursesWindow_idcok, METH_VARARGS},
2716-
{"idlok", PyCursesWindow_idlok, METH_VARARGS},
2737+
{"idcok", PyCursesWindow_idcok, METH_VARARGS,
2738+
"idcok($self, flag, /)\n--\n\n"
2739+
"Enable or disable the hardware insert/delete character feature."},
2740+
{"idlok", PyCursesWindow_idlok, METH_VARARGS,
2741+
"idlok($self, flag, /)\n--\n\n"
2742+
"Enable or disable the hardware insert/delete line feature."},
27172743
#ifdef HAVE_CURSES_IMMEDOK
2718-
{"immedok", PyCursesWindow_immedok, METH_VARARGS},
2744+
{"immedok", PyCursesWindow_immedok, METH_VARARGS,
2745+
"immedok($self, flag, /)\n--\n\n"
2746+
"If flag is true, refresh the window on every change to it."},
27192747
#endif
27202748
_CURSES_WINDOW_INCH_METHODDEF
27212749
_CURSES_WINDOW_INSCH_METHODDEF
2722-
{"insdelln", PyCursesWindow_winsdelln, METH_VARARGS},
2723-
{"insertln", PyCursesWindow_winsertln, METH_NOARGS},
2750+
{"insdelln", PyCursesWindow_winsdelln, METH_VARARGS,
2751+
"insdelln($self, nlines, /)\n--\n\n"
2752+
"Insert (nlines > 0) or delete (nlines < 0) lines above the cursor."},
2753+
{"insertln", PyCursesWindow_winsertln, METH_NOARGS,
2754+
"insertln($self, /)\n--\n\n"
2755+
"Insert a blank line under the cursor; move following lines down."},
27242756
_CURSES_WINDOW_INSNSTR_METHODDEF
27252757
_CURSES_WINDOW_INSSTR_METHODDEF
27262758
{
27272759
"instr", PyCursesWindow_instr, METH_VARARGS,
27282760
_curses_window_instr__doc__
27292761
},
27302762
_CURSES_WINDOW_IS_LINETOUCHED_METHODDEF
2731-
{"is_wintouched", PyCursesWindow_is_wintouched, METH_NOARGS},
2732-
{"keypad", PyCursesWindow_keypad, METH_VARARGS},
2733-
{"leaveok", PyCursesWindow_leaveok, METH_VARARGS},
2734-
{"move", PyCursesWindow_wmove, METH_VARARGS},
2735-
{"mvderwin", PyCursesWindow_mvderwin, METH_VARARGS},
2736-
{"mvwin", PyCursesWindow_mvwin, METH_VARARGS},
2737-
{"nodelay", PyCursesWindow_nodelay, METH_VARARGS},
2738-
{"notimeout", PyCursesWindow_notimeout, METH_VARARGS},
2763+
{"is_wintouched", PyCursesWindow_is_wintouched, METH_NOARGS,
2764+
"is_wintouched($self, /)\n--\n\n"
2765+
"Return True if the window changed since the last refresh()."},
2766+
{"keypad", PyCursesWindow_keypad, METH_VARARGS,
2767+
"keypad($self, flag, /)\n--\n\n"
2768+
"Interpret escape sequences for special keys if flag is true."},
2769+
{"leaveok", PyCursesWindow_leaveok, METH_VARARGS,
2770+
"leaveok($self, flag, /)\n--\n\n"
2771+
"If flag is true, leave the cursor where the update leaves it."},
2772+
{"move", PyCursesWindow_wmove, METH_VARARGS,
2773+
"move($self, new_y, new_x, /)\n--\n\n"
2774+
"Move the cursor to (new_y, new_x)."},
2775+
{"mvderwin", PyCursesWindow_mvderwin, METH_VARARGS,
2776+
"mvderwin($self, y, x, /)\n--\n\n"
2777+
"Move the window inside its parent window."},
2778+
{"mvwin", PyCursesWindow_mvwin, METH_VARARGS,
2779+
"mvwin($self, new_y, new_x, /)\n--\n\n"
2780+
"Move the window so its upper-left corner is at (new_y, new_x)."},
2781+
{"nodelay", PyCursesWindow_nodelay, METH_VARARGS,
2782+
"nodelay($self, flag, /)\n--\n\n"
2783+
"If flag is true, getch() becomes non-blocking."},
2784+
{"notimeout", PyCursesWindow_notimeout, METH_VARARGS,
2785+
"notimeout($self, flag, /)\n--\n\n"
2786+
"If flag is true, do not time out escape sequences."},
27392787
_CURSES_WINDOW_NOUTREFRESH_METHODDEF
27402788
_CURSES_WINDOW_OVERLAY_METHODDEF
27412789
_CURSES_WINDOW_OVERWRITE_METHODDEF
27422790
_CURSES_WINDOW_PUTWIN_METHODDEF
27432791
_CURSES_WINDOW_REDRAWLN_METHODDEF
2744-
{"redrawwin", PyCursesWindow_redrawwin, METH_NOARGS},
2792+
{"redrawwin", PyCursesWindow_redrawwin, METH_NOARGS,
2793+
"redrawwin($self, /)\n--\n\n"
2794+
"Mark the entire window for redraw on the next refresh()."},
27452795
_CURSES_WINDOW_REFRESH_METHODDEF
27462796
#ifndef STRICT_SYSV_CURSES
2747-
{"resize", PyCursesWindow_wresize, METH_VARARGS},
2797+
{"resize", PyCursesWindow_wresize, METH_VARARGS,
2798+
"resize($self, nlines, ncols, /)\n--\n\n"
2799+
"Resize the window to nlines rows and ncols columns."},
27482800
#endif
27492801
_CURSES_WINDOW_SCROLL_METHODDEF
2750-
{"scrollok", PyCursesWindow_scrollok, METH_VARARGS},
2802+
{"scrollok", PyCursesWindow_scrollok, METH_VARARGS,
2803+
"scrollok($self, flag, /)\n--\n\n"
2804+
"Control whether the window scrolls when the cursor moves off it."},
27512805
_CURSES_WINDOW_SETSCRREG_METHODDEF
2752-
{"standend", PyCursesWindow_wstandend, METH_NOARGS},
2753-
{"standout", PyCursesWindow_wstandout, METH_NOARGS},
2806+
{"standend", PyCursesWindow_wstandend, METH_NOARGS,
2807+
"standend($self, /)\n--\n\n"
2808+
"Turn off the standout attribute."},
2809+
{"standout", PyCursesWindow_wstandout, METH_NOARGS,
2810+
"standout($self, /)\n--\n\n"
2811+
"Turn on the A_STANDOUT attribute."},
27542812
{"subpad", _curses_window_subwin, METH_VARARGS, _curses_window_subwin__doc__},
27552813
_CURSES_WINDOW_SUBWIN_METHODDEF
2756-
{"syncdown", PyCursesWindow_wsyncdown, METH_NOARGS},
2814+
{"syncdown", PyCursesWindow_wsyncdown, METH_NOARGS,
2815+
"syncdown($self, /)\n--\n\n"
2816+
"Touch each location changed in any ancestor of the window."},
27572817
#ifdef HAVE_CURSES_SYNCOK
2758-
{"syncok", PyCursesWindow_syncok, METH_VARARGS},
2818+
{"syncok", PyCursesWindow_syncok, METH_VARARGS,
2819+
"syncok($self, flag, /)\n--\n\n"
2820+
"If flag is true, call syncup() on every change to the window."},
27592821
#endif
2760-
{"syncup", PyCursesWindow_wsyncup, METH_NOARGS},
2761-
{"timeout", PyCursesWindow_wtimeout, METH_VARARGS},
2822+
{"syncup", PyCursesWindow_wsyncup, METH_NOARGS,
2823+
"syncup($self, /)\n--\n\n"
2824+
"Touch locations in ancestors that changed in this window."},
2825+
{"timeout", PyCursesWindow_wtimeout, METH_VARARGS,
2826+
"timeout($self, delay, /)\n--\n\n"
2827+
"Set blocking or non-blocking read behavior for the window."},
27622828
_CURSES_WINDOW_TOUCHLINE_METHODDEF
2763-
{"touchwin", PyCursesWindow_touchwin, METH_NOARGS},
2764-
{"untouchwin", PyCursesWindow_untouchwin, METH_NOARGS},
2829+
{"touchwin", PyCursesWindow_touchwin, METH_NOARGS,
2830+
"touchwin($self, /)\n--\n\n"
2831+
"Mark the whole window as changed."},
2832+
{"untouchwin", PyCursesWindow_untouchwin, METH_NOARGS,
2833+
"untouchwin($self, /)\n--\n\n"
2834+
"Mark all lines in the window as unchanged since last refresh()."},
27652835
_CURSES_WINDOW_VLINE_METHODDEF
27662836
{NULL, NULL} /* sentinel */
27672837
};
@@ -2849,11 +2919,17 @@ static PyType_Spec PyCursesWindow_Type_spec = {
28492919
/*[clinic input]
28502920
_curses.filter
28512921
2922+
Restrict screen updates to the current line.
2923+
2924+
Must be called before initscr(). Afterwards curses confines the cursor
2925+
and screen updates to a single line, which is useful for enabling
2926+
character-at-a-time line editing without touching the rest of the
2927+
screen.
28522928
[clinic start generated code]*/
28532929

28542930
static PyObject *
28552931
_curses_filter_impl(PyObject *module)
2856-
/*[clinic end generated code: output=fb5b8a3642eb70b5 input=668c75a6992d3624]*/
2932+
/*[clinic end generated code: output=fb5b8a3642eb70b5 input=e3c64d6ab2106132]*/
28572933
{
28582934
/* not checking for PyCursesInitialised here since filter() must
28592935
be called before initscr() */
@@ -3720,11 +3796,16 @@ _curses.intrflush
37203796
flag: bool
37213797
/
37223798
3799+
Control flushing of the output buffer when an interrupt key is pressed.
3800+
3801+
If flag is true, pressing an interrupt key (interrupt, break, or quit)
3802+
flushes all output in the terminal driver queue. If flag is false, no
3803+
flushing is done.
37233804
[clinic start generated code]*/
37243805

37253806
static PyObject *
37263807
_curses_intrflush_impl(PyObject *module, int flag)
3727-
/*[clinic end generated code: output=c1986df35e999a0f input=c65fe2ef973fe40a]*/
3808+
/*[clinic end generated code: output=c1986df35e999a0f input=66588c2bccc7e8fa]*/
37283809
{
37293810
PyCursesStatefulInitialised(module);
37303811

@@ -4236,11 +4317,14 @@ update_lines_cols(PyObject *private_module)
42364317
/*[clinic input]
42374318
_curses.update_lines_cols
42384319
4320+
Update the LINES and COLS module variables.
4321+
4322+
This is useful for detecting manual screen resize.
42394323
[clinic start generated code]*/
42404324

42414325
static PyObject *
42424326
_curses_update_lines_cols_impl(PyObject *module)
4243-
/*[clinic end generated code: output=423f2b1e63ed0f75 input=5f065ab7a28a5d90]*/
4327+
/*[clinic end generated code: output=423f2b1e63ed0f75 input=1d8ea7c356b61a8b]*/
42444328
{
42454329
if (!update_lines_cols(module)) {
42464330
return NULL;

Modules/clinic/_cursesmodule.c.h

Lines changed: 18 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)