urwid 5.2.0__tar.gz → 5.2.1__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 (179) hide show
  1. {urwid-5.2.0 → urwid-5.2.1}/PKG-INFO +5 -2
  2. {urwid-5.2.0 → urwid-5.2.1}/README.rst +4 -1
  3. {urwid-5.2.0 → urwid-5.2.1}/urwid/canvas/term/_parser.py +15 -8
  4. {urwid-5.2.0 → urwid-5.2.1}/urwid/canvas/term/_rectangles.py +1 -1
  5. {urwid-5.2.0 → urwid-5.2.1}/urwid/canvas/term/_reports.py +21 -12
  6. {urwid-5.2.0 → urwid-5.2.1}/urwid/display/_posix_raw_display.py +2 -4
  7. {urwid-5.2.0 → urwid-5.2.1}/urwid/display/_raw_display_base/_base.py +1 -1
  8. {urwid-5.2.0 → urwid-5.2.1}/urwid/display/_raw_display_base/_detection.py +44 -79
  9. {urwid-5.2.0 → urwid-5.2.1}/urwid/display/_raw_display_base/_modes.py +18 -0
  10. {urwid-5.2.0 → urwid-5.2.1}/urwid/display/_win32_raw_display.py +1 -1
  11. {urwid-5.2.0 → urwid-5.2.1}/urwid/event_loop/main_loop.py +15 -1
  12. {urwid-5.2.0 → urwid-5.2.1}/urwid/log_handler.py +36 -4
  13. {urwid-5.2.0 → urwid-5.2.1}/urwid/version.py +3 -3
  14. {urwid-5.2.0 → urwid-5.2.1}/urwid/widget/action_menu.py +31 -5
  15. {urwid-5.2.0 → urwid-5.2.1}/urwid/widget/drop_down.py +31 -7
  16. {urwid-5.2.0 → urwid-5.2.1}/urwid/widget/grid_flow.py +192 -59
  17. {urwid-5.2.0 → urwid-5.2.1}/urwid/widget/terminal_output.py +2 -0
  18. {urwid-5.2.0 → urwid-5.2.1}/urwid.egg-info/PKG-INFO +5 -2
  19. urwid-5.2.1/urwid.egg-info/scm_version.json +8 -0
  20. urwid-5.2.0/urwid.egg-info/scm_version.json +0 -8
  21. {urwid-5.2.0 → urwid-5.2.1}/.devcontainer/dev.dockerfile +0 -0
  22. {urwid-5.2.0 → urwid-5.2.1}/.devcontainer/devcontainer.json +0 -0
  23. {urwid-5.2.0 → urwid-5.2.1}/.devcontainer/docs-pdf/devcontainer.json +0 -0
  24. {urwid-5.2.0 → urwid-5.2.1}/.dockerignore +0 -0
  25. {urwid-5.2.0 → urwid-5.2.1}/.editorconfig +0 -0
  26. {urwid-5.2.0 → urwid-5.2.1}/.github/CODE_OF_CONDUCT.md +0 -0
  27. {urwid-5.2.0 → urwid-5.2.1}/.github/ISSUE_TEMPLATE/bug_report.md +0 -0
  28. {urwid-5.2.0 → urwid-5.2.1}/.github/ISSUE_TEMPLATE/docs.md +0 -0
  29. {urwid-5.2.0 → urwid-5.2.1}/.github/ISSUE_TEMPLATE/feature_request.md +0 -0
  30. {urwid-5.2.0 → urwid-5.2.1}/.github/ISSUE_TEMPLATE/question.md +0 -0
  31. {urwid-5.2.0 → urwid-5.2.1}/.github/PULL_REQUEST_TEMPLATE.md +0 -0
  32. {urwid-5.2.0 → urwid-5.2.1}/.github/dependabot.yml +0 -0
  33. {urwid-5.2.0 → urwid-5.2.1}/.github/labeler.yml +0 -0
  34. {urwid-5.2.0 → urwid-5.2.1}/.github/release.yml +0 -0
  35. {urwid-5.2.0 → urwid-5.2.1}/.github/workflows/documentation-pdf.yml +0 -0
  36. {urwid-5.2.0 → urwid-5.2.1}/.github/workflows/documentation.yml +0 -0
  37. {urwid-5.2.0 → urwid-5.2.1}/.github/workflows/isolated_mypy.yml +0 -0
  38. {urwid-5.2.0 → urwid-5.2.1}/.github/workflows/isolated_pylint.yml +0 -0
  39. {urwid-5.2.0 → urwid-5.2.1}/.github/workflows/isolated_pyrefly.yml +0 -0
  40. {urwid-5.2.0 → urwid-5.2.1}/.github/workflows/labels.yml +0 -0
  41. {urwid-5.2.0 → urwid-5.2.1}/.github/workflows/pythonpackage.yml +0 -0
  42. {urwid-5.2.0 → urwid-5.2.1}/.github/workflows/yamllint.yml +0 -0
  43. {urwid-5.2.0 → urwid-5.2.1}/.gitignore +0 -0
  44. {urwid-5.2.0 → urwid-5.2.1}/.pre-commit-config.yaml +0 -0
  45. {urwid-5.2.0 → urwid-5.2.1}/.yamllint.yml +0 -0
  46. {urwid-5.2.0 → urwid-5.2.1}/COPYING +0 -0
  47. {urwid-5.2.0 → urwid-5.2.1}/MANIFEST.in +0 -0
  48. {urwid-5.2.0 → urwid-5.2.1}/SECURITY.md +0 -0
  49. {urwid-5.2.0 → urwid-5.2.1}/classifiers.txt +0 -0
  50. {urwid-5.2.0 → urwid-5.2.1}/conftest.py +0 -0
  51. {urwid-5.2.0 → urwid-5.2.1}/mypy-requirements.txt +0 -0
  52. {urwid-5.2.0 → urwid-5.2.1}/pylint-requirements.txt +0 -0
  53. {urwid-5.2.0 → urwid-5.2.1}/pyproject.toml +0 -0
  54. {urwid-5.2.0 → urwid-5.2.1}/pyrefly-requirements.txt +0 -0
  55. {urwid-5.2.0 → urwid-5.2.1}/pytest_requirements.txt +0 -0
  56. {urwid-5.2.0 → urwid-5.2.1}/requirements.txt +0 -0
  57. {urwid-5.2.0 → urwid-5.2.1}/setup.cfg +0 -0
  58. {urwid-5.2.0 → urwid-5.2.1}/tox.ini +0 -0
  59. {urwid-5.2.0 → urwid-5.2.1}/urwid/__init__.py +0 -0
  60. {urwid-5.2.0 → urwid-5.2.1}/urwid/_deprecation.py +0 -0
  61. {urwid-5.2.0 → urwid-5.2.1}/urwid/_selectors.py +0 -0
  62. {urwid-5.2.0 → urwid-5.2.1}/urwid/ansi_parser/__init__.py +0 -0
  63. {urwid-5.2.0 → urwid-5.2.1}/urwid/ansi_parser/_grammar.py +0 -0
  64. {urwid-5.2.0 → urwid-5.2.1}/urwid/ansi_parser/_parser.py +0 -0
  65. {urwid-5.2.0 → urwid-5.2.1}/urwid/ansi_parser/_resolve.py +0 -0
  66. {urwid-5.2.0 → urwid-5.2.1}/urwid/ansi_parser/_results.py +0 -0
  67. {urwid-5.2.0 → urwid-5.2.1}/urwid/ansi_parser/_vt_parser.py +0 -0
  68. {urwid-5.2.0 → urwid-5.2.1}/urwid/canvas/__init__.py +0 -0
  69. {urwid-5.2.0 → urwid-5.2.1}/urwid/canvas/_base.py +0 -0
  70. {urwid-5.2.0 → urwid-5.2.1}/urwid/canvas/_cache.py +0 -0
  71. {urwid-5.2.0 → urwid-5.2.1}/urwid/canvas/_composite.py +0 -0
  72. {urwid-5.2.0 → urwid-5.2.1}/urwid/canvas/_text.py +0 -0
  73. {urwid-5.2.0 → urwid-5.2.1}/urwid/canvas/term/__init__.py +0 -0
  74. {urwid-5.2.0 → urwid-5.2.1}/urwid/canvas/term/_cells.py +0 -0
  75. {urwid-5.2.0 → urwid-5.2.1}/urwid/canvas/term/_editing.py +0 -0
  76. {urwid-5.2.0 → urwid-5.2.1}/urwid/canvas/term/_modes.py +0 -0
  77. {urwid-5.2.0 → urwid-5.2.1}/urwid/canvas/term/_palette.py +0 -0
  78. {urwid-5.2.0 → urwid-5.2.1}/urwid/canvas/term/_screen.py +0 -0
  79. {urwid-5.2.0 → urwid-5.2.1}/urwid/canvas/term/_state.py +0 -0
  80. {urwid-5.2.0 → urwid-5.2.1}/urwid/command_map.py +0 -0
  81. {urwid-5.2.0 → urwid-5.2.1}/urwid/display/__init__.py +0 -0
  82. {urwid-5.2.0 → urwid-5.2.1}/urwid/display/_raw_display_base/__init__.py +0 -0
  83. {urwid-5.2.0 → urwid-5.2.1}/urwid/display/_raw_display_base/_attributes.py +0 -0
  84. {urwid-5.2.0 → urwid-5.2.1}/urwid/display/_raw_display_base/_input.py +0 -0
  85. {urwid-5.2.0 → urwid-5.2.1}/urwid/display/_raw_display_base/_screen.py +0 -0
  86. {urwid-5.2.0 → urwid-5.2.1}/urwid/display/_sgr.py +0 -0
  87. {urwid-5.2.0 → urwid-5.2.1}/urwid/display/_web.css +0 -0
  88. {urwid-5.2.0 → urwid-5.2.1}/urwid/display/_web.js +0 -0
  89. {urwid-5.2.0 → urwid-5.2.1}/urwid/display/_web_common.js +0 -0
  90. {urwid-5.2.0 → urwid-5.2.1}/urwid/display/_web_common.py +0 -0
  91. {urwid-5.2.0 → urwid-5.2.1}/urwid/display/_websocket.css +0 -0
  92. {urwid-5.2.0 → urwid-5.2.1}/urwid/display/_websocket.html +0 -0
  93. {urwid-5.2.0 → urwid-5.2.1}/urwid/display/_websocket.js +0 -0
  94. {urwid-5.2.0 → urwid-5.2.1}/urwid/display/_win32.py +0 -0
  95. {urwid-5.2.0 → urwid-5.2.1}/urwid/display/common/__init__.py +0 -0
  96. {urwid-5.2.0 → urwid-5.2.1}/urwid/display/common/_attr_spec.py +0 -0
  97. {urwid-5.2.0 → urwid-5.2.1}/urwid/display/common/_colors.py +0 -0
  98. {urwid-5.2.0 → urwid-5.2.1}/urwid/display/common/_css.py +0 -0
  99. {urwid-5.2.0 → urwid-5.2.1}/urwid/display/common/_depth.py +0 -0
  100. {urwid-5.2.0 → urwid-5.2.1}/urwid/display/common/_screen.py +0 -0
  101. {urwid-5.2.0 → urwid-5.2.1}/urwid/display/curses.py +0 -0
  102. {urwid-5.2.0 → urwid-5.2.1}/urwid/display/escape/__init__.py +0 -0
  103. {urwid-5.2.0 → urwid-5.2.1}/urwid/display/escape/_input.py +0 -0
  104. {urwid-5.2.0 → urwid-5.2.1}/urwid/display/escape/_keys.py +0 -0
  105. {urwid-5.2.0 → urwid-5.2.1}/urwid/display/escape/_mouse.py +0 -0
  106. {urwid-5.2.0 → urwid-5.2.1}/urwid/display/escape/_sequences.py +0 -0
  107. {urwid-5.2.0 → urwid-5.2.1}/urwid/display/escape/_trie.py +0 -0
  108. {urwid-5.2.0 → urwid-5.2.1}/urwid/display/html_fragment.py +0 -0
  109. {urwid-5.2.0 → urwid-5.2.1}/urwid/display/lcd.py +0 -0
  110. {urwid-5.2.0 → urwid-5.2.1}/urwid/display/raw.py +0 -0
  111. {urwid-5.2.0 → urwid-5.2.1}/urwid/display/web.py +0 -0
  112. {urwid-5.2.0 → urwid-5.2.1}/urwid/display/websocket.py +0 -0
  113. {urwid-5.2.0 → urwid-5.2.1}/urwid/event_loop/__init__.py +0 -0
  114. {urwid-5.2.0 → urwid-5.2.1}/urwid/event_loop/abstract_loop.py +0 -0
  115. {urwid-5.2.0 → urwid-5.2.1}/urwid/event_loop/asyncio_loop.py +0 -0
  116. {urwid-5.2.0 → urwid-5.2.1}/urwid/event_loop/glib_loop.py +0 -0
  117. {urwid-5.2.0 → urwid-5.2.1}/urwid/event_loop/guarded_loop.py +0 -0
  118. {urwid-5.2.0 → urwid-5.2.1}/urwid/event_loop/select_loop.py +0 -0
  119. {urwid-5.2.0 → urwid-5.2.1}/urwid/event_loop/tornado_loop.py +0 -0
  120. {urwid-5.2.0 → urwid-5.2.1}/urwid/event_loop/trio_loop.py +0 -0
  121. {urwid-5.2.0 → urwid-5.2.1}/urwid/event_loop/twisted_loop.py +0 -0
  122. {urwid-5.2.0 → urwid-5.2.1}/urwid/event_loop/zmq_loop.py +0 -0
  123. {urwid-5.2.0 → urwid-5.2.1}/urwid/font.py +0 -0
  124. {urwid-5.2.0 → urwid-5.2.1}/urwid/graphics.py +0 -0
  125. {urwid-5.2.0 → urwid-5.2.1}/urwid/numedit.py +0 -0
  126. {urwid-5.2.0 → urwid-5.2.1}/urwid/py.typed +0 -0
  127. {urwid-5.2.0 → urwid-5.2.1}/urwid/signals.py +0 -0
  128. {urwid-5.2.0 → urwid-5.2.1}/urwid/split_repr.py +0 -0
  129. {urwid-5.2.0 → urwid-5.2.1}/urwid/str_util.py +0 -0
  130. {urwid-5.2.0 → urwid-5.2.1}/urwid/testing.py +0 -0
  131. {urwid-5.2.0 → urwid-5.2.1}/urwid/text_layout.py +0 -0
  132. {urwid-5.2.0 → urwid-5.2.1}/urwid/util.py +0 -0
  133. {urwid-5.2.0 → urwid-5.2.1}/urwid/vterm.py +0 -0
  134. {urwid-5.2.0 → urwid-5.2.1}/urwid/widget/__init__.py +0 -0
  135. {urwid-5.2.0 → urwid-5.2.1}/urwid/widget/_pop_up_list.py +0 -0
  136. {urwid-5.2.0 → urwid-5.2.1}/urwid/widget/ansi_text.py +0 -0
  137. {urwid-5.2.0 → urwid-5.2.1}/urwid/widget/attr_map.py +0 -0
  138. {urwid-5.2.0 → urwid-5.2.1}/urwid/widget/attr_wrap.py +0 -0
  139. {urwid-5.2.0 → urwid-5.2.1}/urwid/widget/bar_graph.py +0 -0
  140. {urwid-5.2.0 → urwid-5.2.1}/urwid/widget/big_text.py +0 -0
  141. {urwid-5.2.0 → urwid-5.2.1}/urwid/widget/box_adapter.py +0 -0
  142. {urwid-5.2.0 → urwid-5.2.1}/urwid/widget/columns.py +0 -0
  143. {urwid-5.2.0 → urwid-5.2.1}/urwid/widget/constants.py +0 -0
  144. {urwid-5.2.0 → urwid-5.2.1}/urwid/widget/container.py +0 -0
  145. {urwid-5.2.0 → urwid-5.2.1}/urwid/widget/deque_walker.py +0 -0
  146. {urwid-5.2.0 → urwid-5.2.1}/urwid/widget/divider.py +0 -0
  147. {urwid-5.2.0 → urwid-5.2.1}/urwid/widget/edit.py +0 -0
  148. {urwid-5.2.0 → urwid-5.2.1}/urwid/widget/filler.py +0 -0
  149. {urwid-5.2.0 → urwid-5.2.1}/urwid/widget/filtered_walker.py +0 -0
  150. {urwid-5.2.0 → urwid-5.2.1}/urwid/widget/frame.py +0 -0
  151. {urwid-5.2.0 → urwid-5.2.1}/urwid/widget/line_box.py +0 -0
  152. {urwid-5.2.0 → urwid-5.2.1}/urwid/widget/list_walker.py +0 -0
  153. {urwid-5.2.0 → urwid-5.2.1}/urwid/widget/listbox.py +0 -0
  154. {urwid-5.2.0 → urwid-5.2.1}/urwid/widget/monitored_deque.py +0 -0
  155. {urwid-5.2.0 → urwid-5.2.1}/urwid/widget/monitored_list.py +0 -0
  156. {urwid-5.2.0 → urwid-5.2.1}/urwid/widget/notifications.py +0 -0
  157. {urwid-5.2.0 → urwid-5.2.1}/urwid/widget/overlay.py +0 -0
  158. {urwid-5.2.0 → urwid-5.2.1}/urwid/widget/overlay_stack.py +0 -0
  159. {urwid-5.2.0 → urwid-5.2.1}/urwid/widget/padding.py +0 -0
  160. {urwid-5.2.0 → urwid-5.2.1}/urwid/widget/pile.py +0 -0
  161. {urwid-5.2.0 → urwid-5.2.1}/urwid/widget/popup.py +0 -0
  162. {urwid-5.2.0 → urwid-5.2.1}/urwid/widget/progress_bar.py +0 -0
  163. {urwid-5.2.0 → urwid-5.2.1}/urwid/widget/scrollable.py +0 -0
  164. {urwid-5.2.0 → urwid-5.2.1}/urwid/widget/solid_fill.py +0 -0
  165. {urwid-5.2.0 → urwid-5.2.1}/urwid/widget/spinner.py +0 -0
  166. {urwid-5.2.0 → urwid-5.2.1}/urwid/widget/table.py +0 -0
  167. {urwid-5.2.0 → urwid-5.2.1}/urwid/widget/tabs.py +0 -0
  168. {urwid-5.2.0 → urwid-5.2.1}/urwid/widget/text.py +0 -0
  169. {urwid-5.2.0 → urwid-5.2.1}/urwid/widget/treetools.py +0 -0
  170. {urwid-5.2.0 → urwid-5.2.1}/urwid/widget/widget.py +0 -0
  171. {urwid-5.2.0 → urwid-5.2.1}/urwid/widget/widget_decoration.py +0 -0
  172. {urwid-5.2.0 → urwid-5.2.1}/urwid/widget/wimp.py +0 -0
  173. {urwid-5.2.0 → urwid-5.2.1}/urwid.egg-info/SOURCES.txt +0 -0
  174. {urwid-5.2.0 → urwid-5.2.1}/urwid.egg-info/dependency_links.txt +0 -0
  175. {urwid-5.2.0 → urwid-5.2.1}/urwid.egg-info/not-zip-safe +0 -0
  176. {urwid-5.2.0 → urwid-5.2.1}/urwid.egg-info/requires.txt +0 -0
  177. {urwid-5.2.0 → urwid-5.2.1}/urwid.egg-info/scm_file_list.json +0 -0
  178. {urwid-5.2.0 → urwid-5.2.1}/urwid.egg-info/top_level.txt +0 -0
  179. {urwid-5.2.0 → urwid-5.2.1}/yamllint-requirements.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: urwid
