Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Doc/library/curses.rst
Original file line number Diff line number Diff line change
Expand Up @@ -838,6 +838,14 @@ The module :mod:`!curses` defines the following functions:
appearance of the screen.


.. function:: term_attrs()

Like :func:`termattrs`, but return the attributes as :ref:`WA_*
<curses-wa-constants>` values rather than ``A_*`` values.

.. versionadded:: next


.. function:: termname()

Return the value of the environment variable :envvar:`TERM`, as a bytes object,
Expand Down
5 changes: 5 additions & 0 deletions Doc/whatsnew/3.16.rst
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,11 @@ curses
:func:`~curses.scr_set`, which dump the whole screen to a file and restore it.
(Contributed by Serhiy Storchaka in :gh:`152260`.)

* Add the :func:`curses.term_attrs` function, which returns the supported
video attributes as :ref:`WA_* <curses-wa-constants>` values, the
counterpart of :func:`curses.termattrs`.
(Contributed by Serhiy Storchaka in :gh:`152332`.)

* Add the :mod:`curses` key-management functions :func:`~curses.define_key`,
:func:`~curses.key_defined` and :func:`~curses.keyok`, available when built
against an ncurses with ``NCURSES_EXT_FUNCS``.
Expand Down
2 changes: 1 addition & 1 deletion Lib/test/test_curses.py
Original file line number Diff line number Diff line change
Expand Up @@ -1277,13 +1277,13 @@ def test_misc_module_funcs(self):
curses.newpad(50, 50)

def test_env_queries(self):
# TODO: term_attrs()
self.assertIsInstance(curses.termname(), bytes)
self.assertIsInstance(curses.longname(), bytes)
self.assertIsInstance(curses.baudrate(), int)
self.assertIsInstance(curses.has_ic(), bool)
self.assertIsInstance(curses.has_il(), bool)
self.assertIsInstance(curses.termattrs(), int)
self.assertIsInstance(curses.term_attrs(), int)

c = curses.killchar()
self.assertIsInstance(c, bytes)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Add the :func:`curses.term_attrs` function, the counterpart of
:func:`curses.termattrs` for the ``WA_*`` attributes.
19 changes: 19 additions & 0 deletions Modules/_cursesmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -7333,6 +7333,24 @@ _curses_termattrs_impl(PyObject *module)
/*[clinic end generated code: output=b06f437fce1b6fc4 input=0559882a04f84d1d]*/
NoArgReturnIntFunctionBody(termattrs)

/*[clinic input]
_curses.term_attrs

Return a logical OR of all video attributes supported by the terminal.

The attributes are WA_* values, the extended-attribute counterparts of
the A_* values returned by termattrs().
[clinic start generated code]*/

static PyObject *
_curses_term_attrs_impl(PyObject *module)
/*[clinic end generated code: output=c559daa1370948d6 input=963136fd17ab797a]*/
{
PyCursesStatefulInitialised(module);

return PyLong_FromUnsignedLong(term_attrs());
}

/*[clinic input]
@permit_long_summary
_curses.termname
Expand Down Expand Up @@ -7891,6 +7909,7 @@ static PyMethodDef cursesmodule_methods[] = {
_CURSES_SETUPTERM_METHODDEF
_CURSES_START_COLOR_METHODDEF
_CURSES_TERMATTRS_METHODDEF
_CURSES_TERM_ATTRS_METHODDEF
_CURSES_TERMNAME_METHODDEF
_CURSES_TIGETFLAG_METHODDEF
_CURSES_TIGETNUM_METHODDEF
Expand Down
23 changes: 22 additions & 1 deletion Modules/clinic/_cursesmodule.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading