Skip to content

Commit 0ed6711

Browse files
gh-152332: Add the curses.term_attrs() function (GH-152333)
term_attrs() returns the video attributes supported by the terminal as WA_* values, the counterpart of termattrs() for the A_* values. Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 003d362 commit 0ed6711

6 files changed

Lines changed: 57 additions & 2 deletions

File tree

Doc/library/curses.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -841,6 +841,14 @@ The module :mod:`!curses` defines the following functions:
841841
appearance of the screen.
842842

843843

844+
.. function:: term_attrs()
845+
846+
Like :func:`termattrs`, but return the attributes as :ref:`WA_*
847+
<curses-wa-constants>` values rather than ``A_*`` values.
848+
849+
.. versionadded:: next
850+
851+
844852
.. function:: termname()
845853

846854
Return the value of the environment variable :envvar:`TERM`, as a bytes object,

Doc/whatsnew/3.16.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,11 @@ curses
165165
:func:`~curses.scr_set`, which dump the whole screen to a file and restore it.
166166
(Contributed by Serhiy Storchaka in :gh:`152260`.)
167167

168+
* Add the :func:`curses.term_attrs` function, which returns the supported
169+
video attributes as :ref:`WA_* <curses-wa-constants>` values, the
170+
counterpart of :func:`curses.termattrs`.
171+
(Contributed by Serhiy Storchaka in :gh:`152332`.)
172+
168173
* Add the :mod:`curses` key-management functions :func:`~curses.define_key`,
169174
:func:`~curses.key_defined` and :func:`~curses.keyok`, available when built
170175
against an ncurses with ``NCURSES_EXT_FUNCS``.

Lib/test/test_curses.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1512,13 +1512,13 @@ def test_misc_module_funcs(self):
15121512
curses.newpad(50, 50)
15131513

15141514
def test_env_queries(self):
1515-
# TODO: term_attrs()
15161515
self.assertIsInstance(curses.termname(), bytes)
15171516
self.assertIsInstance(curses.longname(), bytes)
15181517
self.assertIsInstance(curses.baudrate(), int)
15191518
self.assertIsInstance(curses.has_ic(), bool)
15201519
self.assertIsInstance(curses.has_il(), bool)
15211520
self.assertIsInstance(curses.termattrs(), int)
1521+
self.assertIsInstance(curses.term_attrs(), int)
15221522

15231523
c = curses.killchar()
15241524
self.assertIsInstance(c, bytes)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Add the :func:`curses.term_attrs` function, the counterpart of
2+
:func:`curses.termattrs` for the ``WA_*`` attributes.

Modules/_cursesmodule.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7347,6 +7347,24 @@ _curses_termattrs_impl(PyObject *module)
73477347
/*[clinic end generated code: output=b06f437fce1b6fc4 input=0559882a04f84d1d]*/
73487348
NoArgReturnIntFunctionBody(termattrs)
73497349

7350+
/*[clinic input]
7351+
_curses.term_attrs
7352+
7353+
Return a logical OR of all video attributes supported by the terminal.
7354+
7355+
The attributes are WA_* values, the extended-attribute counterparts of
7356+
the A_* values returned by termattrs().
7357+
[clinic start generated code]*/
7358+
7359+
static PyObject *
7360+
_curses_term_attrs_impl(PyObject *module)
7361+
/*[clinic end generated code: output=c559daa1370948d6 input=963136fd17ab797a]*/
7362+
{
7363+
PyCursesStatefulInitialised(module);
7364+
7365+
return PyLong_FromUnsignedLong(term_attrs());
7366+
}
7367+
73507368
/*[clinic input]
73517369
@permit_long_summary
73527370
_curses.termname
@@ -7905,6 +7923,7 @@ static PyMethodDef cursesmodule_methods[] = {
79057923
_CURSES_SETUPTERM_METHODDEF
79067924
_CURSES_START_COLOR_METHODDEF
79077925
_CURSES_TERMATTRS_METHODDEF
7926+
_CURSES_TERM_ATTRS_METHODDEF
79087927
_CURSES_TERMNAME_METHODDEF
79097928
_CURSES_TIGETFLAG_METHODDEF
79107929
_CURSES_TIGETNUM_METHODDEF

Modules/clinic/_cursesmodule.c.h

Lines changed: 22 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)