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
@@ -1,72 +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
- require_relative "../view"
9
-
10
- # Renders a real-time summary of the most recent events.
11
- #
12
- # Users need to see the immediate result of their actions without digging through a log.
13
- # Identifying the specific details of the last key press or mouse move at a glance is difficult.
14
- #
15
- # This component displays a table showing the latest event of each type with its timestamp and description.
16
- #
17
- # Use it to provide instant feedback for user interactions.
18
- #
19
- # === Examples
20
- #
21
- # live_view = View::Live.new
22
- # live_view.call(model, tui, frame, area)
23
- class View::Live
24
- # Renders the live event table to the given area.
25
- #
26
- # [model] AppModel containing event data.
27
- # [tui] RatatuiRuby instance.
28
- # [frame] RatatuiRuby::Frame being rendered.
29
- # [area] RatatuiRuby::Layout::Rect defining the widget's bounds.
30
- #
31
- # === Example
32
- #
33
- # live_view.call(model, tui, frame, area)
34
- def call(model, tui, frame, area)
35
- border_color = model.focused ? :green : :gray
36
- rows = []
37
-
38
- rows << tui.text_line(spans: [
39
- tui.text_span(content: "Type".ljust(9), style: tui.style(fg: :gray, modifiers: [:bold])),
40
- tui.text_span(content: "Time".ljust(10), style: tui.style(fg: :gray, modifiers: [:bold])),
41
- tui.text_span(content: "Description", style: tui.style(fg: :gray, modifiers: [:bold])),
42
- ])
43
-
44
- (AppAllEvents::EVENT_TYPES - [:none]).each do |type|
45
- event_data = model.live_event(type)
46
-
47
- class_str = type.to_s.capitalize
48
- time_str = event_data ? event_data[:time].strftime("%H:%M:%S") : "—"
49
- desc_str = event_data ? event_data[:description] : "—"
50
-
51
- is_lit = model.lit?(type)
52
- row_style = is_lit ? tui.style(fg: :green, modifiers: [:reversed]) : nil
53
-
54
- rows << tui.text_line(spans: [
55
- tui.text_span(content: class_str.ljust(9), style: row_style || tui.style(fg: :cyan)),
56
- tui.text_span(content: time_str.ljust(10), style: row_style || tui.style(fg: :white)),
57
- tui.text_span(content: desc_str, style: row_style),
58
- ])
59
- end
60
-
61
- widget = tui.paragraph(
62
- text: rows,
63
- scroll: [0, 0],
64
- block: tui.block(
65
- title: "Live Display",
66
- borders: [:all],
67
- border_style: tui.style(fg: border_color)
68
- )
69
- )
70
- frame.render_widget(widget, area)
71
- end
72
- end
@@ -1,57 +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
- require_relative "../view"
9
-
10
- # Renders a detailed, scrollable history of application events.
11
- #
12
- # Debugging complex event flows requires a chronological record of raw data.
13
- # Interpreting raw event objects without formatting is difficult and slow.
14
- #
15
- # This component renders event history as a series of formatted, color-coded entries showing raw data.
16
- #
17
- # Use it to provide a detailed audit trail of all terminal interactions.
18
- class View::Log
19
- # Renders the event log widget to the given area.
20
- #
21
- # [model] AppModel containing event data.
22
- # [tui] RatatuiRuby instance.
23
- # [frame] RatatuiRuby::Frame being rendered.
24
- # [area] RatatuiRuby::Layout::Rect defining the widget's bounds.
25
- def call(model, tui, frame, area)
26
- dimmed_style = tui.style(fg: :dark_gray)
27
- border_color = model.focused ? :green : :gray
28
-
29
- visible_entries_count = (area.height - 2) / 2
30
- display_entries = model.visible(visible_entries_count)
31
-
32
- log_lines = []
33
- if model.empty?
34
- log_lines << tui.text_line(spans: [tui.text_span(content: "No events yet...", style: dimmed_style)])
35
- else
36
- display_entries.each do |entry|
37
- entry_style = tui.style(fg: entry.color)
38
- description = entry.description
39
-
40
- log_lines << tui.text_line(spans: [tui.text_span(content: description, style: entry_style)])
41
- log_lines << tui.text_line(spans: [tui.text_span(content: "", style: entry_style)])
42
- end
43
- end
44
-
45
- widget = tui.paragraph(
46
- text: log_lines,
47
- scroll: [0, 0],
48
- wrap: { trim: true },
49
- block: tui.block(
50
- title: "Event Log",
51
- borders: [:all],
52
- border_style: tui.style(fg: border_color)
53
- )
54
- )
55
- frame.render_widget(widget, area)
56
- end
57
- end
@@ -1,9 +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
- module View
9
- end
@@ -1,81 +0,0 @@
1
- <!--
2
- SPDX-FileCopyrightText: 2026 Kerrick Long <me@kerricklong.com>
3
- SPDX-License-Identifier: CC-BY-SA-4.0
4
- -->
5
-
6
- # CLI Rich Moments Example
7
-
8
- [![CLI Rich Moments](../../doc/images/app_cli_rich_moments.gif)](app.rb)
9
-
10
- Demonstrates inline viewport usage for CLI tools that need brief moments of rich interactivity without full-screen commitment.
11
-
12
- ## Context
13
-
14
- CLI applications often need moments of richness—a spinner while connecting, a quick menu selection, or a brief editor. But committing to a full-screen TUI feels wrong when 90% of the app is traditional CLI output.
15
-
16
- ## Problem
17
-
18
- Standard full-screen TUIs (alternate screen) erase themselves on exit. Your carefully formatted CLI output disappears. Users lose their history. The terminal scrollback becomes useless.
19
-
20
- ## Solution
21
-
22
- This example shows how **inline viewports** solve this problem. Inline regions persist in terminal scrollback after exit. You can mix inline and fullscreen viewports across multiple `RatatuiRuby.run` calls in a single application flow.
23
-
24
- ## Flow
25
-
26
- The application demonstrates four distinct phases:
27
-
28
- 1. **1-line inline**: Braille spinner (⠋ ⠙ ⠹ etc.) + "Connecting..." status
29
- 2. **5-line inline**: Radio button menu with up/down/enter navigation
30
- 3. **Fullscreen**: Configuration editor showing legitimate use of alternate screen
31
- 4. **1-line inline**: Braille spinner + "Saving..." confirmation
32
-
33
- After exit, all inline outputs remain visible in terminal history. The fullscreen portion disappears cleanly.
34
-
35
- ## Running
36
-
37
- <!-- SPDX-SnippetBegin -->
38
- <!--
39
- SPDX-FileCopyrightText: 2026 Kerrick Long
40
- SPDX-License-Identifier: MIT-0
41
- -->
42
- ```bash
43
- cd examples/app_cli_rich_moments
44
- ruby app.rb
45
- ```
46
- <!-- SPDX-SnippetEnd -->
47
-
48
- ## Architecture
49
-
50
- Each phase is a separate `RatatuiRuby.run` block with its own viewport configuration. State (like menu selection) must be passed between phases via instance variables.
51
-
52
- **Spinner phases**:
53
- - Use `viewport: :inline, height: 1`
54
- - Animate Braille frames with short delays
55
- - No input handling needed
56
-
57
- **Menu phase**:
58
- - Uses `viewport: :inline, height: 5`
59
- - Handles up/down arrow keys for selection
60
- - Returns selected choice for next phase
61
-
62
- **Editor phase**:
63
- - Uses default fullscreen viewport
64
- - Demonstrates when alternate screen is appropriate
65
- - Full 80×24 available
66
-
67
- ## Key Concepts
68
-
69
- - **Viewport independence**: Each `run` block can use different viewport modes
70
- - **Scrollback persistence**: Inline content remains after exit
71
- - **State management**: Pass data between phases via instance variables
72
- - **Appropriate contexts**: Inline for brief moments, fullscreen for sustained interaction
73
-
74
- ## Learning Outcomes
75
-
76
- After studying this example, you'll understand:
77
-
78
- - When to use inline vs fullscreen viewports
79
- - How to mix viewport modes in a single application
80
- - Why inline viewports improve CLI UX for transient interactions
81
- - How to manage state across multiple `run` blocks
@@ -1,189 +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
- require "ratatui_ruby"
10
-
11
- class AppCliRichMoments
12
- SPINNER_FRAMES = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"].freeze
13
- MENU_OPTIONS = [
14
- "Development Environment",
15
- "Staging Environment",
16
- "Production Environment",
17
- ].freeze
18
-
19
- def initialize
20
- @selected_index = 0
21
- @choice = nil
22
- @tui = RatatuiRuby::TUI.new
23
- end
24
-
25
- def run
26
- phase_connecting
27
- @choice = phase_menu
28
- phase_editor
29
- phase_saving
30
- end
31
-
32
- private def phase_connecting
33
- RatatuiRuby.run(viewport: :inline, height: 1) do
34
- 10.times do |i|
35
- render_spinner(SPINNER_FRAMES[i % SPINNER_FRAMES.length], "Connecting to server...")
36
- sleep 0.1
37
- end
38
-
39
- # Insert success message above viewport into scrollback
40
- status = "✓ Connected to server"
41
- @tui.insert_before(1, @tui.paragraph(text: status, style: @tui.style(fg: :green)))
42
- end
43
- end
44
-
45
- private def phase_menu
46
- RatatuiRuby.run(viewport: :inline, height: 5) do
47
- loop do
48
- render_menu
49
- case handle_menu_input
50
- when :quit, :select
51
- # Position cursor after viewport for next phase
52
- area = @tui.viewport_area
53
-
54
- # # If you wanted to remove the menu from scrollback, you could do:
55
- # @tui.draw { |frame| frame.render_widget(@tui.clear, frame.area) }
56
- # # And move the cursor to avoid extra blank space.
57
- # RatatuiRuby.cursor_position = [0, area.y]
58
-
59
- # But instead, we'll leave it in scrollback for reference.
60
- # Move the cursor to avoid overwriting it.
61
- RatatuiRuby.cursor_position = [0, area.y + area.height]
62
-
63
- return MENU_OPTIONS[@selected_index]
64
- end
65
- end
66
- end
67
- end
68
-
69
- private def phase_editor
70
- RatatuiRuby.run do # Fullscreen by default
71
- loop do
72
- render_editor
73
- break if handle_editor_input == :quit
74
- end
75
- end
76
- end
77
-
78
- private def phase_saving
79
- RatatuiRuby.run(viewport: :inline, height: 1) do
80
- 10.times do |i|
81
- render_spinner(SPINNER_FRAMES[i % SPINNER_FRAMES.length], "Saving configuration...")
82
- sleep 0.1
83
- end
84
-
85
- status = "✓ Configuration saved to #{@choice.downcase.gsub(' ', '_')}.yml"
86
- @tui.insert_before(1, @tui.paragraph(text: status, style: @tui.style(fg: :green)))
87
- end
88
- end
89
-
90
- private def render_spinner(frame, message)
91
- @tui.draw do |f|
92
- text = "#{frame} #{message}"
93
- widget = @tui.paragraph(text:, style: @tui.style(fg: :cyan))
94
- f.render_widget(widget, f.area)
95
- end
96
- end
97
-
98
- private def render_menu
99
- @tui.draw do |f|
100
- lines = MENU_OPTIONS.map.with_index do |option, idx|
101
- prefix = (idx == @selected_index) ? "→ " : " "
102
- style = (idx == @selected_index) ? @tui.style(fg: :cyan, modifiers: [:bold]) : @tui.style(fg: :white)
103
- @tui.text_line(spans: [@tui.text_span(content: "#{prefix}#{option}", style:)])
104
- end
105
-
106
- widget = @tui.paragraph(
107
- text: lines,
108
- block: @tui.block(borders: :all, title: "Select Environment")
109
- )
110
- f.render_widget(widget, f.area)
111
- end
112
- end
113
-
114
- private def render_editor
115
- @tui.draw do |f|
116
- areas = @tui.layout_split(
117
- f.area,
118
- direction: :vertical,
119
- constraints: [
120
- @tui.constraint_fill(1),
121
- @tui.constraint_length(3),
122
- ]
123
- )
124
-
125
- # Main content area
126
- content_text = [
127
- "Editing: #{@choice}",
128
- "",
129
- "# Database Configuration",
130
- "database:",
131
- " adapter: postgresql",
132
- " host: db.example.com",
133
- " port: 5432",
134
- "",
135
- "# Cache Configuration",
136
- "cache:",
137
- " provider: redis",
138
- " ttl: 3600",
139
- ].join("\n")
140
-
141
- content = @tui.paragraph(
142
- text: content_text,
143
- block: @tui.block(borders: :all, title: "Configuration Editor"),
144
- style: @tui.style(fg: :yellow)
145
- )
146
- f.render_widget(content, areas[0])
147
-
148
- # Help panel
149
- help_text = "q: Save and Exit | Ctrl+C: Cancel"
150
- help = @tui.paragraph(
151
- text: help_text,
152
- block: @tui.block(borders: :all),
153
- style: @tui.style(fg: :dark_gray),
154
- alignment: :center
155
- )
156
- f.render_widget(help, areas[1])
157
- end
158
- end
159
-
160
- private def handle_menu_input
161
- case @tui.poll_event
162
- in { type: :key, code: "q" } | { type: :key, code: "c", modifiers: ["ctrl"] }
163
- :quit
164
- in { type: :key, code: "enter" }
165
- :select
166
- in { type: :key, code: "up" }
167
- @selected_index = (@selected_index - 1) % MENU_OPTIONS.length
168
- nil
169
- in { type: :key, code: "down" }
170
- @selected_index = (@selected_index + 1) % MENU_OPTIONS.length
171
- nil
172
- else
173
- nil
174
- end
175
- end
176
-
177
- private def handle_editor_input
178
- case @tui.poll_event
179
- in { type: :key, code: "q" }
180
- :quit # "and save," presumably
181
- in { type: :key, code: "c", modifiers: ["ctrl"] }
182
- :quit
183
- else
184
- nil
185
- end
186
- end
187
- end
188
-
189
- AppCliRichMoments.new.run if __FILE__ == $PROGRAM_NAME
@@ -1,156 +0,0 @@
1
- <!--
2
- SPDX-FileCopyrightText: 2026 Kerrick Long <me@kerricklong.com>
3
- SPDX-License-Identifier: CC-BY-SA-4.0
4
- -->
5
-
6
- # Color Picker Example
7
-
8
- [![Color Picker](../../doc/images/app_color_picker.png)](app.rb)
9
-
10
- This example demonstrates how to build a **Feature-Rich Interactive Application** using `ratatui_ruby`.
11
-
12
- It goes beyond simple widgets to show a complete, real-world architecture for handling:
13
- - **Complex State Management** (Input validation, clipboard interaction)
14
- - **Mouse Interaction & Hit Testing**
15
- - **Dynamic Layouts**
16
- - **Modal Dialogs**
17
-
18
- ## Architecture: Component-Based
19
-
20
- This app uses a **Strict Component-Based Architecture** where every UI element encapsulates its own **Rendering**, **State**, and **Event Handling**.
21
-
22
- ### The Component Contract
23
-
24
- Every component implements this duck-type interface:
25
-
26
- <!-- SPDX-SnippetBegin -->
27
- <!--
28
- SPDX-FileCopyrightText: 2026 Kerrick Long
29
- SPDX-License-Identifier: MIT-0
30
- -->
31
- ```ruby
32
- # Renders the component into the given area
33
- # Caches `area` for hit testing
34
- def render(tui, frame, area)
35
- @area = area
36
- # ... render using frame.render_widget
37
- end
38
-
39
- # Processes events; returns a symbolic signal or nil
40
- def handle_event(event) -> Symbol | nil
41
- # Returns :consumed, :submitted, :copy_requested, etc.
42
- end
43
-
44
- # Optional: time-based updates
45
- def tick
46
- end
47
- ```
48
- <!-- SPDX-SnippetEnd -->
49
-
50
- ### 1. The MainContainer (Orchestrator)
51
-
52
- The `MainContainer` class (`main_container.rb`) owns all child components and orchestrates the UI:
53
-
54
- - **Layout Phase:** Calculates `Rect`s using `tui.layout_split`.
55
- - **Delegation Phase:** Calls `child.render(tui, frame, child_area)` for each component.
56
- - **Event Routing (Chain of Responsibility):** Delegates events front-to-back. The modal dialog gets priority when active.
57
- - **Mediator Pattern:** Interprets symbolic signals (`:submitted`, `:copy_requested`) to coordinate cross-component effects.
58
-
59
- ### 2. Self-Contained Components
60
-
61
- Each UI element is a self-contained component:
62
-
63
- - **`Input`**: Text entry with validation. Returns `:submitted` when Enter is pressed.
64
- - **`Palette`**: Displays color harmonies. Accepts `update_color` from the container.
65
- - **`ExportPane`**: Shows HEX/RGB/HSL formats. Returns `:copy_requested` when clicked.
66
- - **`Controls`**: Displays keyboard shortcuts. Has a `tick` lifecycle for clipboard feedback.
67
- - **`CopyDialog`**: Modal confirmation dialog. Returns `:consumed` when handling events.
68
-
69
- ### 3. The App (Minimal Runner)
70
-
71
- The `App` class (`app.rb`) is a thin runner:
72
- - Creates the `MainContainer`.
73
- - Runs the main loop: `tick` → `render` → `poll` → `handle_event`.
74
- - Checks for quit events.
75
-
76
- ## Key Features Showcased
77
-
78
- ### 🖱️ Encapsulated Hit Testing
79
-
80
- Components cache their render area (`@area`) during `render`. In `handle_event`, they check `@area&.contains?(x, y)` to detect clicks. The container never calculates coordinates—hit testing is fully encapsulated.
81
-
82
- ### 🔲 Modal Dialogs via Chain of Responsibility
83
-
84
- When `CopyDialog` is active, the `MainContainer` offers it events first. If it returns `:consumed`, event propagation stops. This creates modal behavior without explicit flags in the app.
85
-
86
- ### 📡 Symbolic Signals (Mediator Pattern)
87
-
88
- Components return semantic symbols instead of just `:consumed`:
89
- - `Input` returns `:submitted` when the user presses Enter.
90
- - `ExportPane` returns `:copy_requested` when clicked.
91
-
92
- The `MainContainer` interprets these signals to coordinate cross-component communication:
93
-
94
- <!-- SPDX-SnippetBegin -->
95
- <!--
96
- SPDX-FileCopyrightText: 2026 Kerrick Long
97
- SPDX-License-Identifier: MIT-0
98
- -->
99
- ```ruby
100
- result = @input.handle_event(event)
101
- case result
102
- when :submitted
103
- @palette.update_color(@input.parsed_color)
104
- return :consumed
105
- end
106
- ```
107
- <!-- SPDX-SnippetEnd -->
108
-
109
- ### ⏱️ Lifecycle Hooks (`tick`)
110
-
111
- Components can have time-based updates. `Controls#tick` delegates to `Clipboard#tick` to decrement the feedback timer.
112
-
113
- ## Problem Solving: What You Can Learn
114
-
115
- Read this example if you are trying to solve:
116
- 1. **"How do I structure a larger app?"** → Use the Component Contract and a Container for orchestration.
117
- 2. **"How do I handle mouse clicks?"** → Cache `@area` during render; check `contains?` in `handle_event`.
118
- 3. **"How do I make a popup?"** → Use Chain of Responsibility: the active modal gets events first.
119
- 4. **"How do I coordinate between components?"** → Use symbolic signals and the Mediator pattern.
120
- 5. **"How do I validate input?"** → Encapsulate validation inside the `Input` component.
121
-
122
- ## Usage
123
-
124
- <!-- SPDX-SnippetBegin -->
125
- <!--
126
- SPDX-FileCopyrightText: 2026 Kerrick Long
127
- SPDX-License-Identifier: MIT-0
128
- -->
129
- ```bash
130
- ruby examples/app_color_picker/app.rb
131
- ```
132
- <!-- SPDX-SnippetEnd -->
133
-
134
- - Type a hex code (e.g., `#FF0055`) or color name (`cyan`).
135
- - Press `Enter` to generate the palette.
136
- - Click on the **Export Formats** box to copy the hex code.
137
-
138
- ## Comparison: Choosing an Architecture
139
-
140
- Complex applications require structured state habits. This Color Picker and the [App All Events](../app_all_events/README.md) example demonstrate two different approaches.
141
-
142
- ### The Tool Approach (Color Picker)
143
-
144
- Tools require interaction. Users click buttons and drag sliders. Components need to know where they exist on screen for hit testing. The Container orchestrates cross-component effects.
145
-
146
- This example uses a **Component-Based** pattern. Each component owns its own state, rendering, and event handling. The Container routes events and mediates communication.
147
-
148
- Use this pattern for forms, editors, and mouse-driven tools.
149
-
150
- ### The Dashboard Approach (AppAllEvents)
151
-
152
- Dashboards display data. They rarely require complex mouse interaction. Model-View-Update works best there. State is immutable. Logic is pure. Updates are predictable. This simplifies testing.
153
-
154
- Use that pattern for logs, monitors, and data viewers.
155
-
156
- [Read the source code →](app.rb)
@@ -1,76 +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 "main_container"
13
-
14
- # A terminal-based color picker application.
15
- #
16
- # Terminal users often need to select colors for themes or UI components.
17
- # Manually typing hex codes and guessing how they will look is slow and error-prone.
18
- #
19
- # This application solves the problem by providing an interactive interface. It parses hex strings,
20
- # generates palettes, and displays them visually in the terminal.
21
- #
22
- # === Architecture
23
- #
24
- # This example uses a Component-Based pattern:
25
- # - **Components**: Self-contained UI elements with `render`, `handle_event`, and optional `tick`
26
- # - **Container**: Owns layout, delegates to children, routes events via Chain of Responsibility
27
- # - **Mediator**: Container interprets symbolic signals (`:consumed`, `:submitted`) for cross-component effects
28
- #
29
- # === Examples
30
- #
31
- # AppColorPicker.new.run
32
- #
33
- class AppColorPicker
34
- # Creates a new <tt>AppColorPicker</tt> instance.
35
- def initialize
36
- @container = nil
37
- end
38
-
39
- # Starts the terminal session and enters the main event loop.
40
- #
41
- # This method initializes the terminal, creates the MainContainer, and runs
42
- # the event loop until the user quits.
43
- #
44
- # === Example
45
- #
46
- # app = AppColorPicker.new
47
- # app.run
48
- #
49
- def run
50
- RatatuiRuby.run do |tui|
51
- @container = MainContainer.new(tui)
52
-
53
- loop do
54
- @container.tick
55
- tui.draw { |frame| @container.render(tui, frame, frame.area) }
56
-
57
- event = tui.poll_event
58
- break if quit_event?(event)
59
-
60
- @container.handle_event(event)
61
- end
62
- end
63
- end
64
-
65
- private def quit_event?(event)
66
- case event
67
- in { type: :key, code: "q" } | { type: :key, code: "esc" } |
68
- { type: :key, code: "c", modifiers: [/ctrl/] }
69
- true
70
- else
71
- false
72
- end
73
- end
74
- end
75
-
76
- AppColorPicker.new.run if __FILE__ == $PROGRAM_NAME