urwid 5.1.2__tar.gz → 5.1.3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (139) hide show
  1. {urwid-5.1.2 → urwid-5.1.3}/PKG-INFO +1 -28
  2. {urwid-5.1.2 → urwid-5.1.3}/README.rst +0 -26
  3. {urwid-5.1.2 → urwid-5.1.3}/SECURITY.md +3 -1
  4. {urwid-5.1.2 → urwid-5.1.3}/classifiers.txt +0 -1
  5. {urwid-5.1.2 → urwid-5.1.3}/conftest.py +1 -1
  6. {urwid-5.1.2 → urwid-5.1.3}/tox.ini +0 -25
  7. {urwid-5.1.2 → urwid-5.1.3}/urwid/_deprecation.py +12 -4
  8. {urwid-5.1.2 → urwid-5.1.3}/urwid/display/_posix_raw_display.py +83 -9
  9. {urwid-5.1.2 → urwid-5.1.3}/urwid/display/_raw_display_base.py +151 -34
  10. {urwid-5.1.2 → urwid-5.1.3}/urwid/display/_web.js +2 -1
  11. {urwid-5.1.2 → urwid-5.1.3}/urwid/display/_web_common.py +42 -0
  12. {urwid-5.1.2 → urwid-5.1.3}/urwid/display/_win32_raw_display.py +65 -20
  13. {urwid-5.1.2 → urwid-5.1.3}/urwid/display/curses.py +113 -15
  14. {urwid-5.1.2 → urwid-5.1.3}/urwid/display/escape.py +385 -101
  15. {urwid-5.1.2 → urwid-5.1.3}/urwid/display/web.py +69 -17
  16. {urwid-5.1.2 → urwid-5.1.3}/urwid/display/websocket.py +4 -31
  17. {urwid-5.1.2 → urwid-5.1.3}/urwid/event_loop/asyncio_loop.py +6 -5
  18. {urwid-5.1.2 → urwid-5.1.3}/urwid/event_loop/main_loop.py +29 -7
  19. {urwid-5.1.2 → urwid-5.1.3}/urwid/event_loop/zmq_loop.py +1 -1
  20. {urwid-5.1.2 → urwid-5.1.3}/urwid/str_util.py +11 -2
  21. {urwid-5.1.2 → urwid-5.1.3}/urwid/util.py +32 -17
  22. {urwid-5.1.2 → urwid-5.1.3}/urwid/version.py +3 -3
  23. {urwid-5.1.2 → urwid-5.1.3}/urwid/vterm.py +116 -17
  24. {urwid-5.1.2 → urwid-5.1.3}/urwid/widget/bar_graph.py +1 -2
  25. {urwid-5.1.2 → urwid-5.1.3}/urwid/widget/columns.py +2 -2
  26. {urwid-5.1.2 → urwid-5.1.3}/urwid/widget/drop_down.py +13 -5
  27. {urwid-5.1.2 → urwid-5.1.3}/urwid/widget/monitored_deque.py +54 -7
  28. {urwid-5.1.2 → urwid-5.1.3}/urwid/widget/monitored_list.py +45 -9
  29. {urwid-5.1.2 → urwid-5.1.3}/urwid/widget/pile.py +2 -2
  30. {urwid-5.1.2 → urwid-5.1.3}/urwid/widget/spinner.py +1 -2
  31. {urwid-5.1.2 → urwid-5.1.3}/urwid/widget/widget.py +1 -10
  32. {urwid-5.1.2 → urwid-5.1.3}/urwid.egg-info/PKG-INFO +1 -28
  33. {urwid-5.1.2 → urwid-5.1.3}/urwid.egg-info/scm_file_list.json +3 -0
  34. urwid-5.1.3/urwid.egg-info/scm_version.json +8 -0
  35. urwid-5.1.2/urwid.egg-info/scm_version.json +0 -8
  36. {urwid-5.1.2 → urwid-5.1.3}/.devcontainer/dev.dockerfile +0 -0
  37. {urwid-5.1.2 → urwid-5.1.3}/.devcontainer/devcontainer.json +0 -0
  38. {urwid-5.1.2 → urwid-5.1.3}/.devcontainer/docs-pdf/devcontainer.json +0 -0
  39. {urwid-5.1.2 → urwid-5.1.3}/.dockerignore +0 -0
  40. {urwid-5.1.2 → urwid-5.1.3}/.editorconfig +0 -0
  41. {urwid-5.1.2 → urwid-5.1.3}/.github/CODE_OF_CONDUCT.md +0 -0
  42. {urwid-5.1.2 → urwid-5.1.3}/.github/ISSUE_TEMPLATE/bug_report.md +0 -0
  43. {urwid-5.1.2 → urwid-5.1.3}/.github/ISSUE_TEMPLATE/docs.md +0 -0
  44. {urwid-5.1.2 → urwid-5.1.3}/.github/ISSUE_TEMPLATE/feature_request.md +0 -0
  45. {urwid-5.1.2 → urwid-5.1.3}/.github/ISSUE_TEMPLATE/question.md +0 -0
  46. {urwid-5.1.2 → urwid-5.1.3}/.github/PULL_REQUEST_TEMPLATE.md +0 -0
  47. {urwid-5.1.2 → urwid-5.1.3}/.github/dependabot.yml +0 -0
  48. {urwid-5.1.2 → urwid-5.1.3}/.github/labeler.yml +0 -0
  49. {urwid-5.1.2 → urwid-5.1.3}/.github/release.yml +0 -0
  50. {urwid-5.1.2 → urwid-5.1.3}/.github/workflows/documentation-pdf.yml +0 -0
  51. {urwid-5.1.2 → urwid-5.1.3}/.github/workflows/documentation.yml +0 -0
  52. {urwid-5.1.2 → urwid-5.1.3}/.github/workflows/isolated_mypy.yml +0 -0
  53. {urwid-5.1.2 → urwid-5.1.3}/.github/workflows/isolated_pylint.yml +0 -0
  54. {urwid-5.1.2 → urwid-5.1.3}/.github/workflows/isolated_pyrefly.yml +0 -0
  55. {urwid-5.1.2 → urwid-5.1.3}/.github/workflows/labels.yml +0 -0
  56. {urwid-5.1.2 → urwid-5.1.3}/.github/workflows/pythonpackage.yml +0 -0
  57. {urwid-5.1.2 → urwid-5.1.3}/.github/workflows/yamllint.yml +0 -0
  58. {urwid-5.1.2 → urwid-5.1.3}/.gitignore +0 -0
  59. {urwid-5.1.2 → urwid-5.1.3}/.pre-commit-config.yaml +0 -0
  60. {urwid-5.1.2 → urwid-5.1.3}/.yamllint.yml +0 -0
  61. {urwid-5.1.2 → urwid-5.1.3}/COPYING +0 -0
  62. {urwid-5.1.2 → urwid-5.1.3}/MANIFEST.in +0 -0
  63. {urwid-5.1.2 → urwid-5.1.3}/mypy-requirements.txt +0 -0
  64. {urwid-5.1.2 → urwid-5.1.3}/pylint-requirements.txt +0 -0
  65. {urwid-5.1.2 → urwid-5.1.3}/pyproject.toml +0 -0
  66. {urwid-5.1.2 → urwid-5.1.3}/pyrefly-requirements.txt +0 -0
  67. {urwid-5.1.2 → urwid-5.1.3}/pytest_requirements.txt +0 -0
  68. {urwid-5.1.2 → urwid-5.1.3}/requirements.txt +0 -0
  69. {urwid-5.1.2 → urwid-5.1.3}/setup.cfg +0 -0
  70. {urwid-5.1.2 → urwid-5.1.3}/urwid/__init__.py +0 -0
  71. {urwid-5.1.2 → urwid-5.1.3}/urwid/_selectors.py +0 -0
  72. {urwid-5.1.2 → urwid-5.1.3}/urwid/ansi_parser.py +0 -0
  73. {urwid-5.1.2 → urwid-5.1.3}/urwid/canvas.py +0 -0
  74. {urwid-5.1.2 → urwid-5.1.3}/urwid/command_map.py +0 -0
  75. {urwid-5.1.2 → urwid-5.1.3}/urwid/display/__init__.py +0 -0
  76. {urwid-5.1.2 → urwid-5.1.3}/urwid/display/_web.css +0 -0
  77. {urwid-5.1.2 → urwid-5.1.3}/urwid/display/_web_common.js +0 -0
  78. {urwid-5.1.2 → urwid-5.1.3}/urwid/display/_websocket.css +0 -0
  79. {urwid-5.1.2 → urwid-5.1.3}/urwid/display/_websocket.html +0 -0
  80. {urwid-5.1.2 → urwid-5.1.3}/urwid/display/_websocket.js +0 -0
  81. {urwid-5.1.2 → urwid-5.1.3}/urwid/display/_win32.py +0 -0
  82. {urwid-5.1.2 → urwid-5.1.3}/urwid/display/common.py +0 -0
  83. {urwid-5.1.2 → urwid-5.1.3}/urwid/display/html_fragment.py +0 -0
  84. {urwid-5.1.2 → urwid-5.1.3}/urwid/display/lcd.py +0 -0
  85. {urwid-5.1.2 → urwid-5.1.3}/urwid/display/raw.py +0 -0
  86. {urwid-5.1.2 → urwid-5.1.3}/urwid/event_loop/__init__.py +0 -0
  87. {urwid-5.1.2 → urwid-5.1.3}/urwid/event_loop/abstract_loop.py +0 -0
  88. {urwid-5.1.2 → urwid-5.1.3}/urwid/event_loop/glib_loop.py +0 -0
  89. {urwid-5.1.2 → urwid-5.1.3}/urwid/event_loop/guarded_loop.py +0 -0
  90. {urwid-5.1.2 → urwid-5.1.3}/urwid/event_loop/select_loop.py +0 -0
  91. {urwid-5.1.2 → urwid-5.1.3}/urwid/event_loop/tornado_loop.py +0 -0
  92. {urwid-5.1.2 → urwid-5.1.3}/urwid/event_loop/trio_loop.py +0 -0
  93. {urwid-5.1.2 → urwid-5.1.3}/urwid/event_loop/twisted_loop.py +0 -0
  94. {urwid-5.1.2 → urwid-5.1.3}/urwid/font.py +0 -0
  95. {urwid-5.1.2 → urwid-5.1.3}/urwid/graphics.py +0 -0
  96. {urwid-5.1.2 → urwid-5.1.3}/urwid/numedit.py +0 -0
  97. {urwid-5.1.2 → urwid-5.1.3}/urwid/py.typed +0 -0
  98. {urwid-5.1.2 → urwid-5.1.3}/urwid/signals.py +0 -0
  99. {urwid-5.1.2 → urwid-5.1.3}/urwid/split_repr.py +0 -0
  100. {urwid-5.1.2 → urwid-5.1.3}/urwid/testing.py +0 -0
  101. {urwid-5.1.2 → urwid-5.1.3}/urwid/text_layout.py +0 -0
  102. {urwid-5.1.2 → urwid-5.1.3}/urwid/widget/__init__.py +0 -0
  103. {urwid-5.1.2 → urwid-5.1.3}/urwid/widget/ansi_text.py +0 -0
  104. {urwid-5.1.2 → urwid-5.1.3}/urwid/widget/attr_map.py +0 -0
  105. {urwid-5.1.2 → urwid-5.1.3}/urwid/widget/attr_wrap.py +0 -0
  106. {urwid-5.1.2 → urwid-5.1.3}/urwid/widget/big_text.py +0 -0
  107. {urwid-5.1.2 → urwid-5.1.3}/urwid/widget/box_adapter.py +0 -0
  108. {urwid-5.1.2 → urwid-5.1.3}/urwid/widget/constants.py +0 -0
  109. {urwid-5.1.2 → urwid-5.1.3}/urwid/widget/container.py +0 -0
  110. {urwid-5.1.2 → urwid-5.1.3}/urwid/widget/deque_walker.py +0 -0
  111. {urwid-5.1.2 → urwid-5.1.3}/urwid/widget/divider.py +0 -0
  112. {urwid-5.1.2 → urwid-5.1.3}/urwid/widget/edit.py +0 -0
  113. {urwid-5.1.2 → urwid-5.1.3}/urwid/widget/filler.py +0 -0
  114. {urwid-5.1.2 → urwid-5.1.3}/urwid/widget/filtered_walker.py +0 -0
  115. {urwid-5.1.2 → urwid-5.1.3}/urwid/widget/frame.py +0 -0
  116. {urwid-5.1.2 → urwid-5.1.3}/urwid/widget/grid_flow.py +0 -0
  117. {urwid-5.1.2 → urwid-5.1.3}/urwid/widget/line_box.py +0 -0
  118. {urwid-5.1.2 → urwid-5.1.3}/urwid/widget/list_walker.py +0 -0
  119. {urwid-5.1.2 → urwid-5.1.3}/urwid/widget/listbox.py +0 -0
  120. {urwid-5.1.2 → urwid-5.1.3}/urwid/widget/notifications.py +0 -0
  121. {urwid-5.1.2 → urwid-5.1.3}/urwid/widget/overlay.py +0 -0
  122. {urwid-5.1.2 → urwid-5.1.3}/urwid/widget/overlay_stack.py +0 -0
  123. {urwid-5.1.2 → urwid-5.1.3}/urwid/widget/padding.py +0 -0
  124. {urwid-5.1.2 → urwid-5.1.3}/urwid/widget/popup.py +0 -0
  125. {urwid-5.1.2 → urwid-5.1.3}/urwid/widget/progress_bar.py +0 -0
  126. {urwid-5.1.2 → urwid-5.1.3}/urwid/widget/scrollable.py +0 -0
  127. {urwid-5.1.2 → urwid-5.1.3}/urwid/widget/solid_fill.py +0 -0
  128. {urwid-5.1.2 → urwid-5.1.3}/urwid/widget/table.py +0 -0
  129. {urwid-5.1.2 → urwid-5.1.3}/urwid/widget/tabs.py +0 -0
  130. {urwid-5.1.2 → urwid-5.1.3}/urwid/widget/text.py +0 -0
  131. {urwid-5.1.2 → urwid-5.1.3}/urwid/widget/treetools.py +0 -0
  132. {urwid-5.1.2 → urwid-5.1.3}/urwid/widget/widget_decoration.py +0 -0
  133. {urwid-5.1.2 → urwid-5.1.3}/urwid/widget/wimp.py +0 -0
  134. {urwid-5.1.2 → urwid-5.1.3}/urwid.egg-info/SOURCES.txt +0 -0
  135. {urwid-5.1.2 → urwid-5.1.3}/urwid.egg-info/dependency_links.txt +0 -0
  136. {urwid-5.1.2 → urwid-5.1.3}/urwid.egg-info/not-zip-safe +0 -0
  137. {urwid-5.1.2 → urwid-5.1.3}/urwid.egg-info/requires.txt +0 -0
  138. {urwid-5.1.2 → urwid-5.1.3}/urwid.egg-info/top_level.txt +0 -0
  139. {urwid-5.1.2 → urwid-5.1.3}/yamllint-requirements.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: urwid
