Skip to content

Commit b32cb97

Browse files
asottileserhiy-storchaka
authored andcommitted
bpo-38312: Add curses.{get,set}_escdelay and curses.{get,set}_tabsize. (GH-16938)
1 parent b15100f commit b32cb97

File tree

6 files changed

+247
-1
lines changed

6 files changed

+247
-1
lines changed

Doc/library/curses.rst

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,32 @@ The module :mod:`curses` defines the following functions:
511511
Save the current state of the terminal modes in a buffer, usable by
512512
:func:`resetty`.
513513

514+
.. function:: get_escdelay()
515+
516+
Retrieves the value set by :func:`set_escdelay`.
517+
518+
.. versionadded:: 3.9
519+
520+
.. function:: set_escdelay(ms)
521+
522+
Sets the number of milliseconds to wait after reading an escape character,
523+
to distinguish between an individual escape character entered on the
524+
keyboard from escape sequences sent by cursor and function keys.
525+
526+
.. versionadded:: 3.9
527+
528+
.. function:: get_tabsize()
529+
530+
Retrieves the value set by :func:`set_tabsize`.
531+
532+
.. versionadded:: 3.9
533+
534+
.. function:: set_tabsize(size)
535+
536+
Sets the number of columns used by the curses library when converting a tab
537+
character to spaces as it adds the tab to a window.
538+
539+
.. versionadded:: 3.9
514540

515541
.. function:: setsyx(y, x)
516542

Doc/whatsnew/3.9.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,13 @@ that schedules a shutdown for the default executor that waits on the
130130
:func:`asyncio.run` has been updated to use the new :term:`coroutine`.
131131
(Contributed by Kyle Stanley in :issue:`34037`.)
132132

133+
curses
134+
------
135+
136+
Add :func:`curses.get_escdelay`, :func:`curses.set_escdelay`,
137+
:func:`curses.get_tabsize`, and :func:`curses.set_tabsize` functions.
138+
(Contributed by Anthony Sottile in :issue:`38312`.)
139+
133140
fcntl
134141
-----
135142

Lib/test/test_curses.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,10 @@ def test_module_funcs(self):
261261
curses.putp(b'abc')
262262
curses.qiflush()
263263
curses.raw() ; curses.raw(1)
264+
curses.set_escdelay(25)
265+
self.assertEqual(curses.get_escdelay(), 25)
266+
curses.set_tabsize(4)
267+
self.assertEqual(curses.get_tabsize(), 4)
264268
if hasattr(curses, 'setsyx'):
265269
curses.setsyx(5,5)
266270
curses.tigetflag('hc')
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Add :func:`curses.get_escdelay`, :func:`curses.set_escdelay`,
2+
:func:`curses.get_tabsize`, and :func:`curses.set_tabsize` functions -
3+
by Anthony Sottile.

Modules/_cursesmodule.c

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3255,6 +3255,86 @@ _curses_setupterm_impl(PyObject *module, const char *term, int fd)
32553255
Py_RETURN_NONE;
32563256
}
32573257

3258+
/*[clinic input]
3259+
_curses.get_escdelay
3260+
3261+
Gets the curses ESCDELAY setting.
3262+
3263+
Gets the number of milliseconds to wait after reading an escape character,
3264+
to distinguish between an individual escape character entered on the
3265+
keyboard from escape sequences sent by cursor and function keys.
3266+
[clinic start generated code]*/
3267+
3268+
static PyObject *
3269+
_curses_get_escdelay_impl(PyObject *module)
3270+
/*[clinic end generated code: output=222fa1a822555d60 input=be2d5b3dd974d0a4]*/
3271+
{
3272+
return PyLong_FromLong(ESCDELAY);
3273+
}
3274+
/*[clinic input]
3275+
_curses.set_escdelay
3276+
ms: int
3277+
length of the delay in milliseconds.
3278+
/
3279+
3280+
Sets the curses ESCDELAY setting.
3281+
3282+
Sets the number of milliseconds to wait after reading an escape character,
3283+
to distinguish between an individual escape character entered on the
3284+
keyboard from escape sequences sent by cursor and function keys.
3285+
[clinic start generated code]*/
3286+
3287+
static PyObject *
3288+
_curses_set_escdelay_impl(PyObject *module, int ms)
3289+
/*[clinic end generated code: output=43818efbf7980ac4 input=7796fe19f111e250]*/
3290+
{
3291+
if (ms <= 0) {
3292+
PyErr_SetString(PyExc_ValueError, "ms must be > 0");
3293+
return NULL;
3294+
}
3295+
3296+
return PyCursesCheckERR(set_escdelay(ms), "set_escdelay");
3297+
}
3298+
3299+
/*[clinic input]
3300+
_curses.get_tabsize
3301+
3302+
Gets the curses TABSIZE setting.
3303+
3304+
Gets the number of columns used by the curses library when converting a tab
3305+
character to spaces as it adds the tab to a window.
3306+
[clinic start generated code]*/
3307+
3308+
static PyObject *
3309+
_curses_get_tabsize_impl(PyObject *module)
3310+
/*[clinic end generated code: output=7e9e51fb6126fbdf input=74af86bf6c9f5d7e]*/
3311+
{
3312+
return PyLong_FromLong(TABSIZE);
3313+
}
3314+
/*[clinic input]
3315+
_curses.set_tabsize
3316+
size: int
3317+
rendered cell width of a tab character.
3318+
/
3319+
3320+
Sets the curses TABSIZE setting.
3321+
3322+
Sets the number of columns used by the curses library when converting a tab
3323+
character to spaces as it adds the tab to a window.
3324+
[clinic start generated code]*/
3325+
3326+
static PyObject *
3327+
_curses_set_tabsize_impl(PyObject *module, int size)
3328+
/*[clinic end generated code: output=c1de5a76c0daab1e input=78cba6a3021ad061]*/
3329+
{
3330+
if (size <= 0) {
3331+
PyErr_SetString(PyExc_ValueError, "size must be > 0");
3332+
return NULL;
3333+
}
3334+
3335+
return PyCursesCheckERR(set_tabsize(size), "set_tabsize");
3336+
}
3337+
32583338
/*[clinic input]
32593339
_curses.intrflush
32603340
@@ -4415,6 +4495,10 @@ static PyMethodDef PyCurses_methods[] = {
44154495
_CURSES_RESIZETERM_METHODDEF
44164496
_CURSES_RESIZE_TERM_METHODDEF
44174497
_CURSES_SAVETTY_METHODDEF
4498+
_CURSES_GET_ESCDELAY_METHODDEF
4499+
_CURSES_SET_ESCDELAY_METHODDEF
4500+
_CURSES_GET_TABSIZE_METHODDEF
4501+
_CURSES_SET_TABSIZE_METHODDEF
44184502
_CURSES_SETSYX_METHODDEF
44194503
_CURSES_SETUPTERM_METHODDEF
44204504
_CURSES_START_COLOR_METHODDEF

Modules/clinic/_cursesmodule.c.h

Lines changed: 123 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)