3
- Version: 5.2.0
3
+ Version: 5.2.1
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
@@ -110,10 +110,13 @@ Windows support is limited to the Windows 10+ due to ANSI support requirement.
110
110
 
111
111
  * Not supported:
112
112
 
113
- 1. Terminal widget and all related render API (TermCanvas, TermCharset, TermModes, TermScroller)
113
+ 1. Terminal widget (it runs a child process on a pty)
114
114
  2. Any file descriptors except sockets (Windows OS limitation)
115
115
  3. ZMQEventLoop.
116
116
 
117
+ * Supported, although they belong to the terminal emulation: ``TerminalOutput``, ``TermCanvas``, ``TermCharset`` and
118
+ ``TermModes``.
119
+
117
120
  * Special requirements:
118
121
 
119
122
  1. Extra libraries required for curses display support:
@@ -53,10 +53,13 @@ Windows support is limited to the Windows 10+ due to ANSI support requirement.
53
53
 
54
54
  * Not supported:
55
55
 
56
- 1. Terminal widget and all related render API (TermCanvas, TermCharset, TermModes, TermScroller)
56
+ 1. Terminal widget (it runs a child process on a pty)
57
57
  2. Any file descriptors except sockets (Windows OS limitation)
58
58
  3. ZMQEventLoop.