3
- Version: 5.1.2
3
+ Version: 5.1.3
4
4
  Summary: A full-featured console (xterm et al.) user interface library
5
5
  Author-email: Ian Ward <ian@excess.org>
6
6
  License-Expression: LGPL-2.1-only
@@ -30,7 +30,6 @@ Classifier: Programming Language :: Python :: 3.15
30
30
  Classifier: Programming Language :: Python :: 3 :: Only
31
31
  Classifier: Programming Language :: Python :: Implementation :: CPython
32
32
  Classifier: Programming Language :: Python :: Implementation :: PyPy
33
- Classifier: Programming Language :: Python :: Implementation :: GraalPy
34
33
  Classifier: Programming Language :: Python :: Free Threading :: 2 - Beta
35
34
  Classifier: Typing :: Typed
36
35
  Requires-Python: >=3.11.0
@@ -173,19 +172,6 @@ Tests with compatible extras (tornado, trio, serial). Excludes problematic C ext
173
172
  tox -e pypy311 # PyPy 3.11
174
173
  tox -e pypy312 # PyPy 3.12
175
174
 
176
- **GraalPy**
177
-
178
- Tests with compatible extras (tornado, serial). Excludes extras that need C extensions GraalPy
179
- doesn't support (glib, zmq) or that have known compatibility issues (trio, twisted). GraalPy also
180
- ships no ``_curses`` module, so curses-dependent tests are expected to fail, and the Terminal
181
- widget (``urwid.vterm``) is unsupported since its ``fcntl``/``pty`` usage doesn't work on GraalPy,
182
- so its tests are skipped rather than run.
183
-
184
- .. code:: bash
185
-
186
- tox -e graalpy312 # GraalPy 3.12
187
- tox -e graalpy313 # GraalPy 3.13
188
-
189
175
  Supported Python versions
