Skip to content

Commit d3bafbc

Browse files
gh-152332: Add the curses.term_attrs() function
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 bbf7786 commit d3bafbc

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
@@ -807,6 +807,14 @@ The module :mod:`!curses` defines the following functions:
807807
appearance of the screen.
808808

809809

810+
.. function:: term_attrs()
811+
812+
Like :func:`termattrs`, but return the attributes as :ref:`WA_*
813+
<curses-wa-constants>` values rather than ``A_*`` values.
814+
815+
.. versionadded:: next
816+
817+
810818
.. function:: termname()
811819

812820
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
gzip
169174
----
170175

Lib/test/test_curses.py

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

12841284
def test_env_queries(self):
1285-
# TODO: term_attrs()
12861285
self.assertIsInstance(curses.termname(), bytes)
12871286
self.assertIsInstance(curses.longname(), bytes)
12881287
self.assertIsInstance(curses.baudrate(), int)
12891288
self.assertIsInstance(curses.has_ic(), bool)
12901289
self.assertIsInstance(curses.has_il(), bool)
12911290
self.assertIsInstance(curses.termattrs(), int)
1291+
self.assertIsInstance(curses.term_attrs(), int)
12921292

12931293
c = curses.killchar()
12941294
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
@@ -7262,6 +7262,24 @@ _curses_termattrs_impl(PyObject *module)
72627262
/*[clinic end generated code: output=b06f437fce1b6fc4 input=0559882a04f84d1d]*/
72637263
NoArgReturnIntFunctionBody(termattrs)
72647264

7265+
/*[clinic input]
7266+
_curses.term_attrs
7267+
7268+
Return a logical OR of all video attributes supported by the terminal.
7269+
7270+
The attributes are WA_* values, the extended-attribute counterparts of
7271+
the A_* values returned by termattrs().
7272+
[clinic start generated code]*/
7273+
7274+
static PyObject *
7275+
_curses_term_attrs_impl(PyObject *module)
7276+
/*[clinic end generated code: output=c559daa1370948d6 input=963136fd17ab797a]*/
7277+
{
7278+
PyCursesStatefulInitialised(module);
7279+
7280+
return PyLong_FromUnsignedLong(term_attrs());
7281+
}
7282+
72657283
/*[clinic input]
72667284
@permit_long_summary
72677285
_curses.termname
@@ -7817,6 +7835,7 @@ static PyMethodDef cursesmodule_methods[] = {
78177835
_CURSES_SETUPTERM_METHODDEF
78187836
_CURSES_START_COLOR_METHODDEF
78197837
_CURSES_TERMATTRS_METHODDEF
7838+
_CURSES_TERM_ATTRS_METHODDEF
78207839
_CURSES_TERMNAME_METHODDEF
78217840
_CURSES_TIGETFLAG_METHODDEF
78227841
_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)