59
59
 
60
+ * Supported, although they belong to the terminal emulation: ``TerminalOutput``, ``TermCanvas``, ``TermCharset`` and
61
+ ``TermModes``.
62
+
60
63
  * Special requirements:
61
64
 
62
65
  1. Extra libraries required for curses display support:
@@ -331,7 +331,8 @@ class TermCanvas(_ReportsCanvas, _RectanglesCanvas, _ModesCanvas, _VTParser[byte
331
331
  if self._escbuf.startswith(b"?"):
332
332
  if (mode := self._escbuf[1:-1]).isdigit():
333
333
  self.csi_report_private_mode(int(mode))
334
- elif (mode := self._escbuf[:-1]).isdigit():
334
+ elif (mode := self._escbuf[:-1]).isdigit() and self.conformance_level > 62:
335
+ # for an ANSI mode only from the VT300 level (63) on, as in xterm
335
336
  self.csi_report_mode(int(mode))
336
337
  return
337
338
 
@@ -367,8 +368,8 @@ class TermCanvas(_ReportsCanvas, _RectanglesCanvas, _ModesCanvas, _VTParser[byte
367
368
  return
368
369
 
369
370
  if char == b"w" and self._escbuf.endswith(b"$"):
370
- # DECRQPSR: CSI Ps $ w, which a VT100 (level 61) does not answer
371
- if (report := self._escbuf[:-1]).isdigit() and self.conformance_level > 61:
371
+ # DECRQPSR: CSI Ps $ w, answered from the VT300 level (63) on, as in xterm
372
+ if (report := self._escbuf[:-1]).isdigit() and self.conformance_level > 62:
372
373
  self.csi_report_presentation_state(int(report))
373
374
  return
374
375
 
@@ -433,15 +434,19 @@ class TermCanvas(_ReportsCanvas, _RectanglesCanvas, _ModesCanvas, _VTParser[byte
433
434
  # another intermediate byte, such as S7C1T/S8C1T (ESC SP F, ESC SP G): accepted and not applied
434
435
  pass
435
436
  elif char in _GR_LOCKING_SHIFTS:
436
- self.charset.gr = _GR_LOCKING_SHIFTS[char]
437
+ # the G2 and G3 shifts are VT200 functions, which a VT100 (level 61) ignores, as xterm does
438
+ if self.conformance_level > 61:
439
+ self.charset.gr = _GR_LOCKING_SHIFTS[char]
437
440
  elif char == b"6": # DECBI
438
441
  self.back_index()
439
442
  elif char == b"9": # DECFI
440
443
  self.forward_index()
441
444
  elif char in _LOCKING_SHIFTS:
442
- self.charset.activate(_LOCKING_SHIFTS[char])
445
+ if self.conformance_level > 61:
446
+ self.charset.activate(_LOCKING_SHIFTS[char])
443
447
  elif char in _SINGLE_SHIFTS:
444
- self.charset.single_shift(_SINGLE_SHIFTS[char])
448
+ if self.conformance_level > 61:
449
+ self.charset.single_shift(_SINGLE_SHIFTS[char])
445
450
  elif char in {b"=", b">"}: # DECKPAM, DECKPNM
446
451
  self.modes.keypad_application = char == b"="
447
452
  elif char == b"M": # reverse line feed
@@ -574,7 +579,8 @@ class TermCanvas(_ReportsCanvas, _RectanglesCanvas, _ModesCanvas, _VTParser[byte
574
579
  """Apply the DCS string *body*, given without its ``ESC P`` and ST framing.
575
580
 
576
581
  DECRQSS and XTGETTCAP are answered and DECRSPS is applied.
577
- As in xterm, at the VT100 level (61) DECRSPS is not applied, and DECRQSS does not answer the conformance level.
582
+ As in xterm, DECRSPS is applied from the VT300 level (63) on,
583
+ and at the VT100 level (61) DECRQSS does not answer the conformance level.
578
584
  Any other DCS string is ignored.
579
585
  """
580
586
  if body.startswith(b"$q"):
@@ -582,7 +588,8 @@ class TermCanvas(_ReportsCanvas, _RectanglesCanvas, _ModesCanvas, _VTParser[byte
582
588
  self.dcs_request_setting(body[2:])
583
589
  elif body.startswith(b"+q"):
584
590
  self.dcs_request_termcap(body[2:])
585
- elif self.conformance_level == _CONFORMANCE_LEVELS[0]:
591
+ elif self.conformance_level < 63:
592
+ # DECRSPS, from the VT300 level (63) on, as in xterm
586
593
  return
587
594
  elif body.startswith(b"1$t"):
588
595
  self.dcs_restore_cursor_information(body[3:])
@@ -310,7 +310,7 @@ class _RectanglesCanvas(_EditingCanvas):
310
310
  character, valued as one.
311
311
 
312
312
  Without parameters it is not answered, and an empty Pid is 65535, as in xterm.
313
- It is not answered at the VT100 level (61), like the other DCS replies.
313
+ It is not answered at the VT100 level (61).
314
314
  """
315
315
  if self.conformance_level == 61 or params == [None]:
316
316
  return
@@ -263,22 +263,27 @@ class _ReportsCanvas(_EditingCanvas):
263
263
  The reply follows xterm:
264
264
 
265
265
  - the names are answered in order up to the first one that is not answered;
266
- - those answered are listed in one DCS 1 + r Pt ST, Pt holding ``name=value;`` for each, the value hex-encoded
267
- as the name is;
266
+ - those answered are listed in one DCS 1 + r Pt ST, Pt holding ``name=value`` for each, separated by ``;``,
267
+ the value hex-encoded as the name is, and ending with ``;`` when a name after them is not answered;
268
268
  - when the first name is not answered, the reply is DCS 0 + r ST.
269
269
  """
270
270
  values = {"Co": str(_PALETTE_COLORS), "colors": str(_PALETTE_COLORS), "RGB": "8"}
271
- answered = ""
271
+ answered: list[str] = []
272
+ stopped = False
272
273
  for name in names.split(b";"):
273
274
  try:
274
275
  hex_name = name.decode("ascii")
275
276
  key = bytes.fromhex(hex_name).decode("ascii")
276
277
  except ValueError:
277
- break
278
+ key = None
278
279
  if key not in values:
280
+ stopped = True
279
281
  break
280
- answered += f"{hex_name}={values[key].encode('ascii').hex().upper()};"
281
- self.widget.respond(f"{DCS}1+r{answered}{ST}" if answered else f"{DCS}0+r{ST}")
282
+ answered.append(f"{hex_name}={values[key].encode('ascii').hex().upper()}")
283
+ if not answered:
284
+ self.widget.respond(f"{DCS}0+r{ST}")
285
+ return
286
+ self.widget.respond(f"{DCS}1+r{';'.join(answered)}{';' if stopped else ''}{ST}")
282
287
 
283
288
  def dcs_restore_tab_stops(self, body: bytes) -> None:
284
289
  """Set the tab stops to the 1-based columns of a DECTABSR report *body* (DECRSPS 2), separated by ``/``.
@@ -298,17 +303,19 @@ class _ReportsCanvas(_EditingCanvas):
298
303
  """Answer DECRQUPSS (``CSI & u``) with DECAUPSS for ISO Latin-1, ``DCS 1 ! u A ST``.
299
304
 
300
305
  That is the 96-character set a designation such as ``ESC - A`` draws.
301
- It is not answered at the VT100 level (61), like the other DCS replies.
306
+ It is answered from the VT300 level (63) on, as in xterm.
302
307
  """
303
- if self.conformance_level > 61:
308
+ if self.conformance_level > 62:
304
309
  self.widget.respond(f"{DCS}1!uA{ST}")
305
310
 
306
311
  def csi_report_displayed_extent(self, _params: Sequence[int | None]) -> None:
307
312
  """Answer DECRQDE (``CSI " v``) with DECRPDE.
308
313
 
309
314
  The reply is the height and the width, and column, row and page 1 at the top left.
315
+ It is answered from the VT300 level (63) on, as in xterm.
310
316
  """
311
- self.widget.respond(f'{CSI}{self.height:d};{self.width:d};1;1;1"w')
317
+ if self.conformance_level > 62:
318
+ self.widget.respond(f'{CSI}{self.height:d};{self.width:d};1;1;1"w')
312
319
 
313
320
  def csi_get_device_attributes(self, qmark: bool) -> None:
314
321
  """Report the primary device attributes: a VT220 with ANSI colour."""
@@ -324,8 +331,9 @@ class _ReportsCanvas(_EditingCanvas):
324
331
  - 6, the cursor position report, with the row and the column counted from the top and left margins in
325
332
  origin mode, as CUP takes them.
326
333
  :param private: the DEC form, ``CSI ? Ps n``, was sent.
327
- Its cursor position report (DECXCPR) adds page 1, and it also answers 15 (no printer), 25 (user-defined
328
- keys unlocked) and 26 (a North American keyboard, ready, an LK201).
334
+ Its cursor position report (DECXCPR) adds page 1 from the VT300 level (63) on.
335
+ It also answers 15 (no printer), 25 (user-defined keys unlocked)
336
+ and 26 (a North American keyboard, ready, an LK201).
329
337
  """
330
338
  prefix = "?" if private else ""
331
339
  if mode == 5:
@@ -335,7 +343,8 @@ class _ReportsCanvas(_EditingCanvas):
335
343
  if self.modes.constrain_scrolling:
336
344
  x -= self.margin_left
337
345
  y -= self.scrollregion_start
338
- self.widget.respond(f"{CSI}{prefix}{y + 1:d};{x + 1:d}{';1' if private else ''}R")
346
+ page = ";1" if private and self.conformance_level > 62 else ""
347
+ self.widget.respond(f"{CSI}{prefix}{y + 1:d};{x + 1:d}{page}R")
339
348
  elif private and mode in _PRIVATE_STATUS_REPORTS:
340
349
  self.widget.respond(f"{CSI}?{_PRIVATE_STATUS_REPORTS[mode]}n")
341
350
 
@@ -141,7 +141,7 @@ class Screen(_raw_display_base.Screen):
141
141
  and the state the terminal reported is set back when it stops; without a report the mode stays as set.
142
142
  :param underline_styles: draw the underline styles and the underline colors of the display attributes;
143
143
  without them an underline is drawn single and in the text color.
144
- None (default) detects them by the terminfo entry of ``TERM`` and by the terminal's environment variables,
144
+ None (default) detects them by the terminfo entry of ``TERM``,
145
145
  and turns them on when the terminal's reply to a capability or version query shows them;
146
146
  pass True/False to force it.
147
147
 
@@ -433,9 +433,7 @@ class Screen(_raw_display_base.Screen):
433
433
  # and raising here would hide the error that ended the run, such as the closed input.
434
434
  if exc.errno not in {errno.EIO, errno.ENXIO, errno.EPIPE}:
435
435
  raise
436
- # _stop_mouse_restore_buffer() did not clear the flag; a later start that fails before clearing it
437
- # draws nothing either
438
- self._start_complete = False
436
+ self._forget_stop_state()
439
437
  finally:
440
438
  # a failed write skips the step of _mouse_tracking() that stops the helper
441
439
  self._stop_gpm_tracking()
@@ -314,7 +314,7 @@ class _ScreenBase(BaseScreen, RealTerminal):
314
314
  and the state the terminal reported is set back when it stops; without a report the mode stays as set.
315
315
  :param underline_styles: draw the underline styles and the underline colors of the display attributes;
316
316
  without them an underline is drawn single and in the text color.
317
- None (default) detects them by the terminfo entry of ``TERM`` and by the terminal's environment variables,
317
+ None (default) detects them by the terminfo entry of ``TERM``,
318
318
  and turns them on when the terminal's reply to a capability or version query shows them;
319
319
  pass True/False to force it.
320
320
  """
@@ -49,6 +49,7 @@ _ColorCount = typing.Literal[1, 16, 88, 256, 16777216]
49
49
  _INDEPENDENT_BRIGHT_FAMILIES = frozenset(
50
50
  {
51
51
  "alacritty",
52
+ "conemu",
52
53
  "cygwin",
53
54
  "eterm",
54
55
  "foot",
@@ -65,6 +66,7 @@ _INDEPENDENT_BRIGHT_FAMILIES = frozenset(
65
66
  "st",
66
67
  "terminator",
67
68
  "tmux",
69
+ "vscode",
68
70
  "vte",
69
71
  "wezterm",
70
72
  "xfce",
@@ -84,34 +86,22 @@ _TRUECOLOR_FAMILIES = frozenset(
84
86
  }
85
87
  )
86
88
  _NO_UNDERLINE_FAMILIES = frozenset({"dumb", "unknown", "vt52"})
89
+ # the TERM families of a multiplexer, which answers the program in place of the terminal around it
90
+ _MULTIPLEXER_FAMILIES = frozenset({"screen", "tmux"})
87
91
  # the terminals that draw every underline style (SGR 4:2 to 4:5) and the underline colour without a terminfo entry
88
- # saying so, by the environment variable holding their version, and the first version that draws them all:
89
- # VTE 0.76, the first with dotted and dashed underlines, and Konsole 22.12
90
- _VTE_UNDERLINE_STYLE_VERSION: typing.Final = 7600
91
- _KONSOLE_UNDERLINE_STYLE_VERSION: typing.Final = 221200
92
- _UNDERLINE_STYLE_VERSIONS: Sequence[tuple[str, int]] = (
93
- ("VTE_VERSION", _VTE_UNDERLINE_STYLE_VERSION),
94
- ("KONSOLE_VERSION", _KONSOLE_UNDERLINE_STYLE_VERSION),
95
- )
96
- # the same first versions by the lower-case TERM_PROGRAM of a terminal that sets TERM_PROGRAM_VERSION;
97
- # iTerm2 also sets LC_TERMINAL and LC_TERMINAL_VERSION, which SSH passes on with the locale
98
- _TERM_PROGRAM_UNDERLINE_STYLE_FLOORS: Mapping[str, tuple[int, ...]] = {
92
+ # saying so, by the lower-case terminal name of their XTVERSION reply, and the first version that draws them all.
93
+ # VTE replies with the number of its VTE_VERSION, and 0.76 is the first with dotted and dashed underlines.
94
+ # The environment variables that name these terminals are not read: a terminal started from inside another one
95
+ # inherits them (Konsole and tmux pass VTE_VERSION on), while the reply comes from the terminal itself.
96
+ _XTVERSION_UNDERLINE_STYLE_FLOORS: Mapping[str, tuple[int, ...]] = {
97
+ "foot": (1, 18, 0),
99
98
  "ghostty": (1, 0, 0),
100
- "iterm.app": (3, 6, 7),
99
+ "iterm2": (3, 6, 7),
100
+ "konsole": (22, 12),
101
101
  "mintty": (3, 1, 5),
102
102
  "rio": (0, 1, 6),
103
- "vscode": (1, 71, 0),
103
+ "vte": (7600,),
104
104
  "wezterm": (20210203, 95643),
105
- }
106
- _ITERM2_UNDERLINE_STYLE_FLOOR: typing.Final = _TERM_PROGRAM_UNDERLINE_STYLE_FLOORS["iterm.app"]
107
- # the same first versions by the lower-case terminal name of an XTVERSION reply; VTE replies with VTE_VERSION's number
108
- # and Konsole with its release, and foot drew the styles from 1.18.0 and xterm.js from 5.0.0
109
- _XTVERSION_UNDERLINE_STYLE_FLOORS: Mapping[str, tuple[int, ...]] = {
110
- **{name: _TERM_PROGRAM_UNDERLINE_STYLE_FLOORS[name] for name in ("ghostty", "mintty", "rio", "wezterm")},
111
- "foot": (1, 18, 0),
112
- "iterm2": _ITERM2_UNDERLINE_STYLE_FLOOR,
113
- "konsole": (_KONSOLE_UNDERLINE_STYLE_VERSION // 10000, _KONSOLE_UNDERLINE_STYLE_VERSION // 100 % 100),
114
- "vte": (_VTE_UNDERLINE_STYLE_VERSION,),
115
105
  "xterm.js": (5, 0, 0),
116
106
  }
117
107
  # the numbers a version starts with, separated by "." or "-", as in "3.6.7" or WezTerm's "20240203-110809-5046fc22"
@@ -125,9 +115,9 @@ _XTVERSION_TEXT = re.compile(r"([A-Za-z][\w.+-]*?)[ (](.*)")
125
115
  _QUERIED_CAPABILITIES: typing.Final = ("colors", "RGB", "Tc", "Smulx", "Setulc")
126
116
  # an RGB value that names the bits per component, as ncurses gives it: one number, or one per component
127
117
  _RGB_BITS: typing.Final = re.compile(r"[1-9][0-9]?(?:/[1-9][0-9]?/[1-9][0-9]?)?", re.ASCII)
128
- # the terminals that draw 24-bit colours and answer neither the rendition probe nor XTGETTCAP, by the lower-case
129
- # name of their XTVERSION reply
130
- _XTVERSION_TRUE_COLOR_TERMINALS: typing.Final = frozenset({"konsole"})
118
+ # the terminals that draw 24-bit colours and show it in no reply to the rendition probe or XTGETTCAP, by the
119
+ # lower-case name of their XTVERSION reply; tmux converts them for the terminal around it
120
+ _XTVERSION_TRUE_COLOR_TERMINALS: typing.Final = frozenset({"konsole", "tmux", "xterm.js"})
131
121
  # the background the rendition probe sets, a 256-colour cube entry the 88-colour palette does not have, as an RGB
132
122
  # value and as that entry
133
123
  _PROBE_RGB: typing.Final = (135, 175, 215)
@@ -141,7 +131,6 @@ _BYTE: typing.Final = re.compile(r"[0-9]{1,3}", re.ASCII)
141
131
  # Windows 10 TH2 (1511) gained 256-color VT; 1703-era build 14931 gained 24-bit color.
142
132
  _WINDOWS_256COLOR_BUILD = 10586
143
133
  _WINDOWS_TRUECOLOR_BUILD = 14931
144
- _TRUECOLOR_TERM_PROGRAMS = frozenset({"hyper", "tabby", "vscode", "vscode-insiders"})
145
134
 
146
135
  # Compiled terminfo entries, as term(5) describes them.
147
136
  # ncurses' built-in search path on common systems, searched after TERMINFO, ~/.terminfo and TERMINFO_DIRS.
@@ -185,8 +174,9 @@ def sends_incomplete_window_size_reports(environ: Mapping[str, str]) -> bool:
185
174
 
186
175
  iTerm2 sets ``LC_TERMINAL`` and ``LC_TERMINAL_VERSION``, and SSH passes them on with the locale.
187
176
  An iTerm2 version that cannot be read counts as such a release.
177
+ Under screen or tmux, as TERM names them, the variables are inherited, and the program talks to the multiplexer.
188
178
  """
189
- if environ.get("LC_TERMINAL") != "iTerm2":
179
+ if environ.get("LC_TERMINAL") != "iTerm2" or _term_families(environ.get("TERM", "")) & _MULTIPLEXER_FAMILIES:
190
180
  return False
191
181
  version = re.match(r"(\d+)\.(\d+)\.(\d+)", environ.get("LC_TERMINAL_VERSION", ""))
192
182
  return version is None or tuple(int(part) for part in version.groups()) < _ITERM2_COMPLETE_WINDOW_SIZE_REPORT
@@ -264,17 +254,6 @@ def _windows_console_colors(version: tuple[int, int, int] | None) -> _ColorCount
264
254
  return 16
265
255
 
266
256
 
267
- def _truecolor_host(environ: Mapping[str, str]) -> bool:
268
- """Hosts that speak 24-bit SGR even when TERM still says xterm-256color."""
269
- if (colorterm := environ.get("COLORTERM")) and colorterm.lower() in {"truecolor", "24bit"}:
270
- return True
271
- if environ.get("WT_SESSION") or environ.get("WT_PROFILE_ID"):
272
- return True
273
- if environ.get("ConEmuANSI", "").lower() in {"on", "1"} or environ.get("ConEmuPID"):
274
- return True
275
- return environ.get("TERM_PROGRAM", "").lower() in _TRUECOLOR_TERM_PROGRAMS
276
-
277
-
278
257
  def _colors_from_term(term: str, families: frozenset[str]) -> _ColorCount:
279
258
  term_l = term.lower()
280
259
  if not term_l:
@@ -448,10 +427,14 @@ def _terminfo_entry(term: str, environ: Mapping[str, str]) -> bytes | None:
448
427
  def _version_reaches(version: str, floor: tuple[int, ...] | None) -> bool:
449
428
  """Return whether *version* is a release at or after *floor*.
450
429
 
451
- A version with a pre-release word after its numbers, such as ``3.6.7beta2`` or ``1.2.0-dev``, counts as before.
430
+ A version with a pre-release word after its numbers, such as ``3.6.7beta2`` or ``1.2.0-dev``, counts as just before
431
+ the release its numbers name, so it reaches only a *floor* below that release.
432
+ VS Code ships pre-releases of xterm.js, such as ``6.1.0-beta.337``.
452
433
 
453
434
  >>> _version_reaches("3.6.7", (3, 6, 7)), _version_reaches("3.6.7beta2", (3, 6, 7))
454
435
  (True, False)
436
+ >>> _version_reaches("6.1.0-beta.337", (5, 0, 0)), _version_reaches("22.12.0-rc1", (22, 12))
437
+ (True, False)
455
438
  >>> _version_reaches("20240203-110809-5046fc22", (20210203, 95643))
456
439
  True
457
440
 
@@ -459,9 +442,14 @@ def _version_reaches(version: str, floor: tuple[int, ...] | None) -> bool:
459
442
  """
460
443
  if floor is None or (match := _VERSION_NUMBERS.match(version)) is None:
461
444
  return False
445
+ numbers = tuple(int(part) for part in re.split(r"[.-]", match.group(1)))
446
+ # missing parts are zeros, so 22.12.0 and 22.12 name the same release
447
+ width = max(len(numbers), len(floor))
448
+ numbers += (0,) * (width - len(numbers))
449
+ floor += (0,) * (width - len(floor))
462
450
  if _PRERELEASE.search(version, match.end()):
463
- return False
464
- return tuple(int(part) for part in re.split(r"[.-]", match.group(1))) >= floor
451
+ return numbers > floor
452
+ return numbers >= floor
465
453
 
466
454
 
467
455
  def _underline_styles_from_version(text: str) -> bool:
@@ -627,14 +615,15 @@ def detect_term_colors(
627
615
 
628
616
  - ``NO_COLOR``, then ``FORCE_COLOR`` / ``CLICOLOR_FORCE``, then ``CLICOLOR=0``.
629
617
  - A monochrome TERM such as ``dumb``.
630
- - A 24-bit host: ``COLORTERM=truecolor``, Windows Terminal, ConEmu, VS Code, or Windows 10 from build 14931.
631
- - Any other ``COLORTERM``, which means at least 256 colours.
618
+ - Windows 10 from build 14931, which has 24-bit colours.
632
619
  - The Windows 10 console from build 10586, which has 256 colours.
633
620
  - TERM itself.
634
621
 
635
622
  TERM gives a count by its name, matched by family so ``gnome-256color``, ``konsole-direct``
636
623
  and ``rxvt-unicode-256color`` are recognized.
637
624
  The ``colors`` capability of its terminfo entry raises that count and never lowers it.
625
+ Variables that name a terminal, such as ``COLORTERM`` or ``WT_SESSION``, are not read: a terminal or multiplexer
626
+ started inside another one inherits them. The raw screen raises the count from the terminal's own replies instead.
638
627
  The entry is searched in the ``TERMINFO``, ``$HOME/.terminfo`` and ``TERMINFO_DIRS`` directories of *environ*,
639
628
  then in the system terminfo directories; native Windows has no terminfo lookup.
640
629
 
@@ -659,11 +648,7 @@ def detect_term_colors(
659
648
  if term_colors == 1:
660
649
  return 1
661
650
  win_colors = _windows_console_colors(_windows_version() if windows_version is None else windows_version)
662
- if _truecolor_host(env) or win_colors == 16777216:
663
- return 16777216
664
- # Any other COLORTERM, or the Windows console, sets the minimum.
665
- minimum: _ColorCount = 256 if env.get("COLORTERM") else win_colors or 1
666
- return max(term_colors, minimum)
651
+ return max(term_colors, win_colors or 1)
667
652
 
668
653
 
669
654
  def detect_terminal_properties(
@@ -672,14 +657,13 @@ def detect_terminal_properties(
672
657
  *,
673
658
  windows_version: tuple[int, int, int] | None = None,
674
659
  ) -> TerminalProperties:
675
- """Detect raw-display capabilities from TERM and standard colour environment variables.
660
+ """Detect raw-display capabilities from TERM, its terminfo entry and the colour settings in the environment.
676
661
 
677
662
  The colour count comes from :func:`detect_term_colors`.
678
663
  TERM names are matched by family, so ``screen.xterm-256color`` is treated as both screen and xterm.
679
664
 
680
- On Windows 10 and later the console VT host is used when TERM is empty or generic.
681
- Windows Terminal (``WT_SESSION``), ConEmu and VS Code's terminal are treated as VT hosts even
682
- when TERM still reports ``xterm-256color``.
665
+ On Windows 10 from build 10586 the console VT host draws bright colours without bold and draws underlines,
666
+ under any TERM but the Linux console's.
683
667
  """
684
668
  env = os.environ if environ is None else environ
685
669
  term_value = env.get("TERM", "") if term is None else term
@@ -688,11 +672,12 @@ def detect_terminal_properties(
688
672
  if windows_version is None:
689
673
  windows_version = _windows_version()
690
674
  win_colors = _windows_console_colors(windows_version)
691
- vt_host = _truecolor_host(env) or win_colors in {256, 16777216}
675
+ vt_host = win_colors in {256, 16777216}
692
676
 
693
677
  has_underline = not bool(families & _NO_UNDERLINE_FAMILIES)
694
678
  linux_console = _is_linux_console(term_value)
695
- fg_bright_is_bold = not bool(families & _INDEPENDENT_BRIGHT_FAMILIES)
679
+ # ms-terminal is Windows Terminal; the other ms-* entries name older Microsoft consoles, most with 8 colours
680
+ fg_bright_is_bold = not (families & _INDEPENDENT_BRIGHT_FAMILIES or term_l.startswith("ms-terminal"))
696
681
  if vt_host and not linux_console:
697
682
  fg_bright_is_bold = False
698
683
  has_underline = True
@@ -705,35 +690,15 @@ def detect_terminal_properties(
705
690
  fg_bright_is_bold=fg_bright_is_bold,
706
691
  bg_bright_is_blink=bg_bright_is_blink,
707
692
  back_color_erase=back_color_erase,
708
- underline_styles=_has_underline_styles(term_value, env, families),
693
+ underline_styles=_has_underline_styles(term_value, env),
709
694
  )
710
695
 
711
696
 
712
- def _has_underline_styles(term: str, environ: Mapping[str, str], families: frozenset[str]) -> bool:
713
- """Return whether the terminal draws underline styles (SGR 4:2 to 4:5) and underline colors (SGR 58).
697
+ def _has_underline_styles(term: str, environ: Mapping[str, str]) -> bool:
698
+ """Return whether the terminfo entry of *term* says the terminal draws underline styles and underline colors.
714
699
 
715
- It does when the terminfo entry of *term* has ``Smulx`` or ``Setulc``, or when the environment names a terminal
716
- version known to draw them.
717
- Under screen or tmux, *families* of *term*, the outer terminal's variables are not taken, since the multiplexer
718
- decides what reaches the terminal.
700
+ The styles are SGR 4:2 to 4:5 and the colors SGR 58; the entry says so with ``Smulx`` or ``Setulc``.
719
701
  """
720
- if not families & {"screen", "tmux"}:
721
- for name, first in _UNDERLINE_STYLE_VERSIONS:
722
- # isdigit() alone accepts digits that int() rejects, such as "²"
723
- value = environ.get(name, "")
724
- if value.isascii() and value.isdigit() and len(value) <= 9 and int(value) >= first:
725
- return True
726
- program = environ.get("TERM_PROGRAM", "").lower()
727
- if _version_reaches(
728
- environ.get("TERM_PROGRAM_VERSION", ""),
729
- _TERM_PROGRAM_UNDERLINE_STYLE_FLOORS.get(program),
730
- ):
731
- return True
732
- if environ.get("LC_TERMINAL") == "iTerm2" and _version_reaches(
733
- environ.get("LC_TERMINAL_VERSION", ""),
734
- _ITERM2_UNDERLINE_STYLE_FLOOR,
735
- ):
736
- return True
737
702
  if (data := _terminfo_entry(term, environ)) is None:
738
703
  return False
739
704
  try:
@@ -477,6 +477,24 @@ class _ModesScreen(_AttributesScreen): # pylint: disable=abstract-method # a p
477
477
  # start can reset the character sets, so G1 is designated again then
478
478
  self._setup_G1_done = False
479
479
 
480
+ def _forget_stop_state(self) -> None:
481
+ """Clear the state the stop steps clear, for a stop whose output failed before they all ran.
482
+
483
+ A later stop then writes nothing for the run that ended, and a later start begins as after a full stop.
484
+ A step added to the stop clears its state here too.
485
+ """
486
+ self._in_band_resize = False
487
+ self._alternate_scroll_written = False
488
+ self._keyboard_protocol_enabled = None
489
+ self._keyboard_query_pending = False
490
+ self._capability_query_pending = False
491
+ self._color_probe = _ColorProbe.FINISHED
492
+ self._modified_palette_entries.clear()
493
+ self._title_saved = False
494
+ self._alternate_buffer = False
495
+ self._start_complete = False
496
+ self._setup_G1_done = False
497
+
480
498
  def _stop_restore_palette(self) -> None:
481
499
  """Reset any palette entries modify_terminal_palette() changed this session.
482
500
 
@@ -97,7 +97,7 @@ class Screen(_raw_display_base.Screen):
97
97
  and the state the terminal reported is set back when it stops; without a report the mode stays as set.
98
98
  :param underline_styles: draw the underline styles and the underline colors of the display attributes;
99
99
  without them an underline is drawn single and in the text color.
100
- None (default) detects them by the terminfo entry of ``TERM`` and by the terminal's environment variables,
100
+ None (default) detects them by the terminfo entry of ``TERM``,
101
101
  and turns them on when the terminal's reply to a capability or version query shows them;
102
102
  pass True/False to force it.
103
103
  """
@@ -34,6 +34,7 @@ import math
34
34
  import os
35
35
  import socket
36
36
  import sys
37
+ import threading
37
38
  import time
38
39
  import typing
39
40
  import weakref
@@ -118,12 +119,13 @@ class _Activation:
118
119
  Ending an entry clears :attr:`loop`, which ends it in all of those contexts at once and releases the loop.
119
120
  """
120
121
 
121
- __slots__ = ("__weakref__", "loop", "previous", "running")
122
+ __slots__ = ("__weakref__", "loop", "previous", "running", "thread")
122
123
 
123
124
  def __init__(self, loop: MainLoop, *, running: bool, previous: _Activation | None = None) -> None:
124
125
  self.loop: MainLoop | None = loop # None once the entry ended: lookups skip it
125
126
  self.running: typing.Final = running # False: a mask, which hides every entry below it
126
127
  self.previous = previous # the start entry of the same loop that this one is nested in
128
+ self.thread: typing.Final = threading.current_thread() # the thread that pushed it
127
129
 
128
130
 
129
131
  class _ThreadCall:
@@ -186,6 +188,18 @@ def get_running_loop_or_none() -> MainLoop | None:
186
188
  return None
187
189
 
188
190
 
191
+ def _get_running_loop_of_this_thread() -> MainLoop | None:
192
+ """Return the loop :func:`get_running_loop_or_none` finds, when the current thread started it or runs its callback.
193
+
194
+ A thread that only runs in a copy of the loop's context, such as every thread started from a loop callback on a
195
+ free-threaded build, gets ``None``.
196
+ """
197
+ if (loop := get_running_loop_or_none()) is None:
198
+ return None
199
+ thread = threading.current_thread()
200
+ return loop if any(entry.loop is loop and entry.thread is thread for entry in _running.get()) else None
201
+
202
+
189
203
  def get_running_loop() -> MainLoop:
190
204
  """Return the :class:`MainLoop` running in the current thread or task.
191
205
 
@@ -29,6 +29,7 @@ import typing
29
29
  from collections.abc import Hashable
30
30
 
31
31
  from urwid.event_loop import ExitMainLoop, get_running_loop_or_none
32
+ from urwid.event_loop.main_loop import _get_running_loop_of_this_thread
32
33
  from urwid.widget.constants import Severity
33
34
  from urwid.widget.notifications import Notifications, _Unset
34
35
  from urwid.widget.text import Text
@@ -92,12 +93,13 @@ class _LoopHandler(logging.Handler):
92
93
  so a sustained flood shows up to :data:`_ENTRIES_PER_DRAIN` times that limit before input is served again.
93
94
 
94
95
  Records held while the loop does not run are shown after :meth:`resume`, which starts each run.
95
- The widget is changed by :meth:`_drain` only, so on the loop thread only.
96
+ :meth:`flush` shows the queued entries at once, from the loop thread.
97
+ The widget is changed by :meth:`_drain` and :meth:`flush` only, so on the loop thread only.
96
98
 
97
99
  State, read and written under the handler lock:
98
100
 
99
101
  - ``_scheduled``: a :meth:`_drain` call was handed to the loop and has not started.
100
- - ``_draining``: a :meth:`_drain` call is running.
102
+ - ``_draining``: a :meth:`_drain` or :meth:`flush` call is showing entries.
101
103
  - ``_shut``: :meth:`close` was called.
102
104
  """
103
105
 
@@ -185,13 +187,43 @@ class _LoopHandler(logging.Handler):
185
187
  :exc:`~urwid.ExitMainLoop` from the widget propagates.
186
188
  Any other exception is logged and the next entry is shown.
187
189
  """
190
+ self._deliver(drain=True)
191
+
192
+ def flush(self) -> None:
193
+ """Show the records queued now in the widget.
194
+
195
+ Call it on the loop thread while the loop runs, for example before a widget callback stops the loop or
196
+ reads the widget, so the widget shows every record logged before the call, without waiting for the loop to
197
+ hand them over.
198
+ Records logged while it shows them, such as by the widget, wait for the next hand-over;
199
+ when they fill ``max_pending``, the oldest queued records are dropped as usual.
200
+ On any other thread, also one that runs in a copy of the loop's context, and after :meth:`close`,
201
+ it does nothing and the records stay queued.
202
+ A call from a widget callback during a hand-over shows nothing, and leaves the rest to that hand-over.
203
+ Any exception from the widget other than :exc:`~urwid.ExitMainLoop` is logged and the next entry is shown.
204
+
205
+ :raises ~urwid.ExitMainLoop: the widget stopped the loop.
206
+ """
207
+ if _get_running_loop_of_this_thread() is self.loop:
208
+ self._deliver(drain=False)
209
+
210
+ def _deliver(self, *, drain: bool) -> None:
211
+ """Show queued entries, oldest first, and hand the loop a call for the rest.
212
+
213
+ A hand-over (*drain* true) shows up to :data:`_ENTRIES_PER_DRAIN` entries,
214
+ otherwise every entry queued at the call.
215
+ Showing stops before the next entry once the loop is no longer the running loop, and after :meth:`close`.
216
+ Call it on the loop thread only.
217
+ """
188
218
  with self._lock:
189
- self._scheduled = False
219
+ if drain:
220
+ self._scheduled = False
190
221
  if self._draining:
191
222
  return
192
223
  self._draining = True
224
+ count = _ENTRIES_PER_DRAIN if drain else len(self._pending)
193
225
  try:
194
- for _ in range(_ENTRIES_PER_DRAIN):
226
+ for _ in range(count):
195
227
  if get_running_loop_or_none() is not self.loop:
196
228
  break
197
229
  with self._lock:
@@ -18,7 +18,7 @@ version_tuple: tuple[int | str, ...]
18
18
  commit_id: str | None
19
19
  __commit_id__: str | None
20
20
 
21
- __version__ = version = '5.2.0'
22
- __version_tuple__ = version_tuple = (5, 2, 0)
21
+ __version__ = version = '5.2.1'
22
+ __version_tuple__ = version_tuple = (5, 2, 1)
23
23
 
24
- __commit_id__ = commit_id = 'gfb1f26904'
24
+ __commit_id__ = commit_id = 'g8d7ed1f26'