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
146 changes: 146 additions & 0 deletions Doc/library/curses.rst
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,41 @@ The module :mod:`!curses` defines the following functions:
no flushing is done.


.. function:: is_cbreak()

Return ``True`` if cbreak mode (see :func:`cbreak`) is enabled,
``False`` otherwise.
Availability: ncurses 6.5 or later.

.. versionadded:: next


.. function:: is_echo()

Return ``True`` if echo mode (see :func:`echo`) is enabled,
``False`` otherwise.
Availability: ncurses 6.5 or later.

.. versionadded:: next


.. function:: is_nl()

Return ``True`` if nl mode (see :func:`nl`) is enabled, ``False`` otherwise.
Availability: ncurses 6.5 or later.

.. versionadded:: next


.. function:: is_raw()

Return ``True`` if raw mode (see :func:`raw`) is enabled,
``False`` otherwise.
Availability: ncurses 6.5 or later.

.. versionadded:: next


.. function:: is_term_resized(nlines, ncols)

Return ``True`` if :func:`resize_term` would modify the window structure,
Expand Down Expand Up @@ -1005,6 +1040,16 @@ Window objects
.. versionadded:: 3.3


.. method:: window.getdelay()

Return the window's read timeout in milliseconds,
as set by :meth:`nodelay` or :meth:`timeout`:
``-1`` for blocking, ``0`` for non-blocking,
or a positive number of milliseconds.

.. versionadded:: next


.. method:: window.getkey([y, x])

Get a character, returning a string instead of an integer, as :meth:`getch`
Expand All @@ -1018,13 +1063,29 @@ Window objects
Return a tuple ``(y, x)`` of the height and width of the window.


.. method:: window.getparent()

Return the parent window of this subwindow,
or ``None`` if this window is not a subwindow.

.. versionadded:: next


.. method:: window.getparyx()

Return the beginning coordinates of this window relative to its parent window
as a tuple ``(y, x)``. Return ``(-1, -1)`` if this window has no
parent.


.. method:: window.getscrreg()

Return a tuple ``(top, bottom)`` of the window's current scrolling region,
as set by :meth:`setscrreg`.

.. versionadded:: next


.. method:: window.getstr()
window.getstr(n)
window.getstr(y, x)
Expand Down Expand Up @@ -1137,13 +1198,98 @@ Window objects
The maximum value for *n* was increased from 1023 to 2047.


.. method:: window.is_cleared()

Return the current value set by :meth:`clearok`.

.. versionadded:: next


.. method:: window.is_idcok()

Return the current value set by :meth:`idcok`.

.. versionadded:: next


.. method:: window.is_idlok()

Return the current value set by :meth:`idlok`.

.. versionadded:: next


.. method:: window.is_immedok()

Return the current value set by :meth:`immedok`.

.. versionadded:: next


.. method:: window.is_keypad()

Return the current value set by :meth:`keypad`.

.. versionadded:: next


.. method:: window.is_leaveok()

Return the current value set by :meth:`leaveok`.

.. versionadded:: next


.. method:: window.is_linetouched(line)

Return ``True`` if the specified line was modified since the last call to
:meth:`refresh`; otherwise return ``False``. Raise a :exc:`curses.error`
exception if *line* is not valid for the given window.


.. method:: window.is_nodelay()

Return the current value set by :meth:`nodelay`.

.. versionadded:: next


.. method:: window.is_notimeout()

Return the current value set by :meth:`notimeout`.

.. versionadded:: next


.. method:: window.is_pad()

Return ``True`` if the window is a pad created by :func:`newpad`.

.. versionadded:: next


.. method:: window.is_scrollok()

Return the current value set by :meth:`scrollok`.

.. versionadded:: next


.. method:: window.is_subwin()

Return ``True`` if the window is a subwindow created by :meth:`subwin`
or :meth:`derwin`.

.. versionadded:: next


.. method:: window.is_syncok()

Return the current value set by :meth:`syncok`.

.. versionadded:: next


.. method:: window.is_wintouched()

Return ``True`` if the specified window was modified since the last call to
Expand Down
6 changes: 6 additions & 0 deletions Doc/whatsnew/3.16.rst
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@ curses
* Add :func:`curses.nofilter`, which undoes the effect of :func:`curses.filter`.
(Contributed by Serhiy Storchaka in :gh:`151744`.)

