ratatui_ruby 1.3.0 → 1.4.0

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 (263) hide show
  1. checksums.yaml +4 -4
  2. data/ext/ratatui_ruby/Cargo.lock +2 -1
  3. data/ext/ratatui_ruby/Cargo.toml +2 -1
  4. data/ext/ratatui_ruby/src/events.rs +157 -18
  5. data/lib/ratatui_ruby/test_helper/snapshot.rb +58 -10
  6. data/lib/ratatui_ruby/test_helper/subprocess_timeout.rb +35 -0
  7. data/lib/ratatui_ruby/test_helper.rb +2 -0
  8. data/lib/ratatui_ruby/version.rb +1 -1
  9. metadata +17 -270
  10. data/.builds/ruby-3.2.yml +0 -54
  11. data/.builds/ruby-3.3.yml +0 -54
  12. data/.builds/ruby-3.4.yml +0 -54
  13. data/.builds/ruby-4.0.0.yml +0 -54
  14. data/.pre-commit-config.yaml +0 -16
  15. data/.rubocop.yml +0 -10
  16. data/AGENTS.md +0 -147
  17. data/CHANGELOG.md +0 -771
  18. data/README.md +0 -187
  19. data/README.rdoc +0 -302
  20. data/Rakefile +0 -11
  21. data/Steepfile +0 -50
  22. data/doc/concepts/application_architecture.md +0 -321
  23. data/doc/concepts/application_testing.md +0 -193
  24. data/doc/concepts/async.md +0 -190
  25. data/doc/concepts/custom_widgets.md +0 -247
  26. data/doc/concepts/debugging.md +0 -401
  27. data/doc/concepts/event_handling.md +0 -162
  28. data/doc/concepts/interactive_design.md +0 -146
  29. data/doc/contributors/auditing/parity.md +0 -239
  30. data/doc/contributors/design/ruby_frontend.md +0 -448
  31. data/doc/contributors/design/rust_backend.md +0 -434
  32. data/doc/contributors/design.md +0 -11
  33. data/doc/contributors/developing_examples.md +0 -400
  34. data/doc/contributors/documentation_style.md +0 -121
  35. data/doc/contributors/index.md +0 -21
  36. data/doc/contributors/releasing.md +0 -215
  37. data/doc/contributors/todo/align/api_completeness_audit-finished.md +0 -381
  38. data/doc/contributors/todo/align/api_completeness_audit-unfinished.md +0 -200
  39. data/doc/contributors/todo/align/term.md +0 -351
  40. data/doc/contributors/todo/align/terminal.md +0 -647
  41. data/doc/contributors/todo/future_work.md +0 -169
  42. data/doc/contributors/upstream_requests/paragraph_span_rects.md +0 -259
  43. data/doc/contributors/upstream_requests/tab_rects.md +0 -173
  44. data/doc/contributors/upstream_requests/title_rects.md +0 -132
  45. data/doc/custom.css +0 -22
  46. data/doc/getting_started/quickstart.md +0 -291
  47. data/doc/getting_started/why.md +0 -93
  48. data/doc/images/app_all_events.png +0 -0
  49. data/doc/images/app_cli_rich_moments.gif +0 -0
  50. data/doc/images/app_color_picker.png +0 -0
  51. data/doc/images/app_debugging_showcase.gif +0 -0
  52. data/doc/images/app_debugging_showcase.png +0 -0
  53. data/doc/images/app_external_editor.gif +0 -0
  54. data/doc/images/app_login_form.png +0 -0
  55. data/doc/images/app_stateful_interaction.png +0 -0
  56. data/doc/images/verify_quickstart_dsl.png +0 -0
  57. data/doc/images/verify_quickstart_layout.png +0 -0
  58. data/doc/images/verify_quickstart_lifecycle.png +0 -0
  59. data/doc/images/verify_readme_usage.png +0 -0
  60. data/doc/images/widget_barchart.png +0 -0
  61. data/doc/images/widget_block.png +0 -0
  62. data/doc/images/widget_box.png +0 -0
  63. data/doc/images/widget_calendar.png +0 -0
  64. data/doc/images/widget_canvas.png +0 -0
  65. data/doc/images/widget_cell.png +0 -0
  66. data/doc/images/widget_center.png +0 -0
  67. data/doc/images/widget_chart.png +0 -0
  68. data/doc/images/widget_gauge.png +0 -0
  69. data/doc/images/widget_layout_split.png +0 -0
  70. data/doc/images/widget_line_gauge.png +0 -0
  71. data/doc/images/widget_list.png +0 -0
  72. data/doc/images/widget_map.png +0 -0
  73. data/doc/images/widget_overlay.png +0 -0
  74. data/doc/images/widget_popup.png +0 -0
  75. data/doc/images/widget_ratatui_logo.png +0 -0
  76. data/doc/images/widget_ratatui_mascot.png +0 -0
  77. data/doc/images/widget_rect.png +0 -0
  78. data/doc/images/widget_render.png +0 -0
  79. data/doc/images/widget_rich_text.png +0 -0
  80. data/doc/images/widget_scroll_text.png +0 -0
  81. data/doc/images/widget_scrollbar.png +0 -0
  82. data/doc/images/widget_sparkline.png +0 -0
  83. data/doc/images/widget_style_colors.png +0 -0
  84. data/doc/images/widget_table.png +0 -0
  85. data/doc/images/widget_tabs.png +0 -0
  86. data/doc/images/widget_text_width.png +0 -0
  87. data/doc/index.md +0 -34
  88. data/doc/troubleshooting/async.md +0 -4
  89. data/doc/troubleshooting/terminal_limitations.md +0 -131
  90. data/doc/troubleshooting/tui_output.md +0 -197
  91. data/examples/app_all_events/README.md +0 -114
  92. data/examples/app_all_events/app.rb +0 -98
  93. data/examples/app_all_events/model/app_model.rb +0 -159
  94. data/examples/app_all_events/model/event_color_cycle.rb +0 -43
  95. data/examples/app_all_events/model/event_entry.rb +0 -94
  96. data/examples/app_all_events/model/msg.rb +0 -39
  97. data/examples/app_all_events/model/timestamp.rb +0 -56
  98. data/examples/app_all_events/update.rb +0 -75
  99. data/examples/app_all_events/view/app_view.rb +0 -80
  100. data/examples/app_all_events/view/controls_view.rb +0 -54
  101. data/examples/app_all_events/view/counts_view.rb +0 -61
  102. data/examples/app_all_events/view/live_view.rb +0 -72
  103. data/examples/app_all_events/view/log_view.rb +0 -57
  104. data/examples/app_all_events/view.rb +0 -9
  105. data/examples/app_cli_rich_moments/README.md +0 -81
  106. data/examples/app_cli_rich_moments/app.rb +0 -189
  107. data/examples/app_color_picker/README.md +0 -156
  108. data/examples/app_color_picker/app.rb +0 -76
  109. data/examples/app_color_picker/clipboard.rb +0 -86
  110. data/examples/app_color_picker/color.rb +0 -193
  111. data/examples/app_color_picker/controls.rb +0 -92
  112. data/examples/app_color_picker/copy_dialog.rb +0 -168
  113. data/examples/app_color_picker/export_pane.rb +0 -128
  114. data/examples/app_color_picker/harmony.rb +0 -58
  115. data/examples/app_color_picker/input.rb +0 -176
  116. data/examples/app_color_picker/main_container.rb +0 -180
  117. data/examples/app_color_picker/palette.rb +0 -111
  118. data/examples/app_debugging_showcase/README.md +0 -119
  119. data/examples/app_debugging_showcase/app.rb +0 -318
  120. data/examples/app_external_editor/README.md +0 -62
  121. data/examples/app_external_editor/app.rb +0 -344
  122. data/examples/app_login_form/README.md +0 -58
  123. data/examples/app_login_form/app.rb +0 -109
  124. data/examples/app_stateful_interaction/README.md +0 -35
  125. data/examples/app_stateful_interaction/app.rb +0 -328
  126. data/examples/timeout_demo.rb +0 -45
  127. data/examples/verify_quickstart_dsl/README.md +0 -55
  128. data/examples/verify_quickstart_dsl/app.rb +0 -49
  129. data/examples/verify_quickstart_layout/README.md +0 -77
  130. data/examples/verify_quickstart_layout/app.rb +0 -73
  131. data/examples/verify_quickstart_lifecycle/README.md +0 -68
  132. data/examples/verify_quickstart_lifecycle/app.rb +0 -62
  133. data/examples/verify_readme_usage/README.md +0 -49
  134. data/examples/verify_readme_usage/app.rb +0 -42
  135. data/examples/verify_website_managed/README.md +0 -48
  136. data/examples/verify_website_managed/app.rb +0 -36
  137. data/examples/verify_website_menu/README.md +0 -60
  138. data/examples/verify_website_menu/app.rb +0 -84
  139. data/examples/verify_website_spinner/README.md +0 -44
  140. data/examples/verify_website_spinner/app.rb +0 -34
  141. data/examples/widget_barchart/README.md +0 -58
  142. data/examples/widget_barchart/app.rb +0 -240
  143. data/examples/widget_block/README.md +0 -44
  144. data/examples/widget_block/app.rb +0 -258
  145. data/examples/widget_box/README.md +0 -54
  146. data/examples/widget_box/app.rb +0 -255
  147. data/examples/widget_calendar/README.md +0 -48
  148. data/examples/widget_calendar/app.rb +0 -115
  149. data/examples/widget_canvas/README.md +0 -31
  150. data/examples/widget_canvas/app.rb +0 -130
  151. data/examples/widget_cell/README.md +0 -45
  152. data/examples/widget_cell/app.rb +0 -112
  153. data/examples/widget_center/README.md +0 -33
  154. data/examples/widget_center/app.rb +0 -118
  155. data/examples/widget_chart/README.md +0 -50
  156. data/examples/widget_chart/app.rb +0 -220
  157. data/examples/widget_gauge/README.md +0 -50
  158. data/examples/widget_gauge/app.rb +0 -229
  159. data/examples/widget_layout_split/README.md +0 -53
  160. data/examples/widget_layout_split/app.rb +0 -260
  161. data/examples/widget_line_gauge/README.md +0 -50
  162. data/examples/widget_line_gauge/app.rb +0 -219
  163. data/examples/widget_list/README.md +0 -58
  164. data/examples/widget_list/app.rb +0 -382
  165. data/examples/widget_map/README.md +0 -48
  166. data/examples/widget_map/app.rb +0 -95
  167. data/examples/widget_overlay/README.md +0 -45
  168. data/examples/widget_overlay/app.rb +0 -250
  169. data/examples/widget_popup/README.md +0 -45
  170. data/examples/widget_popup/app.rb +0 -106
  171. data/examples/widget_ratatui_logo/README.md +0 -43
  172. data/examples/widget_ratatui_logo/app.rb +0 -104
  173. data/examples/widget_ratatui_mascot/README.md +0 -43
  174. data/examples/widget_ratatui_mascot/app.rb +0 -95
  175. data/examples/widget_rect/README.md +0 -53
  176. data/examples/widget_rect/app.rb +0 -222
  177. data/examples/widget_render/README.md +0 -46
  178. data/examples/widget_render/app.rb +0 -186
  179. data/examples/widget_render/app.rbs +0 -41
  180. data/examples/widget_rich_text/README.md +0 -44
  181. data/examples/widget_rich_text/app.rb +0 -193
  182. data/examples/widget_scroll_text/README.md +0 -46
  183. data/examples/widget_scroll_text/app.rb +0 -109
  184. data/examples/widget_scrollbar/README.md +0 -46
  185. data/examples/widget_scrollbar/app.rb +0 -155
  186. data/examples/widget_sparkline/README.md +0 -51
  187. data/examples/widget_sparkline/app.rb +0 -277
  188. data/examples/widget_style_colors/README.md +0 -43
  189. data/examples/widget_style_colors/app.rb +0 -83
  190. data/examples/widget_table/README.md +0 -57
  191. data/examples/widget_table/app.rb +0 -285
  192. data/examples/widget_tabs/README.md +0 -50
  193. data/examples/widget_tabs/app.rb +0 -183
  194. data/examples/widget_text_width/README.md +0 -44
  195. data/examples/widget_text_width/app.rb +0 -117
  196. data/migrate_to_buffer.rb +0 -145
  197. data/mise.toml +0 -8
  198. data/tasks/autodoc/examples.rb +0 -87
  199. data/tasks/autodoc/member.rb +0 -58
  200. data/tasks/autodoc/name.rb +0 -21
  201. data/tasks/autodoc.rake +0 -21
  202. data/tasks/bump/bump_workflow.rb +0 -49
  203. data/tasks/bump/cargo_lockfile.rb +0 -21
  204. data/tasks/bump/changelog.rb +0 -104
  205. data/tasks/bump/header.rb +0 -32
  206. data/tasks/bump/history.rb +0 -32
  207. data/tasks/bump/links.rb +0 -69
  208. data/tasks/bump/manifest.rb +0 -33
  209. data/tasks/bump/patch_release.rb +0 -19
  210. data/tasks/bump/release_branch.rb +0 -17
  211. data/tasks/bump/release_from_trunk.rb +0 -49
  212. data/tasks/bump/repository.rb +0 -54
  213. data/tasks/bump/ruby_gem.rb +0 -29
  214. data/tasks/bump/sem_ver.rb +0 -44
  215. data/tasks/bump/unreleased_section.rb +0 -73
  216. data/tasks/bump.rake +0 -61
  217. data/tasks/doc/documentation.rb +0 -59
  218. data/tasks/doc/link/file_url.rb +0 -30
  219. data/tasks/doc/link/relative_path.rb +0 -61
  220. data/tasks/doc/link/web_url.rb +0 -55
  221. data/tasks/doc/link.rb +0 -52
  222. data/tasks/doc/link_audit.rb +0 -116
  223. data/tasks/doc/problem.rb +0 -40
  224. data/tasks/doc/source_file.rb +0 -93
  225. data/tasks/doc.rake +0 -905
  226. data/tasks/example_viewer.html.erb +0 -172
  227. data/tasks/extension.rake +0 -14
  228. data/tasks/license/headers_md.rb +0 -223
  229. data/tasks/license/headers_rb.rb +0 -210
  230. data/tasks/license/license_utils.rb +0 -130
  231. data/tasks/license/snippets_md.rb +0 -315
  232. data/tasks/license/snippets_rdoc.rb +0 -150
  233. data/tasks/license.rake +0 -91
  234. data/tasks/lint.rake +0 -170
  235. data/tasks/rbs_predicates/predicate_catalog.rb +0 -52
  236. data/tasks/rbs_predicates/predicate_tests.rb +0 -124
  237. data/tasks/rbs_predicates/rbs_signature.rb +0 -63
  238. data/tasks/rbs_predicates.rake +0 -31
  239. data/tasks/rdoc_config.rb +0 -29
  240. data/tasks/resources/build.yml.erb +0 -60
  241. data/tasks/resources/index.html.erb +0 -141
  242. data/tasks/resources/rubies.yml +0 -7
  243. data/tasks/sourcehut.rake +0 -122
  244. data/tasks/steep.rake +0 -11
  245. data/tasks/terminal_preview/app_screenshot.rb +0 -45
  246. data/tasks/terminal_preview/crash_report.rb +0 -54
  247. data/tasks/terminal_preview/example_app.rb +0 -27
  248. data/tasks/terminal_preview/launcher_script.rb +0 -48
  249. data/tasks/terminal_preview/preview_collection.rb +0 -60
  250. data/tasks/terminal_preview/preview_timing.rb +0 -24
  251. data/tasks/terminal_preview/safety_confirmation.rb +0 -58
  252. data/tasks/terminal_preview/saved_screenshot.rb +0 -56
  253. data/tasks/terminal_preview/system_appearance.rb +0 -13
  254. data/tasks/terminal_preview/terminal_window.rb +0 -138
  255. data/tasks/terminal_preview/window_id.rb +0 -16
  256. data/tasks/terminal_preview.rake +0 -30
  257. data/tasks/test.rake +0 -36
  258. data/tasks/website/index_page.rb +0 -30
  259. data/tasks/website/version.rb +0 -122
  260. data/tasks/website/version_menu.rb +0 -68
  261. data/tasks/website/versioned_documentation.rb +0 -83
  262. data/tasks/website/website.rb +0 -53
  263. data/tasks/website.rake +0 -28
