ratatui_ruby 1.1.0 → 1.1.1

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 (259) hide show
  1. checksums.yaml +4 -4
  2. data/ext/ratatui_ruby/Cargo.lock +1 -1
  3. data/ext/ratatui_ruby/Cargo.toml +1 -1
  4. data/lib/ratatui_ruby/version.rb +1 -1
  5. metadata +1 -255
  6. data/.builds/ruby-3.2.yml +0 -54
  7. data/.builds/ruby-3.3.yml +0 -54
  8. data/.builds/ruby-3.4.yml +0 -54
  9. data/.builds/ruby-4.0.0.yml +0 -54
  10. data/.pre-commit-config.yaml +0 -16
  11. data/.rubocop.yml +0 -10
  12. data/AGENTS.md +0 -147
  13. data/CHANGELOG.md +0 -736
  14. data/README.md +0 -187
  15. data/README.rdoc +0 -302
  16. data/Rakefile +0 -11
  17. data/Steepfile +0 -50
  18. data/doc/concepts/application_architecture.md +0 -321
  19. data/doc/concepts/application_testing.md +0 -193
  20. data/doc/concepts/async.md +0 -190
  21. data/doc/concepts/custom_widgets.md +0 -247
  22. data/doc/concepts/debugging.md +0 -401
  23. data/doc/concepts/event_handling.md +0 -162
  24. data/doc/concepts/interactive_design.md +0 -146
  25. data/doc/contributors/auditing/parity.md +0 -239
  26. data/doc/contributors/design/ruby_frontend.md +0 -448
  27. data/doc/contributors/design/rust_backend.md +0 -434
  28. data/doc/contributors/design.md +0 -11
  29. data/doc/contributors/developing_examples.md +0 -400
  30. data/doc/contributors/documentation_style.md +0 -121
  31. data/doc/contributors/index.md +0 -21
  32. data/doc/contributors/releasing.md +0 -215
  33. data/doc/contributors/todo/align/api_completeness_audit-finished.md +0 -381
  34. data/doc/contributors/todo/align/api_completeness_audit-unfinished.md +0 -200
  35. data/doc/contributors/todo/align/term.md +0 -351
  36. data/doc/contributors/todo/align/terminal.md +0 -647
  37. data/doc/contributors/todo/future_work.md +0 -169
  38. data/doc/contributors/upstream_requests/paragraph_span_rects.md +0 -259
  39. data/doc/contributors/upstream_requests/tab_rects.md +0 -173
  40. data/doc/contributors/upstream_requests/title_rects.md +0 -132
  41. data/doc/custom.css +0 -22
  42. data/doc/getting_started/quickstart.md +0 -291
  43. data/doc/getting_started/why.md +0 -93
  44. data/doc/images/app_all_events.png +0 -0
  45. data/doc/images/app_cli_rich_moments.gif +0 -0
  46. data/doc/images/app_color_picker.png +0 -0
  47. data/doc/images/app_debugging_showcase.gif +0 -0
  48. data/doc/images/app_debugging_showcase.png +0 -0
  49. data/doc/images/app_external_editor.gif +0 -0
  50. data/doc/images/app_login_form.png +0 -0
  51. data/doc/images/app_stateful_interaction.png +0 -0
  52. data/doc/images/verify_quickstart_dsl.png +0 -0
  53. data/doc/images/verify_quickstart_layout.png +0 -0
  54. data/doc/images/verify_quickstart_lifecycle.png +0 -0
  55. data/doc/images/verify_readme_usage.png +0 -0
  56. data/doc/images/widget_barchart.png +0 -0
  57. data/doc/images/widget_block.png +0 -0
  58. data/doc/images/widget_box.png +0 -0
  59. data/doc/images/widget_calendar.png +0 -0
  60. data/doc/images/widget_canvas.png +0 -0
  61. data/doc/images/widget_cell.png +0 -0
  62. data/doc/images/widget_center.png +0 -0
  63. data/doc/images/widget_chart.png +0 -0
  64. data/doc/images/widget_gauge.png +0 -0
  65. data/doc/images/widget_layout_split.png +0 -0
  66. data/doc/images/widget_line_gauge.png +0 -0
  67. data/doc/images/widget_list.png +0 -0
  68. data/doc/images/widget_map.png +0 -0
  69. data/doc/images/widget_overlay.png +0 -0
  70. data/doc/images/widget_popup.png +0 -0
  71. data/doc/images/widget_ratatui_logo.png +0 -0
  72. data/doc/images/widget_ratatui_mascot.png +0 -0
  73. data/doc/images/widget_rect.png +0 -0
  74. data/doc/images/widget_render.png +0 -0
  75. data/doc/images/widget_rich_text.png +0 -0
  76. data/doc/images/widget_scroll_text.png +0 -0
  77. data/doc/images/widget_scrollbar.png +0 -0
  78. data/doc/images/widget_sparkline.png +0 -0
  79. data/doc/images/widget_style_colors.png +0 -0
  80. data/doc/images/widget_table.png +0 -0
  81. data/doc/images/widget_tabs.png +0 -0
  82. data/doc/images/widget_text_width.png +0 -0
  83. data/doc/index.md +0 -34
  84. data/doc/troubleshooting/async.md +0 -4
  85. data/doc/troubleshooting/terminal_limitations.md +0 -131
  86. data/doc/troubleshooting/tui_output.md +0 -197
  87. data/examples/app_all_events/README.md +0 -114
  88. data/examples/app_all_events/app.rb +0 -98
  89. data/examples/app_all_events/model/app_model.rb +0 -159
  90. data/examples/app_all_events/model/event_color_cycle.rb +0 -43
  91. data/examples/app_all_events/model/event_entry.rb +0 -94
  92. data/examples/app_all_events/model/msg.rb +0 -39
  93. data/examples/app_all_events/model/timestamp.rb +0 -56
  94. data/examples/app_all_events/update.rb +0 -75
  95. data/examples/app_all_events/view/app_view.rb +0 -80
  96. data/examples/app_all_events/view/controls_view.rb +0 -54
  97. data/examples/app_all_events/view/counts_view.rb +0 -61
  98. data/examples/app_all_events/view/live_view.rb +0 -72
  99. data/examples/app_all_events/view/log_view.rb +0 -57
  100. data/examples/app_all_events/view.rb +0 -9
  101. data/examples/app_cli_rich_moments/README.md +0 -81
  102. data/examples/app_cli_rich_moments/app.rb +0 -189
  103. data/examples/app_color_picker/README.md +0 -156
  104. data/examples/app_color_picker/app.rb +0 -76
  105. data/examples/app_color_picker/clipboard.rb +0 -86
  106. data/examples/app_color_picker/color.rb +0 -193
  107. data/examples/app_color_picker/controls.rb +0 -92
  108. data/examples/app_color_picker/copy_dialog.rb +0 -168
  109. data/examples/app_color_picker/export_pane.rb +0 -128
  110. data/examples/app_color_picker/harmony.rb +0 -58
  111. data/examples/app_color_picker/input.rb +0 -176
  112. data/examples/app_color_picker/main_container.rb +0 -180
  113. data/examples/app_color_picker/palette.rb +0 -111
  114. data/examples/app_debugging_showcase/README.md +0 -119
  115. data/examples/app_debugging_showcase/app.rb +0 -318
  116. data/examples/app_external_editor/README.md +0 -62
  117. data/examples/app_external_editor/app.rb +0 -344
  118. data/examples/app_login_form/README.md +0 -58
  119. data/examples/app_login_form/app.rb +0 -109
  120. data/examples/app_stateful_interaction/README.md +0 -35
  121. data/examples/app_stateful_interaction/app.rb +0 -328
  122. data/examples/timeout_demo.rb +0 -45
  123. data/examples/verify_quickstart_dsl/README.md +0 -55
  124. data/examples/verify_quickstart_dsl/app.rb +0 -49
  125. data/examples/verify_quickstart_layout/README.md +0 -77
  126. data/examples/verify_quickstart_layout/app.rb +0 -73
  127. data/examples/verify_quickstart_lifecycle/README.md +0 -68
  128. data/examples/verify_quickstart_lifecycle/app.rb +0 -62
  129. data/examples/verify_readme_usage/README.md +0 -49
  130. data/examples/verify_readme_usage/app.rb +0 -42
  131. data/examples/verify_website_managed/README.md +0 -48
  132. data/examples/verify_website_managed/app.rb +0 -36
  133. data/examples/verify_website_menu/README.md +0 -60
  134. data/examples/verify_website_menu/app.rb +0 -84
  135. data/examples/verify_website_spinner/README.md +0 -44
  136. data/examples/verify_website_spinner/app.rb +0 -34
  137. data/examples/widget_barchart/README.md +0 -58
  138. data/examples/widget_barchart/app.rb +0 -240
  139. data/examples/widget_block/README.md +0 -44
  140. data/examples/widget_block/app.rb +0 -258
  141. data/examples/widget_box/README.md +0 -54
  142. data/examples/widget_box/app.rb +0 -255
  143. data/examples/widget_calendar/README.md +0 -48
  144. data/examples/widget_calendar/app.rb +0 -115
  145. data/examples/widget_canvas/README.md +0 -31
  146. data/examples/widget_canvas/app.rb +0 -130
  147. data/examples/widget_cell/README.md +0 -45
  148. data/examples/widget_cell/app.rb +0 -112
  149. data/examples/widget_center/README.md +0 -33
  150. data/examples/widget_center/app.rb +0 -118
  151. data/examples/widget_chart/README.md +0 -50
  152. data/examples/widget_chart/app.rb +0 -220
  153. data/examples/widget_gauge/README.md +0 -50
  154. data/examples/widget_gauge/app.rb +0 -229
  155. data/examples/widget_layout_split/README.md +0 -53
  156. data/examples/widget_layout_split/app.rb +0 -260
  157. data/examples/widget_line_gauge/README.md +0 -50
  158. data/examples/widget_line_gauge/app.rb +0 -219
  159. data/examples/widget_list/README.md +0 -58
  160. data/examples/widget_list/app.rb +0 -382
  161. data/examples/widget_map/README.md +0 -48
  162. data/examples/widget_map/app.rb +0 -95
  163. data/examples/widget_overlay/README.md +0 -45
  164. data/examples/widget_overlay/app.rb +0 -250
  165. data/examples/widget_popup/README.md +0 -45
  166. data/examples/widget_popup/app.rb +0 -106
  167. data/examples/widget_ratatui_logo/README.md +0 -43
  168. data/examples/widget_ratatui_logo/app.rb +0 -104
  169. data/examples/widget_ratatui_mascot/README.md +0 -43
  170. data/examples/widget_ratatui_mascot/app.rb +0 -95
  171. data/examples/widget_rect/README.md +0 -53
  172. data/examples/widget_rect/app.rb +0 -222
  173. data/examples/widget_render/README.md +0 -46
  174. data/examples/widget_render/app.rb +0 -186
  175. data/examples/widget_render/app.rbs +0 -41
  176. data/examples/widget_rich_text/README.md +0 -44
  177. data/examples/widget_rich_text/app.rb +0 -193
  178. data/examples/widget_scroll_text/README.md +0 -46
  179. data/examples/widget_scroll_text/app.rb +0 -109
  180. data/examples/widget_scrollbar/README.md +0 -46
  181. data/examples/widget_scrollbar/app.rb +0 -155
  182. data/examples/widget_sparkline/README.md +0 -51
  183. data/examples/widget_sparkline/app.rb +0 -277
  184. data/examples/widget_style_colors/README.md +0 -43
  185. data/examples/widget_style_colors/app.rb +0 -83
  186. data/examples/widget_table/README.md +0 -57
  187. data/examples/widget_table/app.rb +0 -285
  188. data/examples/widget_tabs/README.md +0 -50
  189. data/examples/widget_tabs/app.rb +0 -183
  190. data/examples/widget_text_width/README.md +0 -44
  191. data/examples/widget_text_width/app.rb +0 -117
  192. data/migrate_to_buffer.rb +0 -145
  193. data/mise.toml +0 -8
  194. data/tasks/autodoc/examples.rb +0 -87
  195. data/tasks/autodoc/member.rb +0 -58
  196. data/tasks/autodoc/name.rb +0 -21
  197. data/tasks/autodoc.rake +0 -21
  198. data/tasks/bump/bump_workflow.rb +0 -49
  199. data/tasks/bump/cargo_lockfile.rb +0 -21
  200. data/tasks/bump/changelog.rb +0 -104
  201. data/tasks/bump/header.rb +0 -32
  202. data/tasks/bump/history.rb +0 -32
  203. data/tasks/bump/links.rb +0 -69
  204. data/tasks/bump/manifest.rb +0 -33
  205. data/tasks/bump/patch_release.rb +0 -19
  206. data/tasks/bump/release_branch.rb +0 -17
  207. data/tasks/bump/release_from_trunk.rb +0 -49
  208. data/tasks/bump/repository.rb +0 -54
  209. data/tasks/bump/ruby_gem.rb +0 -29
  210. data/tasks/bump/sem_ver.rb +0 -44
  211. data/tasks/bump/unreleased_section.rb +0 -73
  212. data/tasks/bump.rake +0 -61
  213. data/tasks/doc/documentation.rb +0 -59
  214. data/tasks/doc/link/file_url.rb +0 -30
  215. data/tasks/doc/link/relative_path.rb +0 -61
  216. data/tasks/doc/link/web_url.rb +0 -55
  217. data/tasks/doc/link.rb +0 -52
  218. data/tasks/doc/link_audit.rb +0 -116
  219. data/tasks/doc/problem.rb +0 -40
  220. data/tasks/doc/source_file.rb +0 -93
  221. data/tasks/doc.rake +0 -905
  222. data/tasks/example_viewer.html.erb +0 -172
  223. data/tasks/extension.rake +0 -14
  224. data/tasks/license/headers_md.rb +0 -223
  225. data/tasks/license/headers_rb.rb +0 -210
  226. data/tasks/license/license_utils.rb +0 -130
  227. data/tasks/license/snippets_md.rb +0 -315
  228. data/tasks/license/snippets_rdoc.rb +0 -150
  229. data/tasks/license.rake +0 -91
  230. data/tasks/lint.rake +0 -170
  231. data/tasks/rbs_predicates/predicate_catalog.rb +0 -52
  232. data/tasks/rbs_predicates/predicate_tests.rb +0 -124
  233. data/tasks/rbs_predicates/rbs_signature.rb +0 -63
  234. data/tasks/rbs_predicates.rake +0 -31
  235. data/tasks/rdoc_config.rb +0 -29
  236. data/tasks/resources/build.yml.erb +0 -60
  237. data/tasks/resources/index.html.erb +0 -141
  238. data/tasks/resources/rubies.yml +0 -7
  239. data/tasks/sourcehut.rake +0 -110
  240. data/tasks/steep.rake +0 -11
  241. data/tasks/terminal_preview/app_screenshot.rb +0 -45
  242. data/tasks/terminal_preview/crash_report.rb +0 -54
  243. data/tasks/terminal_preview/example_app.rb +0 -27
  244. data/tasks/terminal_preview/launcher_script.rb +0 -48
  245. data/tasks/terminal_preview/preview_collection.rb +0 -60
  246. data/tasks/terminal_preview/preview_timing.rb +0 -24
  247. data/tasks/terminal_preview/safety_confirmation.rb +0 -58
  248. data/tasks/terminal_preview/saved_screenshot.rb +0 -56
  249. data/tasks/terminal_preview/system_appearance.rb +0 -13
  250. data/tasks/terminal_preview/terminal_window.rb +0 -138
  251. data/tasks/terminal_preview/window_id.rb +0 -16
  252. data/tasks/terminal_preview.rake +0 -30
  253. data/tasks/test.rake +0 -36
  254. data/tasks/website/index_page.rb +0 -30
  255. data/tasks/website/version.rb +0 -122
  256. data/tasks/website/version_menu.rb +0 -68
  257. data/tasks/website/versioned_documentation.rb +0 -83
  258. data/tasks/website/website.rb +0 -53
  259. data/tasks/website.rake +0 -28