* Add :mod:`curses` functions and window methods that report state which could
previously only be set, such as :meth:`curses.window.is_keypad`,
:meth:`curses.window.getparent` and :func:`curses.is_cbreak`,
available when built against an ncurses with ``NCURSES_EXT_FUNCS``.
(Contributed by Serhiy Storchaka in :gh:`151776`.)

gzip
----

Expand Down
69 changes: 69 additions & 0 deletions Lib/test/test_curses.py
Original file line number Diff line number Diff line change
Expand Up @@ -890,6 +890,75 @@ def test_input_options(self):
stdscr.timeout(0)
stdscr.timeout(5)

@requires_curses_window_meth('is_scrollok')
def test_state_getters(self):
stdscr = self.stdscr
# Each is_*() getter returns the value set by the matching setter.
for setter, getter in [
('clearok', 'is_cleared'),
('idcok', 'is_idcok'),
('idlok', 'is_idlok'),
('keypad', 'is_keypad'),
('leaveok', 'is_leaveok'),
('nodelay', 'is_nodelay'),
('notimeout', 'is_notimeout'),
('scrollok', 'is_scrollok'),
]:
getattr(stdscr, setter)(True)
self.assertIs(getattr(stdscr, getter)(), True)
getattr(stdscr, setter)(False)
self.assertIs(getattr(stdscr, getter)(), False)
if hasattr(stdscr, 'immedok'):
stdscr.immedok(True)
self.assertIs(stdscr.is_immedok(), True)
stdscr.immedok(False)
if hasattr(stdscr, 'syncok'):
stdscr.syncok(True)
self.assertIs(stdscr.is_syncok(), True)
stdscr.syncok(False)

# getdelay() reflects timeout()/nodelay().
stdscr.timeout(100)
self.assertEqual(stdscr.getdelay(), 100)
stdscr.nodelay(True)
self.assertEqual(stdscr.getdelay(), 0)
stdscr.timeout(-1)
self.assertEqual(stdscr.getdelay(), -1)

# getscrreg() reflects setscrreg().
stdscr.setscrreg(5, 10)
self.assertEqual(stdscr.getscrreg(), (5, 10))

# is_pad()/is_subwin()/getparent().
self.assertIs(stdscr.is_pad(), False)
self.assertIs(stdscr.is_subwin(), False)
self.assertIsNone(stdscr.getparent())
sub = stdscr.subwin(3, 3, 0, 0)
self.assertIs(sub.is_subwin(), True)
self.assertIs(sub.getparent(), stdscr)
pad = curses.newpad(5, 5)
self.assertIs(pad.is_pad(), True)

@requires_curses_func('is_cbreak')
def test_global_state_getters(self):
if self.isatty:
curses.cbreak()
self.assertIs(curses.is_cbreak(), True)
curses.nocbreak()
self.assertIs(curses.is_cbreak(), False)
curses.raw()
self.assertIs(curses.is_raw(), True)
curses.noraw()
self.assertIs(curses.is_raw(), False)
curses.echo()
self.assertIs(curses.is_echo(), True)
curses.noecho()
self.assertIs(curses.is_echo(), False)
curses.nl()
self.assertIs(curses.is_nl(), True)
curses.nonl()
self.assertIs(curses.is_nl(), False)

@requires_curses_func('typeahead')
def test_typeahead(self):
curses.typeahead(sys.__stdin__.fileno())
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Add :mod:`curses` functions and window methods that report state which could
previously only be set: the window methods :meth:`~curses.window.is_cleared`,
:meth:`~curses.window.is_idcok`, :meth:`~curses.window.is_idlok`,
:meth:`~curses.window.is_immedok`, :meth:`~curses.window.is_keypad`,
:meth:`~curses.window.is_leaveok`, :meth:`~curses.window.is_nodelay`,
:meth:`~curses.window.is_notimeout`, :meth:`~curses.window.is_pad`,
:meth:`~curses.window.is_scrollok`, :meth:`~curses.window.is_subwin`,
:meth:`~curses.window.is_syncok`, :meth:`~curses.window.getdelay`,
:meth:`~curses.window.getparent` and :meth:`~curses.window.getscrreg`, and the
functions :func:`curses.is_cbreak`, :func:`curses.is_echo`,
:func:`curses.is_nl` and :func:`curses.is_raw`. They are only available when
built against an ncurses with ``NCURSES_EXT_FUNCS``.
Loading
Loading