@@ -1,219 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- #--
4
- # SPDX-FileCopyrightText: 2026 Kerrick Long <me@kerricklong.com>
5
- # SPDX-License-Identifier: MIT-0
6
- #++
7
-
8
- $LOAD_PATH.unshift File.expand_path("../../lib", __dir__)
9
- require "ratatui_ruby"
10
-
11
- # Demonstrates compact status visualization with interactive attribute cycling.
12
- #
13
- # Screen space is precious. Standard block gauges are bulky and consume multiple rows.
14
- #
15
- # This demo showcases the <tt>LineGauge</tt> widget. It provides an interactive playground where you can cycle through different ratios, symbols, and styling for both filled and unfilled portions in real-time.
16
- #
17
- # Use it to understand how to provide status feedback in constrained layouts without consuming vertical space.
18
- #
19
- # === Example
20
- #
21
- # Run the demo from the terminal:
22
- #
23
- # ruby examples/widget_line_gauge/app.rb
24
- #
25
- # rdoc-image:/doc/images/widget_line_gauge.png
26
- class WidgetLineGauge
27
- def initialize
28
- @ratio = 0.5
29
- @ratios = [0.2, 0.35, 0.5, 0.65, 0.8, 0.95]
30
- @ratio_index = 2
31
-
32
- @filled_symbols = [
33
- { name: "█ (Block)", symbol: "█" },
34
- { name: "▓ (Dark Shade)", symbol: "▓" },
35
- { name: "▒ (Medium Shade)", symbol: "▒" },
36
- { name: "= (Equals)", symbol: "=" },
37
- { name: "# (Hash)", symbol: "#" },
38
- ]
39
- @filled_symbol_index = 0
40
-
41
- @unfilled_symbols = [
42
- { name: "░ (Light Shade)", symbol: "░" },
43
- { name: "· (Dot)", symbol: "·" },
44
- { name: "- (Dash)", symbol: "-" },
45
- { name: "~ (Tilde)", symbol: "~" },
46
- ]
47
- @unfilled_symbol_index = 0
48
-
49
- @filled_colors = [
50
- { name: "Red", color: :red },
51
- { name: "Yellow", color: :yellow },
52
- { name: "Green", color: :green },
53
- { name: "Cyan", color: :cyan },
54
- { name: "Blue", color: :blue },
55
- ]
56
- @filled_color_index = 2
57
-
58
- @unfilled_colors = [
59
- { name: "Default", color: nil },
60
- { name: "Dark Gray", color: :dark_gray },
61
- { name: "Gray", color: :gray },
62
- ]
63
- @unfilled_color_index = 1
64
-
65
- @base_styles = nil # Initialized in run when @tui is available
66
- @base_style_index = 0
67
- @hotkey_style = nil # Initialized in run when @tui is available
68
- end
69
-
70
- def run
71
- RatatuiRuby.run do |tui|
72
- @tui = tui
73
-
74
- # Initialize styles using tui helpers
75
- @base_styles = [
76
- { name: "None", style: nil },
77
- { name: "Bold White", style: tui.style(fg: :white, modifiers: [:bold]) },
78
- { name: "White on Blue", style: tui.style(fg: :white, bg: :blue) },
79
- { name: "Italic Cyan", style: tui.style(fg: :cyan, modifiers: [:italic]) },
80
- ]
81
- @hotkey_style = tui.style(modifiers: [:bold, :underlined])
82
-
83
- loop do
84
- render
85
- break if handle_input == :quit
86
- sleep 0.05
87
- end
88
- end
89
- end
90
-
91
- private def render
92
- @ratio = @ratios[@ratio_index]
93
-
94
- filled_color = @filled_colors[@filled_color_index][:color]
95
- unfilled_color = @unfilled_colors[@unfilled_color_index][:color]
96
-
97
- filled_style = filled_color ? @tui.style(fg: filled_color) : @tui.style(fg: :white)
98
- unfilled_style = unfilled_color ? @tui.style(fg: unfilled_color) : @tui.style(fg: :dark_gray)
99
-
100
- @tui.draw do |frame|
101
- # Split into main content and control panel
102
- main_area, controls_area = @tui.layout_split(
103
- frame.area,
104
- direction: :vertical,
105
- constraints: [
106
- @tui.constraint_fill(1),
107
- @tui.constraint_length(5),
108
- ]
109
- )
110
-
111
- # Split main area into title, gauges, and spacer
112
- title_area, gauge1_area, gauge2_area, spacer_area = @tui.layout_split(
113
- main_area,
114
- direction: :vertical,
115
- constraints: [
116
- @tui.constraint_length(1),
117
- @tui.constraint_length(4),
118
- @tui.constraint_length(4),
119
- @tui.constraint_fill(1),
120
- ]
121
- )
122
-
123
- # Render title
124
- title = @tui.paragraph(text: "LineGauge Widget - Cycle attributes with hotkeys")
125
- frame.render_widget(title, title_area)
126
-
127
- # Example 1: Static gauge showing all features
128
- gauge1 = @tui.line_gauge(
129
- ratio: @ratio,
130
- label: "#{(@ratio * 100).to_i}%",
131
- style: @base_styles[@base_style_index][:style],
132
- filled_style:,
133
- unfilled_style:,
134
- filled_symbol: @filled_symbols[@filled_symbol_index][:symbol],
135
- unfilled_symbol: @unfilled_symbols[@unfilled_symbol_index][:symbol],
136
- block: @tui.block(title: "Interactive Gauge")
137
- )
138
- frame.render_widget(gauge1, gauge1_area)
139
-
140
- # Example 2: Inverted colors for contrast demonstration
141
- gauge2 = @tui.line_gauge(
142
- ratio: 1.0 - @ratio,
143
- label: "#{((1.0 - @ratio) * 100).to_i}%",
144
- filled_style: @tui.style(fg: :black, bg: :yellow),
145
- unfilled_style: @tui.style(fg: :white, bg: :dark_gray),
146
- filled_symbol: @filled_symbols[@filled_symbol_index][:symbol],
147
- unfilled_symbol: @unfilled_symbols[@unfilled_symbol_index][:symbol],
148
- block: @tui.block(title: "Inverse (100% - ratio)")
149
- )
150
- frame.render_widget(gauge2, gauge2_area)
151
-
152
- # Render empty spacer
153
- spacer = @tui.paragraph(text: "")
154
- frame.render_widget(spacer, spacer_area)
155
-
156
- # Bottom control panel
157
- controls = @tui.block(
158
- title: "Controls",
159
- borders: [:all],
160
- children: [
161
- @tui.paragraph(
162
- text: [
163
- # Line 1: General
164
- @tui.text_line(spans: [
165
- @tui.text_span(content: "←/→", style: @hotkey_style),
166
- @tui.text_span(content: ": Ratio (#{(@ratio * 100).to_i}%) "),
167
- @tui.text_span(content: "b", style: @hotkey_style),
168
- @tui.text_span(content: ": Base Style (#{@base_styles[@base_style_index][:name]}) "),
169
- @tui.text_span(content: "q", style: @hotkey_style),
170
- @tui.text_span(content: ": Quit"),
171
- ]),
172
- # Line 2: Filled
173
- @tui.text_line(spans: [
174
- @tui.text_span(content: "f", style: @hotkey_style),
175
- @tui.text_span(content: ": Filled Symbol (#{@filled_symbols[@filled_symbol_index][:name]}) "),
176
- @tui.text_span(content: "c", style: @hotkey_style),
177
- @tui.text_span(content: ": Filled Color (#{@filled_colors[@filled_color_index][:name]})"),
178
- ]),
179
- # Line 3: Unfilled
180
- @tui.text_line(spans: [
181
- @tui.text_span(content: "u", style: @hotkey_style),
182
- @tui.text_span(content: ": Unfilled Symbol (#{@unfilled_symbols[@unfilled_symbol_index][:name]}) "),
183
- @tui.text_span(content: "x", style: @hotkey_style),
184
- @tui.text_span(content: ": Unfilled Color (#{@unfilled_colors[@unfilled_color_index][:name]})"),
185
- ]),
186
- ]
187
- ),
188
- ]
189
- )
190
- frame.render_widget(controls, controls_area)
191
- end
192
- end
193
-
194
- private def handle_input
195
- case @tui.poll_event
196
- in { type: :key, code: "q" } | { type: :key, code: "c", modifiers: ["ctrl"] }
197
- :quit
198
- in type: :key, code: "right"
199
- @ratio_index = (@ratio_index + 1) % @ratios.length
200
- in type: :key, code: "left"
201
- @ratio_index = (@ratio_index - 1) % @ratios.length
202
- in type: :key, code: "b"
203
- @base_style_index = (@base_style_index + 1) % @base_styles.length
204
- in type: :key, code: "f"
205
- @filled_symbol_index = (@filled_symbol_index + 1) % @filled_symbols.length
206
- in type: :key, code: "c"
207
- @filled_color_index = (@filled_color_index + 1) % @filled_colors.length
208
- in type: :key, code: "u"
209
- @unfilled_symbol_index = (@unfilled_symbol_index + 1) % @unfilled_symbols.length
210
- in type: :key, code: "x"
211
- @unfilled_color_index = (@unfilled_color_index + 1) % @unfilled_colors.length
212
- else
213
- # Ignore other events
214
- nil
215
- end
216
- end
217
- end
218
-
219
- WidgetLineGauge.new.run if __FILE__ == $PROGRAM_NAME
@@ -1,58 +0,0 @@
1
- <!--
2
- SPDX-FileCopyrightText: 2026 Kerrick Long <me@kerricklong.com>
3
- SPDX-License-Identifier: CC-BY-SA-4.0
4
- -->
5
-
6
- # List (ListItem) Example
7
-
8
- [![widget_list](../../doc/images/widget_list.png)](app.rb)
9
-
10
- Demonstrates a selectable list with extensive configuration options.
11
-
12
- Lists are the workhorse of terminal interfaces. Managing selection state, scrolling windows, and highlight styles logic is complex. The `List` widget handles all of this.
13
-
14
- ## Features Demonstrated
15
-
16
- - **Scrolling**: Automatically handles lists larger than the view area.
17
- - **Selection**: Maintains selected index and supports "no selection" state.
18
- - **Highlighting**: Custom styles and symbols (e.g., `>>`) for the selected item.
19
- - **Offset Modes**: Manual control over the scroll offset vs automatic "scroll to selection" behavior.
20
- - **Scroll Padding**: Keeping a margin of items visible above/below the selection.
21
-
22
- ## Hotkeys
23
-
24
- - **i**: Cycle Item Data (`items`)
25
- - **Arrow Keys (↑/↓)**: Navigate (`selected_index`)
26
- - **x**: Toggle Selection (`selected_index`)
27
- - **h**: Cycle Highlight Style (`highlight_style`)
28
- - **y**: Cycle Highlight Symbol (`highlight_symbol`)
29
- - **d**: Toggle Direction (`direction`)
30
- - **s**: Cycle Highlight Spacing (`highlight_spacing`)
31
- - **p**: Cycle Scroll Padding (`scroll_padding`)
32
- - **b**: Cycle Base Style (`style`)
33
- - **r**: Toggle Repeat Highlight Symbol (`repeat_highlight_symbol`)
34
- - **o**: Cycle Offset Mode (`offset`)
35
- - **q**: Quit
36
-
37
- ## Usage
38
-
39
- <!-- SPDX-SnippetBegin -->
40
- <!--
41
- SPDX-FileCopyrightText: 2026 Kerrick Long
42
- SPDX-License-Identifier: MIT-0
43
- -->
44
- ```bash
45
- ruby examples/widget_list/app.rb
46
- ```
47
- <!-- SPDX-SnippetEnd -->
48
-
49
- ## Learning Outcomes
50
-
51
- Use this example if you need to...
52
-
53
- - Create a file explorer.
54
- - Build a navigation menu.
55
- - Display a log where users can scroll back to read history.
56
- - Implement "infinite select" behaviors.
57
-
58
- [Read the source code →](app.rb)
@@ -1,382 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- #--
4
- # SPDX-FileCopyrightText: 2026 Kerrick Long <me@kerricklong.com>
5
- # SPDX-License-Identifier: MIT-0
6
- #++
7
-
8
- $LOAD_PATH.unshift File.expand_path("../../lib", __dir__)
9
- require "ratatui_ruby"
10
- require "faker" # Use Faker for large, realistic datasets
11
-
12
- # Demonstrates a selectable list of items with interactive attribute cycling.
13
- #
14
- # Users need to browse and select from collections of data. Lists are fundamental to terminal interfaces, but managing selection state, scrolling, and styling can be complex.
15
- #
16
- # This demo showcases the <tt>List</tt> widget. It provides an interactive playground where you can cycle through different configurations, styles, and behaviors in real-time.
17
- #
18
- # Use it to understand how to implement menus, file browsers, or any selectable collection of items.
19
- #
20
- # === Examples
21
- #
22
- # Run the demo from the terminal:
23
- #
24
- # ruby examples/widget_list/app.rb
25
- #
26
- # rdoc-image:/doc/images/widget_list.png
27
- class WidgetList
28
- # Initializes the demo with example data and default configuration.
29
- def initialize
30
- Faker::Config.random = Random.new(12345)
31
- @selected_index = 6 # Start at C# to avoid highlighting the rich text examples
32
- @tui_for_setup = nil
33
-
34
- @item_sets = [
35
- {
36
- name: "Programming",
37
- items: [
38
- :ruby_styled, # Will be replaced with rich text in run()
39
- :rust_styled, # Will be replaced with rich text in run()
40
- :python_styled, # Will be replaced with rich text in run()
41
- :javascript_styled, # Will be replaced with rich text in run()
42
- "Go",
43
- "C++",
44
- "C#",
45
- "Java",
46
- "Kotlin",
47
- "Swift",
48
- "Objective-C",
49
- "PHP",
50
- "TypeScript",
51
- "Perl",
52
- "Lua",
53
- "R",
54
- "Scala",
55
- "Haskell",
56
- "Elixir",
57
- "Clojure",
58
- "Groovy",
59
- "Closure",
60
- "VB.NET",
61
- "F#",
62
- "Erlang",
63
- "Lisp",
64
- "Scheme",
65
- "Prolog",
66
- "Fortran",
67
- "COBOL",
68
- "Pascal",
69
- "Delphi",
70
- "Ada",
71
- "Bash",
72
- "Sh",
73
- "Tcl",
74
- "Awk",
75
- "sed",
76
- "Vim Script",
77
- "PowerShell",
78
- "Batch",
79
- "Assembly",
80
- "Wasm",
81
- "WebAssembly",
82
- "Julia",
83
- "Matlab",
84
- "Octave",
85
- "BASIC",
86
- ],
87
- },
88
- {
89
- name: "Large List",
90
- items: (1..200).map { |i| "Item #{i}" },
91
- },
92
- {
93
- name: "Colors",
94
- items: begin
95
- Faker::Color.unique.clear
96
- Array.new(100) { Faker::Color.color_name }
97
- end,
98
- },
99
- {
100
- name: "Fruits",
101
- items: begin
102
- Faker::Food.unique.clear
103
- Array.new(100) { Faker::Food.fruits }
104
- end,
105
- },
106
- ]
107
- @item_set_index = 0
108
-
109
- @highlight_symbol_names = [">> ", "▶ ", "→ ", "• ", "★ "]
110
- @highlight_symbol_index = 0
111
-
112
- @direction_configs = [
113
- { name: "Top to Bottom", direction: :top_to_bottom },
114
- { name: "Bottom to Top", direction: :bottom_to_top },
115
- ]
116
- @direction_index = 0
117
-
118
- @highlight_spacing_configs = [
119
- { name: "When Selected", spacing: :when_selected },
120
- { name: "Always", spacing: :always },
121
- { name: "Never", spacing: :never },
122
- ]
123
- @highlight_spacing_index = 1
124
-
125
- @repeat_modes = [
126
- { name: "Off", repeat: false },
127
- { name: "On", repeat: true },
128
- ]
129
- @repeat_index = 0
130
-
131
- @scroll_padding_configs = [
132
- { name: "None", padding: nil },
133
- { name: "1 item", padding: 1 },
134
- { name: "2 items", padding: 2 },
135
- ]
136
- @scroll_padding_index = 1
137
-
138
- # Offset mode configurations to demonstrate offset + selection interaction
139
- @offset_modes = [
140
- { name: "Auto (No Offset)", offset: nil, allow_selection: true },
141
- { name: "Offset Only", offset: 10, allow_selection: false },
142
- { name: "Selection + Offset (Conflict)", offset: 0, allow_selection: true },
143
- ]
144
- @offset_mode_index = 0
145
- end
146
-
147
- # Runs the demo application.
148
- #
149
- # This method enters the terminal alternate screen, starts the main loop, and handles cleanup on exit.
150
- def run
151
- RatatuiRuby.run do |tui|
152
- @tui = tui
153
-
154
- # Create rich text for "Ruby" - each letter with a different red style
155
- ruby_line = @tui.text_line(spans: [
156
- @tui.text_span(content: "R", style: @tui.style(fg: :red, modifiers: [:underlined])),
157
- @tui.text_span(content: "u", style: @tui.style(fg: :light_red, modifiers: [:bold])),
158
- @tui.text_span(content: "b", style: @tui.style(fg: :red, modifiers: [:italic])),
159
- @tui.text_span(content: "y", style: @tui.style(fg: :light_red, modifiers: [:reversed])),
160
- ])
161
-
162
- # Create rich text for "Rust" - single styled Span
163
- rust_span = @tui.text_span(
164
- content: "Rust",
165
- style: @tui.style(fg: :magenta, modifiers: [:bold, :underlined])
166
- )
167
-
168
- # Create ListItem for "Python" - demonstrates content + row background
169
- python_item = @tui.list_item(
170
- content: @tui.text_span(content: "Python", style: @tui.style(fg: :yellow)),
171
- style: @tui.style(bg: :dark_gray)
172
- )
173
-
174
- # Create ListItem for "JavaScript" - demonstrates styled text with row background
175
- javascript_item = @tui.list_item(
176
- content: @tui.text_line(spans: [
177
- @tui.text_span(content: "Java", style: @tui.style(fg: :yellow, modifiers: [:bold])),
178
- @tui.text_span(content: "Script", style: @tui.style(fg: :light_yellow, modifiers: [:italic])),
179
- ]),
180
- style: @tui.style(bg: :blue)
181
- )
182
-
183
- # Replace the styled placeholders
184
- @item_sets[0][:items][0] = ruby_line
185
- @item_sets[0][:items][1] = rust_span
186
- @item_sets[0][:items][2] = python_item
187
- @item_sets[0][:items][3] = javascript_item
188
-
189
- # Initialize styles that require @tui
190
- @highlight_styles = [
191
- { name: "Blue on White Bold", style: @tui.style(fg: :blue, bg: :white, modifiers: [:bold]) },
192
- { name: "Blue Bold", style: @tui.style(fg: :blue, modifiers: [:bold]) },
193
- { name: "Yellow on Black", style: @tui.style(fg: :yellow, bg: :black) },
194
- { name: "Green Italic", style: @tui.style(fg: :green, modifiers: [:italic]) },
195
- { name: "White Reversed", style: @tui.style(fg: :white, modifiers: [:reversed]) },
196
- { name: "Cyan Bold", style: @tui.style(fg: :cyan, modifiers: [:bold]) },
197
- ]
198
- @highlight_style_index = 0
199
-
200
- @base_styles = [
201
- { name: "None", style: nil },
202
- { name: "Dark Gray", style: @tui.style(fg: :dark_gray) },
203
- { name: "White on Black", style: @tui.style(fg: :white, bg: :black) },
204
- ]
205
- @base_style_index = 0
206
-
207
- @hotkey_style = @tui.style(modifiers: [:bold, :underlined])
208
-
209
- loop do
210
- render
211
- break if handle_input == :quit
212
-
213
- sleep 0.05
214
- end
215
- end
216
- end
217
-
218
- private def render # :nodoc:
219
- items = @item_sets[@item_set_index][:items]
220
- direction_config = @direction_configs[@direction_index]
221
- spacing_config = @highlight_spacing_configs[@highlight_spacing_index]
222
- repeat_config = @repeat_modes[@repeat_index]
223
- highlight_style_config = @highlight_styles[@highlight_style_index]
224
- highlight_symbol = @highlight_symbol_names[@highlight_symbol_index]
225
- base_style_config = @base_styles[@base_style_index]
226
- scroll_padding_config = @scroll_padding_configs[@scroll_padding_index]
227
- offset_mode_config = @offset_modes[@offset_mode_index]
228
-
229
- # Determine selection/offset based on mode
230
- effective_selection = offset_mode_config[:allow_selection] ? @selected_index : nil
231
- effective_offset = offset_mode_config[:offset]
232
-
233
- @tui.draw do |frame|
234
- # Split into main content and control panel
235
- main_area, control_area = @tui.layout_split(
236
- frame.area,
237
- direction: :vertical,
238
- constraints: [
239
- @tui.constraint_fill(1),
240
- @tui.constraint_length(8),
241
- ]
242
- )
243
-
244
- # Split main content into title and list
245
- title_area, list_area = @tui.layout_split(
246
- main_area,
247
- direction: :vertical,
248
- constraints: [
249
- @tui.constraint_length(1),
250
- @tui.constraint_fill(1),
251
- ]
252
- )
253
-
254
- # Render title
255
- title = @tui.paragraph(text: "List Widget - Interactive Attribute Cycling")
256
- frame.render_widget(title, title_area)
257
-
258
- # Build list first to demonstrate query methods:
259
- # - List#len (with #length, #size aliases)
260
- # - List#selection (alias for #selected_index)
261
- # - List#selected_item (returns item at selection, or nil)
262
- base_list = @tui.list(
263
- items:,
264
- selected_index: effective_selection,
265
- offset: effective_offset,
266
- style: base_style_config[:style],
267
- highlight_style: highlight_style_config[:style],
268
- highlight_symbol:,
269
- repeat_highlight_symbol: repeat_config[:repeat],
270
- highlight_spacing: spacing_config[:spacing],
271
- direction: direction_config[:direction],
272
- scroll_padding: scroll_padding_config[:padding]
273
- )
274
-
275
- # Demonstrate query methods: len, selected_index, selected_item
276
- item_count = base_list.len
277
- current_index = base_list.selected_index # Explicit name - returns index
278
- current_item = base_list.selected_item # Explicit name - returns item
279
-
280
- # Format the selected item for display (handle rich text objects)
281
- item_preview = case current_item
282
- when nil then "none"
283
- when String then (current_item.length > 12) ? "#{current_item[0..11]}…" : current_item
284
- else current_item.class.name.split("::").last # Show type for rich text
285
- end
286
-
287
- list = base_list.with(
288
- block: @tui.block(
289
- title: "#{@item_sets[@item_set_index][:name]} (len: #{item_count}) | index: #{current_index.inspect} → #{item_preview}",
290
- borders: [:all]
291
- )
292
- )
293
- frame.render_widget(list, list_area)
294
-
295
- # Render control panel
296
- control_panel = @tui.block(
297
- title: "Controls",
298
- borders: [:all],
299
- children: [
300
- @tui.paragraph(
301
- text: [
302
- @tui.text_line(spans: [
303
- @tui.text_span(content: "i", style: @hotkey_style),
304
- @tui.text_span(content: ": Items "),
305
- @tui.text_span(content: "↑/↓", style: @hotkey_style),
306
- @tui.text_span(content: ": Navigate "),
307
- @tui.text_span(content: "x", style: @hotkey_style),
308
- @tui.text_span(content: ": Select "),
309
- @tui.text_span(content: "h", style: @hotkey_style),
310
- @tui.text_span(content: ": Highlight (#{highlight_style_config[:name]})"),
311
- ]),
312
- @tui.text_line(spans: [
313
- @tui.text_span(content: "y", style: @hotkey_style),
314
- @tui.text_span(content: ": Symbol (#{highlight_symbol}) "),
315
- @tui.text_span(content: "d", style: @hotkey_style),
316
- @tui.text_span(content: ": Direction (#{direction_config[:name]})"),
317
- ]),
318
- @tui.text_line(spans: [
319
- @tui.text_span(content: "s", style: @hotkey_style),
320
- @tui.text_span(content: ": Spacing (#{spacing_config[:name]}) "),
321
- @tui.text_span(content: "p", style: @hotkey_style),
322
- @tui.text_span(content: ": Scroll Padding (#{scroll_padding_config[:name]})"),
323
- ]),
324
- @tui.text_line(spans: [
325
- @tui.text_span(content: "b", style: @hotkey_style),
326
- @tui.text_span(content: ": Base (#{base_style_config[:name]}) "),
327
- @tui.text_span(content: "r", style: @hotkey_style),
328
- @tui.text_span(content: ": Repeat (#{repeat_config[:name]})"),
329
- ]),
330
- @tui.text_line(spans: [
331
- @tui.text_span(content: "o", style: @hotkey_style),
332
- @tui.text_span(content: ": Offset Mode (#{offset_mode_config[:name]}) "),
333
- @tui.text_span(content: "q", style: @hotkey_style),
334
- @tui.text_span(content: ": Quit"),
335
- ]),
336
- ]
337
- ),
338
- ]
339
- )
340
- frame.render_widget(control_panel, control_area)
341
- end
342
- end
343
-
344
- private def handle_input # :nodoc:
345
- case @tui.poll_event
346
- in { type: :key, code: "q" } | { type: :key, code: "c", modifiers: ["ctrl"] }
347
- :quit
348
- in type: :key, code: "i"
349
- @item_set_index = (@item_set_index + 1) % @item_sets.size
350
- @selected_index = nil
351
- in type: :key, code: "up"
352
- items = @item_sets[@item_set_index][:items]
353
- @selected_index = (@selected_index || 0) - 1
354
- @selected_index = items.size - 1 if @selected_index.negative?
355
- in type: :key, code: "down"
356
- items = @item_sets[@item_set_index][:items]
357
- @selected_index = ((@selected_index || -1) + 1) % items.size
358
- in type: :key, code: "x"
359
- @selected_index = @selected_index.nil? ? 0 : nil
360
- in type: :key, code: "h"
361
- @highlight_style_index = (@highlight_style_index + 1) % @highlight_styles.size
362
- in type: :key, code: "y"
363
- @highlight_symbol_index = (@highlight_symbol_index + 1) % @highlight_symbol_names.size
364
- in type: :key, code: "d"
365
- @direction_index = (@direction_index + 1) % @direction_configs.size
366
- in type: :key, code: "s"
367
- @highlight_spacing_index = (@highlight_spacing_index + 1) % @highlight_spacing_configs.size
368
- in type: :key, code: "b"
369
- @base_style_index = (@base_style_index + 1) % @base_styles.size
370
- in type: :key, code: "r"
371
- @repeat_index = (@repeat_index + 1) % @repeat_modes.size
372
- in type: :key, code: "p"
373
- @scroll_padding_index = (@scroll_padding_index + 1) % @scroll_padding_configs.size
374
- in type: :key, code: "o"
375
- @offset_mode_index = (@offset_mode_index + 1) % @offset_modes.size
376
- else
377
- nil
378
- end
379
- end
380
- end
381
-
382
- WidgetList.new.run if __FILE__ == $PROGRAM_NAME