190
176
  =========================
191
177
 
@@ -194,7 +180,6 @@ Urwid supports:
194
180
  - CPython 3.11, 3.12, 3.13, 3.14, 3.15
195
181
  - CPython 3.13+ with free-threading (PEP 703 ``--disable-gil``)
196
182
  - PyPy 3.11
197
- - GraalPy 3.12, 3.13 (experimental)
198
183
 
199
184
  Python implementation notes
200
185
  ===========================
@@ -227,18 +212,6 @@ Urwid core is fully supported. Some extras may have compatibility issues:
227
212
  - ❌ Unsupported: curses on Windows (PyPy for Windows ships no ``_curses`` module and ``windows-curses`` publishes
228
213
  no PyPy wheels)
229
214
 
230
- **GraalPy (experimental)**
231
-
232
- Urwid core and the ``select``/``asyncio`` event loops are supported. Some extras, display
233
- modules, and the Terminal widget are not:
234
-
235
- - ✅ Supported: core, tornado, serial, lcd
236
- - ❌ Unsupported: curses (GraalPy ships no ``_curses`` module), glib, zmq, twisted, trio (no C
237
- extension support, or known compatibility issues), Terminal widget/``urwid.vterm`` (like on
238
- Windows, ``fcntl``/``pty`` usage doesn't work on GraalPy)
239
- - ❌ Unsupported: GraalPy 3.11 (GraalPy 24), whose ``os`` module has no ``O_NOFOLLOW`` and whose ASCII and Latin-1
240
- codecs ignore registered error handlers
241
-
242
215
  Authors
243
216
  =======
244
217
 
@@ -115,19 +115,6 @@ Tests with compatible extras (tornado, trio, serial). Excludes problematic C ext
115
115
  tox -e pypy311 # PyPy 3.11
116
116
  tox -e pypy312 # PyPy 3.12
117
117
 
118
- **GraalPy**
119
-
120
- Tests with compatible extras (tornado, serial). Excludes extras that need C extensions GraalPy
121
- doesn't support (glib, zmq) or that have known compatibility issues (trio, twisted). GraalPy also
122
- ships no ``_curses`` module, so curses-dependent tests are expected to fail, and the Terminal
123
- widget (``urwid.vterm``) is unsupported since its ``fcntl``/``pty`` usage doesn't work on GraalPy,
124
- so its tests are skipped rather than run.
125
-
126
- .. code:: bash
127
-
128
- tox -e graalpy312 # GraalPy 3.12
129
- tox -e graalpy313 # GraalPy 3.13
130
-
131
118
  Supported Python versions
132
119
  =========================
133
120
 
@@ -136,7 +123,6 @@ Urwid supports:
136
123
  - CPython 3.11, 3.12, 3.13, 3.14, 3.15
137
124
  - CPython 3.13+ with free-threading (PEP 703 ``--disable-gil``)
138
125
  - PyPy 3.11
139
- - GraalPy 3.12, 3.13 (experimental)
140
126
 
141
127
  Python implementation notes
142
128
  ===========================
@@ -169,18 +155,6 @@ Urwid core is fully supported. Some extras may have compatibility issues:
169
155
  - ❌ Unsupported: curses on Windows (PyPy for Windows ships no ``_curses`` module and ``windows-curses`` publishes
170
156
  no PyPy wheels)
171
157
 
172
- **GraalPy (experimental)**
173
-
174
- Urwid core and the ``select``/``asyncio`` event loops are supported. Some extras, display
175
- modules, and the Terminal widget are not:
176
-
177
- - ✅ Supported: core, tornado, serial, lcd
178
- - ❌ Unsupported: curses (GraalPy ships no ``_curses`` module), glib, zmq, twisted, trio (no C
179
- extension support, or known compatibility issues), Terminal widget/``urwid.vterm`` (like on
180
- Windows, ``fcntl``/``pty`` usage doesn't work on GraalPy)
181
- - ❌ Unsupported: GraalPy 3.11 (GraalPy 24), whose ``os`` module has no ``O_NOFOLLOW`` and whose ASCII and Latin-1
182
- codecs ignore registered error handlers
183
-
184
158
  Authors
185
159
  =======
186
160
 
@@ -24,7 +24,9 @@ What the module protects:
24
24
  - The id is generated by `secrets.token_urlsafe()`.
25
25
  - A client-supplied id is checked against `_URWID_ID_MAX_LEN` and `_URWID_ID_CHARS` before any file lookup.
26
26
  - Resource limits
27
- - A keystroke request is read up to `MAX_READ` bytes.
27
+ - A request body is read up to the `CONTENT_LENGTH` the web server gives, never until end of input.
28
+ - A keystroke request over `MAX_READ` bytes, and an initial request over `MAX_INITIAL_READ` bytes, are refused.
29
+ - A keyboard input line longer than `MAX_LINE_LENGTH` characters is dropped, up to and including its newline.
28
30
  - The screen size is capped at `MAX_COLS` and `MAX_ROWS`.
29
31
  - The number of concurrent sessions of one user and `pipe_dir` is limited to about `max_clients`
30
32
  (`set_preferences()`): two sessions starting at once can both pass the check, and stale pipes count towards it.
@@ -18,6 +18,5 @@ Programming Language :: Python :: 3.15
18
18
  Programming Language :: Python :: 3 :: Only
19
19
  Programming Language :: Python :: Implementation :: CPython
20
20
  Programming Language :: Python :: Implementation :: PyPy
21
- Programming Language :: Python :: Implementation :: GraalPy
22
21
  Programming Language :: Python :: Free Threading :: 2 - Beta
23
22
  Typing :: Typed
@@ -40,7 +40,7 @@ def _backend_available(name: str) -> bool:
40
40
  """Return whether the module *name* can be imported.
41
41
 
42
42
  Importing is the only reliable probe.
43
- GraalPy and PyPy for Windows ship an ``_curses`` stub that ``find_spec`` resolves,
43
+ PyPy for Windows ships an ``_curses`` stub that ``find_spec`` resolves,
44
44
  but the stub raises ``ModuleNotFoundError`` on import.
45
45
  """
46
46
  try:
@@ -6,7 +6,6 @@ envlist =
6
6
  py31{1,2,3,4,5}
7
7
  py31{3,4,5}t
8
8
  pypy31{1,2}
9
- graalpy31{2,3}
10
9
  ruff
11
10
  pylint
12
11
  mypy
@@ -71,30 +70,6 @@ commands =
71
70
  setenv =
72
71
  PYTHONWARNDEFAULTENCODING=1
73
72
 
74
- [testenv:graalpy31{2,3}]
75
- # GraalPy (Oracle's Python implementation on GraalVM) - experimental support
76
- # GraalPy has limited C extension support, skip problematic ones
77
- usedevelop = true
78
- # GraalPy's JIT warm-up starves next to other environments, so each one runs last and alone.
79
- depends =
80
- {[testenv]depends}
81
- py31{1,2,3,4,5}
82
- py31{3,4,5}t
83
- pypy31{1,2}
84
- graalpy313: graalpy312
85
- dependency_groups = pytest
86
- # GraalPy doesn't support pygobject (glib), pyzmq, or twisted well
87
- extras =
88
- serial
89
- tornado
90
- # Coverage tracing slows GraalPy down by orders of magnitude (one test: 5 s without, over 10 min with).
91
- # Its JIT can be far slower on a cold or loaded machine than the 3.7 s its slowest test took on a workstation,
92
- # so it gets a wider per-test timeout than the project's 300 s.
93
- commands =
94
- pytest --no-cov --timeout=600
95
- setenv =
96
- PYTHONWARNDEFAULTENCODING=1
97
-
98
73
  [testenv:readme]
99
74
  dependency_groups = build
100
75
  extras =
@@ -46,8 +46,14 @@ __all__ = ("deprecated", "warn")
46
46
  _PACKAGE_PREFIX: typing.Final[str] = f"{pathlib.Path(__file__).absolute().parent}{os.sep}"
47
47
 
48
48
 
49
- def warn(message: str, *, since: str, removed_in: str | None) -> None:
50
- """Emit a :exc:`DeprecationWarning` attributed to the first frame outside urwid.
49
+ def warn(
50
+ message: str,
51
+ *,
52
+ since: str,
53
+ removed_in: str | None,
54
+ category: type[DeprecationWarning | PendingDeprecationWarning] = DeprecationWarning,
55
+ ) -> None:
56
+ """Emit a deprecation warning attributed to the first frame outside urwid.
51
57
 
52
58
  The warning points at the application line that used the deprecated API,
53
59
  also when the check runs several urwid frames deep (a ``Padding`` passing its argument to ``WidgetDecoration``).
@@ -56,6 +62,8 @@ def warn(message: str, *, since: str, removed_in: str | None) -> None:
56
62
  :param message: what is deprecated and what to use instead, as complete sentences
57
63
  :param since: the release that deprecated it
58
64
  :param removed_in: the release that removes it, or ``None`` when no removal release is decided
65
+ :param category: :exc:`PendingDeprecationWarning` for the quiet first stage of a deprecation,
66
+ which Python hides by default
59
67
  """
60
68
  if removed_in is None:
61
69
  full_message = f"{message} Deprecated since urwid {since}."
@@ -63,7 +71,7 @@ def warn(message: str, *, since: str, removed_in: str | None) -> None:
63
71
  full_message = f"{message} Deprecated since urwid {since}, will be removed in version {removed_in}."
64
72
 
65
73
  if sys.version_info >= (3, 12):
66
- warnings.warn(full_message, DeprecationWarning, skip_file_prefixes=(_PACKAGE_PREFIX,))
74
+ warnings.warn(full_message, category, skip_file_prefixes=(_PACKAGE_PREFIX,))
67
75
  else:
68
76
  # The frame calling warnings.warn() is stack level 1.
69
77
  frame = inspect.currentframe()
@@ -71,4 +79,4 @@ def warn(message: str, *, since: str, removed_in: str | None) -> None:
71
79
  while frame is not None and frame.f_code.co_filename.startswith(_PACKAGE_PREFIX):
72
80
  frame = frame.f_back
73
81
  stacklevel += 1
74
- warnings.warn(full_message, DeprecationWarning, stacklevel=stacklevel)
82
+ warnings.warn(full_message, category, stacklevel=stacklevel)
@@ -28,6 +28,7 @@ import fcntl
28
28
  import functools
29
29
  import os
30
30
  import signal
31
+ import stat
31
32
  import struct
32
33
  import subprocess
33
34
  import sys
@@ -37,6 +38,7 @@ import typing
37
38
  from subprocess import PIPE, Popen
38
39
 
39
40
  from urwid import signals
41
+ from urwid._selectors import read_selector
40
42
 
41
43
  from . import _raw_display_base, escape
42
44
  from .common import INPUT_DESCRIPTORS_CHANGED, InputClosedError
@@ -84,12 +86,19 @@ _GPM_MOD_ALTGR = 2
84
86
  _GPM_MOD_CTRL = 4
85
87
  _GPM_MOD_ALT = 8
86
88
 
87
- # most bytes of terminal input read per wake-up
88
- _INPUT_READ_LIMIT = 65536
89
-
90
89
  # seconds the gpm helper is given to exit on SIGINT before it is killed
91
90
  _GPM_STOP_TIMEOUT = 1.0
92
91
 
92
+ # Linux virtual consoles /dev/tty1 to /dev/tty63: TTY_MAJOR and MAX_NR_CONSOLES in the kernel's tty headers.
93
+ # Minor 0 is /dev/tty0, the console in the foreground, and minors from 64 on are serial ports.
94
+ _VT_MAJOR = 4
95
+ _VT_MAX_MINOR = 63
96
+ # TTYAUX_MAJOR: /dev/tty and /dev/console, which stand for another terminal.
97
+ _TTY_ALIAS_MAJOR = 5
98
+ # TIOCGDEV, _IOR('T', 0x32, unsigned int): the device behind an alias, in the kernel's 32-bit dev_t encoding.
99
+ # These architectures encode the read direction of an ioctl request in bit 30 instead of bit 31.
100
+ _TIOCGDEV = 0x40045432 if os.uname().machine.startswith(("alpha", "mips", "parisc", "ppc", "sparc")) else 0x80045432
101
+
93
102
 
94
103
  class Screen(_raw_display_base.Screen):
95
104
  """Raw screen backend that drives a real POSIX terminal."""
@@ -101,6 +110,8 @@ class Screen(_raw_display_base.Screen):
101
110
  bracketed_paste_mode: bool | None = None,
102
111
  focus_reporting: bool | None = None,
103
112
  extended_keys: bool = False,
113
+ *,
114
+ in_band_resize: bool | None = None,
104
115
  ) -> None:
105
116
  """Initialize a screen that directly prints escape codes to an output terminal.
106
117
 
@@ -115,6 +126,11 @@ class Screen(_raw_display_base.Screen):
115
126
  :param extended_keys: report the keys the legacy encodings cannot tell apart, such as ``'ctrl enter'``
116
127
  and ``'ctrl i'`` apart from ``'tab'``, through the keyboard protocol the terminal supports.
117
128
  Ctrl+C and Ctrl+Z then arrive as keys instead of signals; see :ref:`extended-keys`.
129
+ :param in_band_resize: take the terminal size from the resize notifications the terminal sends in the input
130
+ (DEC private mode 2048), as well as from ``SIGWINCH``; see :ref:`in-band-resize`.
131
+ None (default) auto-detects via DECRQM and enables it once confirmed supported,
132
+ except on the iTerm2 releases that send the notifications without their final byte;
133
+ pass True/False to force it without probing.
118
134
 
119
135
  .. note::
120
136
  on terminal-generated signals: putting the terminal into cbreak mode (see `start()`)
@@ -140,12 +156,15 @@ class Screen(_raw_display_base.Screen):
140
156
  and without ``IEXTEN`` no Ctrl+O can turn it off.
141
157
  `stop()` restores both flags.
142
158
  """
159
+ if in_band_resize is None and _raw_display_base.sends_incomplete_window_size_reports(os.environ):
160
+ in_band_resize = False
143
161
  super().__init__(
144
162
  input,
145
163
  output,
146
164
  bracketed_paste_mode=bracketed_paste_mode,
147
165
  focus_reporting=focus_reporting,
148
166
  extended_keys=extended_keys,
167
+ in_band_resize=in_band_resize,
149
168
  )
150
169
  self.gpm_mev: Popen[str] | None = None
151
170
  self.gpm_event_pending: bool = False
@@ -163,7 +182,8 @@ class Screen(_raw_display_base.Screen):
163
182
  f"input={self._term_input_file}, "
164
183
  f"output={self._term_output_file}, "
165
184
  f"bracketed_paste_mode={self.modes.bracketed_paste}, "
166
- f"focus_reporting={self.modes.focus_reporting})>"
185
+ f"focus_reporting={self.modes.focus_reporting}, "
186
+ f"in_band_resize={self.modes.in_band_resize})>"
167
187
  )
168
188
 
169
189
  def _sigwinch_handler(self, signum: int = signal.SIGWINCH, frame: FrameType | None = None) -> None:
@@ -214,17 +234,42 @@ class Screen(_raw_display_base.Screen):
214
234
 
215
235
  def _start_gpm_tracking(self) -> None:
216
236
  """
217
- Start the gpm helper that reports mouse events on the Linux console.
237
+ Start the gpm helper that reports mouse events on the Linux console the screen reads from.
238
+
239
+ The helper starts only when :attr:`term` names the Linux console and the input is a virtual console.
240
+ Input opened through :file:`/dev/tty` or :file:`/dev/console` counts as the terminal behind it.
241
+ The helper is attached to that console by number.
242
+ The gpm daemon gives a client that names no console of its own,
243
+ such as one on a pseudo-terminal, the events of every console without a client.
218
244
 
245
+ :raises OSError: the input descriptor cannot be examined, for example because it was closed.
219
246
  :raises RuntimeError: the gpm helper process provides no standard output.
220
247
  """
221
248
  if not os.path.isfile("/usr/bin/mev"):
222
249
  return
223
250
  if not _raw_display_base._is_linux_console(self.term): # pylint: disable=protected-access # same package
224
251
  return
252
+ fd = self._input_fileno()
253
+ if fd is None:
254
+ return
255
+ # The device number tells both whether the input is a virtual console and which one,
256
+ # whatever the names under /dev are.
257
+ input_stat = os.fstat(fd)
258
+ if not stat.S_ISCHR(input_stat.st_mode):
259
+ return
260
+ device = input_stat.st_rdev
261
+ if os.major(device) == _TTY_ALIAS_MAJOR:
262
+ try:
263
+ (device,) = struct.unpack("I", fcntl.ioctl(fd, _TIOCGDEV, bytes(4)))
264
+ except OSError: # a kernel without TIOCGDEV, or an alias with no terminal behind it
265
+ return
266
+ console = os.minor(device)
267
+ if os.major(device) != _VT_MAJOR or not 1 <= console <= _VT_MAX_MINOR:
268
+ return
225
269
 
226
- m = Popen(
227
- ["/usr/bin/mev", "-e", "158"],
270
+ m = Popen( # noqa: S603 # fixed program path; the only variable argument is the kernel's console number
271
+ # mev reads the console number with scanf("%x")
272
+ ["/usr/bin/mev", "-e", "158", "-C", f"{console:x}"],
228
273
  stdin=PIPE,
229
274
  stdout=PIPE,
230
275
  close_fds=True,
@@ -304,6 +349,9 @@ class Screen(_raw_display_base.Screen):
304
349
  if self.modes.focus_reporting:
305
350
  self.write(escape.PrivateMode.FOCUS_REPORTING.enable_seq)
306
351
 
352
+ if self.modes.in_band_resize:
353
+ self._set_in_band_resize(True)
354
+
307
355
  self._enable_keyboard_protocol()
308
356
  self._show_title()
309
357
 
@@ -323,6 +371,8 @@ class Screen(_raw_display_base.Screen):
323
371
  """Restore the screen."""
324
372
  self.clear()
325
373
  self.signal_restore()
374
+ # the terminal may be resized while stopped, and SIGWINCH is what reports that then
375
+ self._reported_cols_rows = None
326
376
 
327
377
  try:
328
378
  try:
@@ -332,6 +382,9 @@ class Screen(_raw_display_base.Screen):
332
382
  if self.modes.focus_reporting:
333
383
  self.write(escape.PrivateMode.FOCUS_REPORTING.disable_seq)
334
384
 
385
+ if self._in_band_resize:
386
+ self._set_in_band_resize(False)
387
+
335
388
  # before the alternate screen is left: the kitty keyboard flags are kept per screen
336
389
  self._disable_keyboard_protocol()
337
390
 
@@ -431,7 +484,10 @@ class Screen(_raw_display_base.Screen):
431
484
  self.stop() # restores the previous SIGTSTP disposition, which the kill below runs
432
485
  os.kill(os.getpid(), signal.SIGTSTP)
433
486
  self.start()
487
+ # This resize is the redraw after the resume and is set after this pass's read,
488
+ # so no input typed before it can still be waiting, and it is not held back.
434
489
  self._resized = True
490
+ self._hold_resize = False
435
491
  return codes
436
492
 
437
493
  def _get_input_codes(self) -> list[int]:
@@ -454,8 +510,13 @@ class Screen(_raw_display_base.Screen):
454
510
  """
455
511
  Read at most `_INPUT_READ_LIMIT` bytes of the raw input available, waiting at most *timeout* seconds.
456
512
 
513
+ `_hold_resize` is set when a resize can have input typed before it still waiting:
514
+ the resize was not pending when the read started, or input is still readable after it.
515
+
457
516
  :raises InputClosedError: the input file has been closed.
458
517
  """
518
+ resize_pending = self._resized
519
+ self._hold_resize = not resize_pending
459
520
  ready = self._wait_for_input_ready(timeout)
460
521
  gpm_stdout = self.gpm_mev.stdout if self.gpm_mev is not None else None
461
522
  if gpm_stdout is not None and gpm_stdout.fileno() in ready:
@@ -467,10 +528,14 @@ class Screen(_raw_display_base.Screen):
467
528
  return chars
468
529
 
469
530
  # `fd` was just reported ready, so this read does not block. Input beyond the limit is read on the next pass.
470
- chunk = os.read(fd, _INPUT_READ_LIMIT)
531
+ chunk = os.read(fd, _raw_display_base._INPUT_READ_LIMIT) # pylint: disable=protected-access # same package
471
532
  if not chunk:
472
533
  raise InputClosedError("stdin has been closed")
473
534
  chars.extend(chunk)
535
+ # A terminal returns at most its line discipline buffer per read (about 4 KiB on Linux), below the limit,
536
+ # so whether input is left is asked of the descriptor rather than read off the size of the chunk.
537
+ with read_selector([(fd, None)]) as selector:
538
+ self._hold_resize = not resize_pending or bool(selector.select(0))
474
539
  return chars
475
540
 
476
541
  def _encode_gpm_event(self) -> list[int]:
@@ -554,7 +619,15 @@ class Screen(_raw_display_base.Screen):
554
619
  return result
555
620
 
556
621
  def get_cols_rows(self) -> tuple[int, int]:
557
- """Return the terminal dimensions (num columns, num rows)."""
622
+ """Return the terminal dimensions (num columns, num rows).
623
+
624
+ The size the terminal last reported in the input is returned while it is newer than the last ``SIGWINCH``,
625
+ see :ref:`in-band-resize`; otherwise the size is read from the terminal device.
626
+ """
627
+ if self._reported_cols_rows is not None:
628
+ x, y = self._last_cols_rows = self._reported_cols_rows
629
+ self.maxrow = y
630
+ return x, y
558
631
  x, y = super().get_cols_rows()
559
632
  with contextlib.suppress(OSError): # Term size could not be determined
560
633
  if isinstance(self._term_output_file, _raw_display_base.SupportsFileno):
@@ -566,6 +639,7 @@ class Screen(_raw_display_base.Screen):
566
639
  if (x <= 0 or y <= 0) and self.term in {"ansi", "vt100"}:
567
640
  y, x = 24, 80
568
641
  self.maxrow = y
642
+ self._last_cols_rows = x, y
569
643
  return x, y
570
644
 
571
645