data/doc/index.md DELETED
@@ -1,34 +0,0 @@
1
- <!--
2
- SPDX-FileCopyrightText: 2026 Kerrick Long <me@kerricklong.com>
3
- SPDX-License-Identifier: CC-BY-SA-4.0
4
- -->
5
- # Start Here
6
-
7
-
8
- ## Documentation for Users
9
-
10
- - [README](../README.md): Project overview and installation
11
-
12
- ### Getting Started
13
-
14
- - [Why RatatuiRuby?](./getting_started/why.md): Philosophy, comparisons, and what makes us different
15
- - [Quickstart](./getting_started/quickstart.md): Build your first TUI app
16
-
17
- ### Concepts
18
-
19
- - [Application Architecture](./concepts/application_architecture.md): Lifecycle patterns and API choices
20
- - [Event Handling](./concepts/event_handling.md): Keyboard, mouse, and terminal events
21
- - [Interactive Design](./concepts/interactive_design.md): Cached layout pattern for hit testing
22
- - [Testing Your Application](./concepts/application_testing.md): Snapshot testing and style assertions
23
- - [Custom Widgets](./concepts/custom_widgets.md): Build anything with the Draw API
24
- - [Async Operations](./concepts/async.md): Background tasks and non-blocking I/O
25
-
26
- ### Troubleshooting
27
-
28
- - [Debugging](./concepts/debugging.md): Debugging techniques and tools
29
- - [Terminal Limitations](./troubleshooting/terminal_limitations.md): Platform quirks and workarounds
30
-
31
- ## Documentation for Contributors
32
-
33
- - [Contributing Guidelines](https://man.sr.ht/~kerrick/ratatui_ruby/contributing.md): How to contribute patches and features
34
- - [More Documentation for Contributors](./contributors/index.md): Internal design docs and style guides
@@ -1,4 +0,0 @@
1
- <!--
2
- SPDX-FileCopyrightText: 2026 Kerrick Long <me@kerricklong.com>
3
- SPDX-License-Identifier: CC-BY-SA-4.0
4
- -->
@@ -1,131 +0,0 @@
1
- <!--
2
- SPDX-FileCopyrightText: 2026 Kerrick Long <me@kerricklong.com>
3
- SPDX-License-Identifier: CC-BY-SA-4.0
4
- -->
5
-
6
- # Terminal Limitations
7
-
8
- Some behaviors are outside the control of `ratatui_ruby`. This document explains common pitfalls that affect your application or your users, but cannot be fixed in the library.
9
-
10
- ## Keyboard Event Interception
11
-
12
- ### The Problem
13
-
14
- Your application receives a key event, but the modifier flags are missing. You pressed Ctrl+PageUp, but the event shows `code="page_up"` with `modifiers=[]`.
15
-
16
- ### The Cause
17
-
18
- Terminal emulators intercept certain key combinations for their own features. The key press never reaches your application—the terminal consumes it first.
19
-
20
- Common culprits on macOS:
21
-
22
- | Key Combination | Terminal Behavior |
23
- |---------------------|--------------------------------------|
24
- | Ctrl+PageUp/Down | Switch tabs (Terminal.app, iTerm2) |
25
- | Ctrl+Tab | Switch tabs |
26
- | Cmd+T / Cmd+N | New tab / New window |
27
- | Cmd+C / Cmd+V | Copy / Paste (not Ctrl) |
28
-
29
- Linux terminals vary widely. Windows Terminal and ConEmu have their own defaults.
30
-
31
- ### The Solution
32
-
33
- 1. **Test with different terminals.** Kitty, WezTerm, and Alacritty pass more key combinations through to applications by default. If a key works in Kitty but not Terminal.app, the terminal is the issue.
34
-
35
- 2. **Reconfigure your terminal.** Most terminal emulators let you unbind or remap default shortcuts in their settings.
36
-
37
- 3. **Use alternative key bindings.** If your users will run your application in various terminals, design your keybindings to avoid commonly intercepted combinations:
38
- - Use Alt+PageUp instead of Ctrl+PageUp
39
- - Use Ctrl+J/K instead of Ctrl+Up/Down
40
- - Avoid Ctrl+Tab entirely
41
-
42
- 4. **Document requirements.** If your application depends on specific key combinations, document the terminal requirements for your users.
43
-
44
- ### Enhanced Keyboard Protocol
45
-
46
- Some terminals support the [Kitty keyboard protocol](https://sw.kovidgoyal.net/kitty/keyboard-protocol/), which provides unambiguous key event reporting including:
47
-
48
- - Individual modifier key events (LeftShift vs RightShift)
49
- - Media keys (Play, Pause, Volume controls)
50
- - Repeat and release events
51
-
52
- Terminals with full protocol support:
53
- - Kitty
54
- - WezTerm
55
- - Foot
56
- - Alacritty (partial)
57
-
58
- Standard terminals (Terminal.app, iTerm2, GNOME Terminal) do not support the enhanced protocol.
59
-
60
- **RatatuiRuby Status:** The underlying library (crossterm) supports this protocol, but RatatuiRuby does not yet expose a way to enable it. The key code mappings for media keys and individual modifier keys exist, but they will only be received from terminals that enable the protocol by default. This is planned for a future release.
61
-
62
- ## Mouse Event Limitations
63
-
64
- ### The Problem
65
-
66
- Mouse events work in some terminals but not others. Or they work, but only up to certain coordinates.
67
-
68
- ### The Cause
69
-
70
- Mouse reporting requires terminal escape sequence support. Older terminals may not support:
71
-
72
- - SGR mouse mode (coordinates > 223)
73
- - Mouse motion tracking
74
- - Button-event tracking
75
-
76
- ### The Solution
77
-
78
- Ensure your terminal supports modern mouse modes. Most actively maintained terminals do. If running in a legacy environment, test mouse functionality and provide keyboard alternatives.
79
-
80
- ## Focus Events
81
-
82
- ### The Problem
83
-
84
- `Event::FocusGained` and `Event::FocusLost` are never received.
85
-
86
- ### The Cause
87
-
88
- Focus event reporting requires explicit terminal support and configuration. Some terminals don't support it at all.
89
-
90
- ### The Solution
91
-
92
- Don't rely on focus events for critical functionality. Treat them as nice-to-have enhancements. If your application shows stale data when the user returns, periodically refresh instead of waiting for focus events.
93
-
94
- ## Process Termination
95
-
96
- ### The Problem
97
-
98
- Your TUI app is terminated by `kill -9` or the [OOM killer](https://en.wikipedia.org/wiki/Out_of_memory#Out_of_memory_management). The terminal stays in raw mode. The user's cursor vanishes. Input echoes weirdly. Their shell is unusable.
99
-
100
- ### The Cause
101
-
102
- SIGKILL (`kill -9`) terminates processes immediately. No cleanup code runs. The terminal never receives the escape sequences to restore normal mode.
103
-
104
- This also happens when:
105
- - The system OOM killer terminates your process
106
- - A parent process force-kills your app
107
- - A debugger disconnects ungracefully
108
-
109
- ### The Solution
110
-
111
- There's no way to catch SIGKILL. You can only mitigate the impact.
112
-
113
- **Tell your users how to recover.** In your README or troubleshooting docs, explain: if the terminal breaks, type `reset` and press Enter. The characters won't echo, but the command runs.
114
-
115
- **Script graceful shutdowns.** If you write deployment or process management scripts, prefer graceful signals with a timeout before SIGKILL:
116
-
117
- <!-- SPDX-SnippetBegin -->
118
- <!--
119
- SPDX-FileCopyrightText: 2026 Kerrick Long
120
- SPDX-License-Identifier: MIT-0
121
- -->
122
- ```bash
123
- # Graceful first, force if needed
124
- kill -15 $PID
125
- sleep 2
126
- kill -0 $PID 2>/dev/null && kill -9 $PID
127
- ```
128
- <!-- SPDX-SnippetEnd -->
129
-
130
- See [Application Architecture: Signal Handling](../concepts/application_architecture.md#signal-handling) for programmatic cleanup strategies.
131
-
@@ -1,197 +0,0 @@
1
- <!--
2
- SPDX-FileCopyrightText: 2026 Kerrick Long <me@kerricklong.com>
3
- SPDX-License-Identifier: CC-BY-SA-4.0
4
- -->
5
-
6
- # Terminal Output During TUI Sessions
7
-
8
- ## The Problem
9
-
10
- Writing to stdout or stderr during a TUI session **corrupts the display**.
11
-
12
- When your application is running inside `RatatuiRuby.run`, the terminal is in "raw mode" and RatatuiRuby has taken control of the display buffer. Any output via `puts`, `warn`, `p`, `print`, or direct writes to `$stdout`/`$stderr` will:
13
-
14
- 1. **Corrupt the screen layout** - Characters appear in random positions
15
- 2. **Mix with TUI output** - Text interleaves with your widgets unpredictably
16
- 3. **Trigger escape sequence errors** - Partial ANSI codes can break rendering
17
-
18
- ## Why This Happens
19
-
20
- In raw mode:
21
- - The terminal doesn't process newlines or carriage returns normally
22
- - Output bypasses the TUI's controlled buffer
23
- - Cursor position is undefined from the TUI's perspective
24
-
25
- ## Safe Patterns
26
-
27
- ### Use `guard_io` to swallow output from gems
28
-
29
- If you're using a gem that might write to stdout/stderr, wrap its calls:
30
-
31
- <!-- SPDX-SnippetBegin -->
32
- <!--
33
- SPDX-FileCopyrightText: 2026 Kerrick Long
34
- SPDX-License-Identifier: MIT-0
35
- -->
36
- ```ruby
37
- RatatuiRuby.run do |tui|
38
- RatatuiRuby.guard_io do
39
- SomeChattyGem.do_something # Any puts/warn calls are swallowed
40
- end
41
-
42
- # Outside guard_io, you can still debug intentionally:
43
- # Object::STDERR.puts "debug: something" # Escape hatch (corrupts display!)
44
- end
45
- ```
46
- <!-- SPDX-SnippetEnd -->
47
-
48
- ### Defer output until after the TUI exits
49
-
50
- <!-- SPDX-SnippetBegin -->
51
- <!--
52
- SPDX-FileCopyrightText: 2026 Kerrick Long
53
- SPDX-License-Identifier: MIT-0
54
- -->
55
- ```ruby
56
- messages = []
57
-
58
- RatatuiRuby.run do |tui|
59
- # Collect messages instead of printing them
60
- messages << "Something happened"
61
-
62
- # ... TUI logic ...
63
- end
64
-
65
- # Now safe to print
66
- messages.each { |msg| puts msg }
67
- ```
68
- <!-- SPDX-SnippetEnd -->
69
-
70
- ### Use Logger to write to a file
71
-
72
- The `Logger` class from Ruby's standard library is the idiomatic solution:
73
-
74
- <!-- SPDX-SnippetBegin -->
75
- <!--
76
- SPDX-FileCopyrightText: 2026 Kerrick Long
77
- SPDX-License-Identifier: MIT-0
78
- -->
79
- ```ruby
80
- require "logger"
81
- require "tmpdir"
82
-
83
- LOG = Logger.new(File.join(Dir.tmpdir, "my_app.log"))
84
- LOG.level = Logger::DEBUG
85
-
86
- RatatuiRuby.run do |tui|
87
- LOG.info "Application started"
88
- LOG.debug "Processing event: #{event.inspect}"
89
-
90
- # ... TUI logic ...
91
- end
92
- ```
93
- <!-- SPDX-SnippetEnd -->
94
-
95
- ### Display messages in the TUI itself
96
-
97
- <!-- SPDX-SnippetBegin -->
98
- <!--
99
- SPDX-FileCopyrightText: 2026 Kerrick Long
100
- SPDX-License-Identifier: MIT-0
101
- -->
102
- ```ruby
103
- RatatuiRuby.run do |tui|
104
- @status_message = "Something happened"
105
-
106
- tui.draw do |frame|
107
- # Show status in the UI
108
- frame.render_widget(
109
- tui.paragraph(text: @status_message),
110
- status_area
111
- )
112
- end
113
- end
114
- ```
115
- <!-- SPDX-SnippetEnd -->
116
-
117
- ## Library Behavior
118
-
119
- RatatuiRuby automatically defers its own warnings (like experimental feature notices) during TUI sessions. They are queued and printed after `restore_terminal` is called.
120
-
121
- You don't need to do anything special for library warnings—they're handled automatically.
122
-
123
- ## Bypassing guard_io
124
-
125
- If you need to write to stdout/stderr even when `guard_io` is active (e.g., for [pipeline integration](#headless-mode-batchpipelinecli) or IPC), use the original IO constants:
126
-
127
- <!-- SPDX-SnippetBegin -->
128
- <!--
129
- SPDX-FileCopyrightText: 2026 Kerrick Long
130
- SPDX-License-Identifier: MIT-0
131
- -->
132
- ```ruby
133
- RatatuiRuby.guard_io do
134
- SomeChattyGem.do_something # This is swallowed
135
-
136
- # But this gets through:
137
- Object::STDOUT.puts "structured output for downstream tools"
138
- end
139
- ```
140
- <!-- SPDX-SnippetEnd -->
141
-
142
- This works regardless of whether `guard_io` is active. During a TUI session, the display will be corrupted—but the output will reach its destination.
143
-
144
- ## Headless Mode (Batch/Pipeline/CLI)
145
-
146
- If your app supports both TUI and non-TUI modes (e.g., `my_app --no-tui`), call `headless!` at startup to silence `guard_io` warnings:
147
-
148
- <!-- SPDX-SnippetBegin -->
149
- <!--
150
- SPDX-FileCopyrightText: 2026 Kerrick Long
151
- SPDX-License-Identifier: MIT-0
152
- -->
153
- ```ruby
154
- if ARGV.include?("--no-tui")
155
- RatatuiRuby.headless!
156
- # guard_io calls are now silent no-ops
157
- process_batch_work
158
- else
159
- RatatuiRuby.run do |tui|
160
- # TUI mode - guard_io works normally
161
- end
162
- end
163
- ```
164
- <!-- SPDX-SnippetEnd -->
165
-
166
- When headless, `guard_io` becomes a no-op (output flows normally), and calling `run` or `init_terminal` raises an error.
167
-
168
- ## Temporarily Exiting TUI Mode
169
-
170
- Some apps need to temporarily leave TUI mode for user interaction—like lazygit does when opening an external editor for commit messages. Use `restore_terminal` and `init_terminal`:
171
-
172
- <!-- SPDX-SnippetBegin -->
173
- <!--
174
- SPDX-FileCopyrightText: 2026 Kerrick Long
175
- SPDX-License-Identifier: MIT-0
176
- -->
177
- ```ruby
178
- RatatuiRuby.run do |tui|
179
- # ... TUI is active ...
180
-
181
- if user_wants_external_editor
182
- RatatuiRuby.restore_terminal
183
-
184
- # Now in normal terminal mode
185
- system("$EDITOR", filename)
186
- puts "Press Enter to return to the TUI..."
187
- gets
188
-
189
- RatatuiRuby.init_terminal
190
- end
191
-
192
- # ... TUI is active again ...
193
- end
194
- ```
195
- <!-- SPDX-SnippetEnd -->
196
-
197
- This pattern lets you hand control back to the user or spawn external processes that need normal terminal access.
@@ -1,114 +0,0 @@
1
- <!--
2
- SPDX-FileCopyrightText: 2026 Kerrick Long <me@kerricklong.com>
3
- SPDX-License-Identifier: CC-BY-SA-4.0
4
- -->
5
-
6
- # App All Events Example
7
-
8
- [![App All Events](../../doc/images/app_all_events.png)](app.rb)
9
-
10
- This example application captures and visualizes every event supported by `ratatui_ruby`. It serves as a comprehensive reference for event handling and a demonstration of the Model-View-Update architectural pattern.
11
-
12
- ## Architecture: Model-View-Update
13
-
14
- This application demonstrates **unidirectional data flow** inspired by The Elm Architecture. This separation ensures that state management is predictable and easy to test.
15
-
16
- ### 1. Model (`model/app_model.rb`)
17
- A single immutable `Data.define` object holding **all** application state:
18
- * Event log entries
19
- * Focus state
20
- * Window size
21
- * Highlight timestamps
22
- * Color cycle index
23
-
24
- State changes use `.with(...)` to return a new Model instance.
25
-
26
- ### 2. Msg (`model/msg.rb`)
27
- Semantic value objects that decouple raw terminal events from business logic:
28
- * `Msg::Input` — keyboard, mouse, or paste events
29
- * `Msg::Resize` — terminal size changes
30
- * `Msg::Focus` — focus gained/lost
31
- * `Msg::Quit` — exit signal
32
-
33
- ### 3. Update (`update.rb`)
34
- A **pure function** that computes the next state:
35
-
36
- <!-- SPDX-SnippetBegin -->
37
- <!--
38
- SPDX-FileCopyrightText: 2026 Kerrick Long
39
- SPDX-License-Identifier: MIT-0
40
- -->
41
- ```ruby
42
- Update.call(msg, model) -> Model
43
- ```
44
- <!-- SPDX-SnippetEnd -->
45
-
46
- All logic previously in `Events.record` now lives here. The function never mutates, never draws, never performs IO.
47
-
48
- ### 4. View (`view/`)
49
- Pure rendering logic. Views accept the immutable `AppModel` and draw to the screen.
50
- * **`View::App`**: Root view handling high-level layout
51
- * **Sub-views**: `Counts`, `Live`, `Log`, `Controls`
52
-
53
- ### 5. Runtime (`app.rb`)
54
- The MVU loop:
55
-
56
- <!-- SPDX-SnippetBegin -->
57
- <!--
58
- SPDX-FileCopyrightText: 2026 Kerrick Long
59
- SPDX-License-Identifier: MIT-0
60
- -->
61
- ```ruby
62
- loop do
63
- tui.draw { |f| view.call(model, tui, f, f.area) }
64
- msg = map_event_to_msg(tui.poll_event, model)
65
- break if msg.is_a?(Msg::Quit)
66
- model = Update.call(msg, model)
67
- end
68
- ```
69
- <!-- SPDX-SnippetEnd -->
70
-
71
- ## Library Features Showcased
72
-
73
- Reading this code will teach you how to:
74
-
75
- * **Handle All Events**:
76
- * **Keyboard**: Capture normal keys and modifiers (`Ctrl+c`, `q`).
77
- * **Mouse**: track clicks, drags, and scroll events.
78
- * **Focus**: React to the terminal window gaining or losing focus (`FocusGained`/`FocusLost`).
79
- * **Resize**: Dynamically adapt layouts when the terminal size changes.
80
- * **Paste**: Handle bracketed paste events (if supported by the terminal).
81
- * **Layouts**: Use `tui.layout_split` with constraints (`Length`, `Fill`) to create complex, responsive dashboards.
82
- * **Styling**: Apply dynamic styles (bold, colors) based on application state.
83
- * **Structure**: Organize a non-trivial CLI tool into small, single-purpose classes.
84
-
85
- ## What Problems Does This Solve?
86
-
87
- ### "What key code is my terminal sending?"
88
- If you are building an app and your logic isn't catching `Ctrl+Left`, run this app and press the keys. You will see exactly how `ratatui_ruby` parses that input (e.g., is it a `Key` event? What are the modifiers?).
89
-
90
- ### "How do I structure a real app?"
91
- Hello World examples are great, but they don't scale. This example shows how to structure an application that can grow. By using immutable state and pure functions, it solves the problem of "where does my state live and how does it change?"
92
-
93
- ### "How do I test my business logic?"
94
- The `Update` function is pure. You can test it by constructing a `Msg`, calling `Update.call(msg, model)`, and asserting on the returned `Model`. No mocking required.
95
-
96
- ## Comparison: Choosing an Architecture
97
-
98
- Complex applications require structured state habits. `AppAllEvents` and the [Color Picker](../app_color_picker/README.md) demonstrate two different approaches.
99
-
100
- ### The Dashboard Approach (AppAllEvents)
101
-
102
- Dashboards display data. They rarely require complex mouse interaction. Model-View-Update works best here. State is immutable. Logic is pure. Updates are predictable. This simplifies testing.
103
-
104
- Use this pattern for logs, monitors, and data viewers.
105
-
106
- ### The Tool Approach (Color Picker)
107
-
108
- Tools require interaction. Users click buttons and drag sliders. Each UI component needs to know where it exists on screen for hit testing.
109
-
110
- The Color Picker uses a Component-Based pattern. Each component encapsulates its own rendering, state, and event handling. The Container routes events and coordinates cross-component effects.
111
-
112
- Use this pattern for forms, editors, and mouse-driven tools.
113
-
114
- [Read the source code →](app.rb)
@@ -1,98 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- #--
4
- # SPDX-FileCopyrightText: 2026 Kerrick Long <me@kerricklong.com>
5
- # SPDX-License-Identifier: AGPL-3.0-or-later
6
- #++
7
-
8
- $LOAD_PATH.unshift File.expand_path("../../lib", __dir__)
9
- $LOAD_PATH.unshift File.expand_path(__dir__)
10
-
11
- require "ratatui_ruby"
12
- require_relative "model/app_model"
13
- require_relative "model/msg"
14
- require_relative "update"
15
- require_relative "view/app_view"
16
-
17
- # Demonstrates the full range of terminal events supported by RatatuiRuby.
18
- #
19
- # Developers need a comprehensive example to understand how keys, mouse, resize, and focus events behave.
20
- # Testing event handling across different terminal emulators and platforms can be unpredictable.
21
- #
22
- # This application captures and logs every event received from the backend, providing real-time feedback and history.
23
- #
24
- # Use it to verify your terminal's capabilities or as a reference for complex event handling.
25
- #
26
- # === Architecture
27
- #
28
- # This example uses the Model-View-Update pattern:
29
- # - **Model**: Immutable AppModel holds all state
30
- # - **Msg**: Semantic message types decouple events from logic
31
- # - **Update**: Pure function computes next state
32
- # - **View**: Renders Model to screen
33
- #
34
- # === Examples
35
- #
36
- # # Run from the command line:
37
- # # ruby examples/app_all_events/app.rb
38
- #
39
- # app = AppAllEvents.new
40
- # app.run
41
- class AppAllEvents
42
- # List of all event types tracked by this application.
43
- EVENT_TYPES = %i[key mouse resize paste focus none].freeze
44
-
45
- # Creates a new AppAllEvents instance and initializes its view.
46
- def initialize
47
- @view = View::App.new
48
- end
49
-
50
- # Starts the application event loop.
51
- #
52
- # Implements the MVU (Model-View-Update) runtime:
53
- # 1. **View**: Render current model
54
- # 2. **Poll**: Get next event
55
- # 3. **Map**: Convert raw event to semantic Msg
56
- # 4. **Update**: Compute next model
57
- #
58
- # === Example
59
- #
60
- # app.run
61
- def run
62
- RatatuiRuby.run do |tui|
63
- model = AppModel.initial
64
-
65
- loop do
66
- tui.draw { |frame| @view.call(model, tui, frame, frame.area) }
67
-
68
- event = tui.poll_event
69
- msg = map_event_to_msg(event, model)
70
- break if msg.is_a?(Msg::Quit)
71
-
72
- model = Update.call(msg, model)
73
- end
74
- end
75
- end
76
-
77
- private def map_event_to_msg(event, model)
78
- case event
79
- when RatatuiRuby::Event::Key
80
- return Msg::Quit.new if event.code == "q"
81
- return Msg::Quit.new if event.code == "c" && event.modifiers.include?("ctrl")
82
-
83
- Msg::Input.new(event:)
84
- when RatatuiRuby::Event::Resize
85
- Msg::Resize.new(width: event.width, height: event.height, previous_size: model.window_size)
86
- when RatatuiRuby::Event::FocusGained
87
- Msg::Focus.new(gained: true)
88
- when RatatuiRuby::Event::FocusLost
89
- Msg::Focus.new(gained: false)
90
- when RatatuiRuby::Event::None
91
- Msg::NoneEvent.new
92
- else
93
- Msg::Input.new(event:)
94
- end
95
- end
96
- end
97
-
98
- AppAllEvents.new.run if __FILE__ == $PROGRAM_NAME