ratatui_ruby 0.5.0 → 0.7.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.
- checksums.yaml +4 -4
- data/.builds/ruby-3.2.yml +1 -1
- data/.builds/ruby-3.3.yml +1 -1
- data/.builds/ruby-3.4.yml +1 -1
- data/.builds/ruby-4.0.0.yml +1 -1
- data/AGENTS.md +10 -4
- data/CHANGELOG.md +79 -7
- data/README.md +37 -5
- data/REUSE.toml +2 -7
- data/doc/application_architecture.md +96 -22
- data/doc/application_testing.md +76 -30
- data/doc/contributors/architectural_overhaul/chat_conversations.md +4952 -0
- data/doc/contributors/architectural_overhaul/implementation_plan.md +60 -0
- data/doc/contributors/architectural_overhaul/task.md +37 -0
- data/doc/contributors/design/ruby_frontend.md +288 -56
- data/doc/contributors/design/rust_backend.md +349 -54
- data/doc/contributors/developing_examples.md +134 -49
- data/doc/contributors/index.md +7 -5
- data/doc/contributors/v1.0.0_blockers.md +1729 -0
- data/doc/event_handling.md +11 -3
- data/doc/images/app_all_events.png +0 -0
- data/doc/images/app_color_picker.png +0 -0
- data/doc/images/app_login_form.png +0 -0
- data/doc/images/app_stateful_interaction.png +0 -0
- data/doc/images/verify_quickstart_dsl.png +0 -0
- data/doc/images/verify_quickstart_layout.png +0 -0
- data/doc/images/verify_quickstart_lifecycle.png +0 -0
- data/doc/images/verify_readme_usage.png +0 -0
- data/doc/images/widget_barchart_demo.png +0 -0
- data/doc/images/widget_block_demo.png +0 -0
- data/doc/images/widget_canvas_demo.png +0 -0
- data/doc/images/widget_cell_demo.png +0 -0
- data/doc/images/widget_center_demo.png +0 -0
- data/doc/images/widget_chart_demo.png +0 -0
- data/doc/images/widget_list_demo.png +0 -0
- data/doc/images/widget_overlay_demo.png +0 -0
- data/doc/images/widget_render.png +0 -0
- data/doc/images/widget_rich_text.png +0 -0
- data/doc/images/widget_scroll_text.png +0 -0
- data/doc/images/widget_sparkline_demo.png +0 -0
- data/doc/images/widget_table_demo.png +0 -0
- data/doc/images/widget_tabs_demo.png +0 -0
- data/doc/images/widget_text_width.png +0 -0
- data/doc/index.md +11 -6
- data/doc/interactive_design.md +2 -2
- data/doc/quickstart.md +127 -165
- data/doc/terminal_limitations.md +92 -0
- data/doc/v0.7.0_migration.md +236 -0
- data/doc/why.md +93 -0
- data/examples/app_all_events/README.md +47 -27
- data/examples/app_all_events/app.rb +38 -35
- data/examples/app_all_events/model/app_model.rb +157 -0
- data/examples/app_all_events/model/event_entry.rb +17 -0
- data/examples/app_all_events/model/msg.rb +37 -0
- data/examples/app_all_events/update.rb +73 -0
- data/examples/app_all_events/view/app_view.rb +9 -9
- data/examples/app_all_events/view/controls_view.rb +9 -7
- data/examples/app_all_events/view/counts_view.rb +13 -9
- data/examples/app_all_events/view/live_view.rb +9 -8
- data/examples/app_all_events/view/log_view.rb +11 -16
- data/examples/app_color_picker/README.md +84 -42
- data/examples/app_color_picker/app.rb +24 -62
- data/examples/app_color_picker/controls.rb +90 -0
- data/examples/app_color_picker/copy_dialog.rb +45 -49
- data/examples/app_color_picker/export_pane.rb +126 -0
- data/examples/app_color_picker/input.rb +99 -67
- data/examples/app_color_picker/main_container.rb +178 -0
- data/examples/app_color_picker/palette.rb +55 -26
- data/examples/app_login_form/README.md +49 -0
- data/examples/app_login_form/app.rb +2 -3
- data/examples/app_stateful_interaction/README.md +33 -0
- data/examples/app_stateful_interaction/app.rb +272 -0
- data/examples/timeout_demo.rb +43 -0
- data/examples/verify_quickstart_dsl/README.md +49 -0
- data/examples/verify_quickstart_dsl/app.rb +2 -0
- data/examples/verify_quickstart_layout/README.md +71 -0
- data/examples/verify_quickstart_layout/app.rb +2 -0
- data/examples/verify_quickstart_lifecycle/README.md +56 -0
- data/examples/verify_quickstart_lifecycle/app.rb +10 -4
- data/examples/verify_readme_usage/README.md +43 -0
- data/examples/verify_readme_usage/app.rb +8 -2
- data/examples/widget_barchart_demo/README.md +50 -0
- data/examples/widget_barchart_demo/app.rb +5 -5
- data/examples/widget_block_demo/README.md +36 -0
- data/examples/widget_block_demo/app.rb +256 -0
- data/examples/widget_box_demo/README.md +45 -0
- data/examples/widget_calendar_demo/README.md +39 -0
- data/examples/widget_calendar_demo/app.rb +5 -1
- data/examples/widget_canvas_demo/README.md +27 -0
- data/examples/widget_canvas_demo/app.rb +123 -0
- data/examples/widget_cell_demo/README.md +36 -0
- data/examples/widget_cell_demo/app.rb +31 -24
- data/examples/widget_center_demo/README.md +29 -0
- data/examples/widget_center_demo/app.rb +116 -0
- data/examples/widget_chart_demo/README.md +41 -0
- data/examples/widget_chart_demo/app.rb +7 -2
- data/examples/widget_gauge_demo/README.md +41 -0
- data/examples/widget_layout_split/README.md +44 -0
- data/examples/widget_line_gauge_demo/README.md +41 -0
- data/examples/widget_list_demo/README.md +49 -0
- data/examples/widget_list_demo/app.rb +91 -107
- data/examples/widget_map_demo/README.md +39 -0
- data/examples/{app_map_demo → widget_map_demo}/app.rb +4 -4
- data/examples/widget_overlay_demo/README.md +36 -0
- data/examples/widget_overlay_demo/app.rb +248 -0
- data/examples/widget_popup_demo/README.md +36 -0
- data/examples/widget_ratatui_logo_demo/README.md +34 -0
- data/examples/widget_ratatui_logo_demo/app.rb +1 -1
- data/examples/widget_ratatui_mascot_demo/README.md +34 -0
- data/examples/widget_rect/README.md +38 -0
- data/examples/widget_render/README.md +37 -0
- data/examples/widget_render/app.rb +3 -3
- data/examples/widget_rich_text/README.md +35 -0
- data/examples/widget_rich_text/app.rb +62 -33
- data/examples/widget_scroll_text/README.md +37 -0
- data/examples/widget_scroll_text/app.rb +0 -1
- data/examples/widget_scrollbar_demo/README.md +37 -0
- data/examples/widget_sparkline_demo/README.md +42 -0
- data/examples/widget_sparkline_demo/app.rb +4 -3
- data/examples/widget_style_colors/README.md +34 -0
- data/examples/widget_table_demo/README.md +48 -0
- data/examples/{app_table_select → widget_table_demo}/app.rb +65 -12
- data/examples/widget_tabs_demo/README.md +41 -0
- data/examples/widget_tabs_demo/app.rb +15 -1
- data/examples/widget_text_width/README.md +35 -0
- data/examples/widget_text_width/app.rb +113 -0
- data/exe/.gitkeep +0 -0
- data/ext/ratatui_ruby/Cargo.lock +11 -4
- data/ext/ratatui_ruby/Cargo.toml +2 -1
- data/ext/ratatui_ruby/src/events.rs +238 -26
- data/ext/ratatui_ruby/src/frame.rs +116 -3
- data/ext/ratatui_ruby/src/lib.rs +37 -6
- data/ext/ratatui_ruby/src/rendering.rs +22 -21
- data/ext/ratatui_ruby/src/string_width.rs +101 -0
- data/ext/ratatui_ruby/src/terminal.rs +39 -15
- data/ext/ratatui_ruby/src/text.rs +13 -4
- data/ext/ratatui_ruby/src/widgets/barchart.rs +24 -6
- data/ext/ratatui_ruby/src/widgets/canvas.rs +5 -5
- data/ext/ratatui_ruby/src/widgets/gauge.rs +9 -2
- data/ext/ratatui_ruby/src/widgets/line_gauge.rs +9 -2
- data/ext/ratatui_ruby/src/widgets/list.rs +179 -3
- data/ext/ratatui_ruby/src/widgets/list_state.rs +137 -0
- data/ext/ratatui_ruby/src/widgets/mod.rs +3 -0
- data/ext/ratatui_ruby/src/widgets/scrollbar.rs +93 -1
- data/ext/ratatui_ruby/src/widgets/scrollbar_state.rs +169 -0
- data/ext/ratatui_ruby/src/widgets/table.rs +191 -34
- data/ext/ratatui_ruby/src/widgets/table_state.rs +121 -0
- data/lib/ratatui_ruby/buffer/cell.rb +168 -0
- data/lib/ratatui_ruby/buffer.rb +15 -0
- data/lib/ratatui_ruby/cell.rb +4 -4
- data/lib/ratatui_ruby/event/key/character.rb +35 -0
- data/lib/ratatui_ruby/event/key/media.rb +44 -0
- data/lib/ratatui_ruby/event/key/modifier.rb +95 -0
- data/lib/ratatui_ruby/event/key/navigation.rb +55 -0
- data/lib/ratatui_ruby/event/key/system.rb +45 -0
- data/lib/ratatui_ruby/event/key.rb +111 -51
- data/lib/ratatui_ruby/event/mouse.rb +3 -3
- data/lib/ratatui_ruby/event/paste.rb +1 -1
- data/lib/ratatui_ruby/frame.rb +100 -4
- data/lib/ratatui_ruby/layout/constraint.rb +95 -0
- data/lib/ratatui_ruby/layout/layout.rb +106 -0
- data/lib/ratatui_ruby/layout/rect.rb +118 -0
- data/lib/ratatui_ruby/layout.rb +19 -0
- data/lib/ratatui_ruby/list_state.rb +88 -0
- data/lib/ratatui_ruby/schema/bar_chart/bar.rb +2 -2
- data/lib/ratatui_ruby/schema/cursor.rb +5 -0
- data/lib/ratatui_ruby/schema/gauge.rb +3 -1
- data/lib/ratatui_ruby/schema/layout.rb +1 -1
- data/lib/ratatui_ruby/schema/line_gauge.rb +2 -2
- data/lib/ratatui_ruby/schema/list.rb +25 -4
- data/lib/ratatui_ruby/schema/list_item.rb +41 -0
- data/lib/ratatui_ruby/schema/rect.rb +43 -0
- data/lib/ratatui_ruby/schema/row.rb +66 -0
- data/lib/ratatui_ruby/schema/style.rb +24 -4
- data/lib/ratatui_ruby/schema/table.rb +29 -11
- data/lib/ratatui_ruby/schema/text.rb +96 -3
- data/lib/ratatui_ruby/scrollbar_state.rb +112 -0
- data/lib/ratatui_ruby/style/style.rb +81 -0
- data/lib/ratatui_ruby/style.rb +15 -0
- data/lib/ratatui_ruby/table_state.rb +90 -0
- data/lib/ratatui_ruby/test_helper/event_injection.rb +169 -0
- data/lib/ratatui_ruby/test_helper/snapshot.rb +414 -0
- data/lib/ratatui_ruby/test_helper/style_assertions.rb +351 -0
- data/lib/ratatui_ruby/test_helper/terminal.rb +127 -0
- data/lib/ratatui_ruby/test_helper/test_doubles.rb +68 -0
- data/lib/ratatui_ruby/test_helper.rb +65 -358
- data/lib/ratatui_ruby/tui/buffer_factories.rb +20 -0
- data/lib/ratatui_ruby/tui/canvas_factories.rb +44 -0
- data/lib/ratatui_ruby/tui/core.rb +38 -0
- data/lib/ratatui_ruby/tui/layout_factories.rb +74 -0
- data/lib/ratatui_ruby/tui/state_factories.rb +33 -0
- data/lib/ratatui_ruby/tui/style_factories.rb +20 -0
- data/lib/ratatui_ruby/tui/text_factories.rb +44 -0
- data/lib/ratatui_ruby/tui/widget_factories.rb +195 -0
- data/lib/ratatui_ruby/tui.rb +75 -0
- data/lib/ratatui_ruby/version.rb +1 -1
- data/lib/ratatui_ruby/widgets/bar_chart/bar.rb +47 -0
- data/lib/ratatui_ruby/widgets/bar_chart/bar_group.rb +25 -0
- data/lib/ratatui_ruby/widgets/bar_chart.rb +239 -0
- data/lib/ratatui_ruby/widgets/block.rb +192 -0
- data/lib/ratatui_ruby/widgets/calendar.rb +84 -0
- data/lib/ratatui_ruby/widgets/canvas.rb +231 -0
- data/lib/ratatui_ruby/widgets/cell.rb +47 -0
- data/lib/ratatui_ruby/widgets/center.rb +59 -0
- data/lib/ratatui_ruby/widgets/chart.rb +185 -0
- data/lib/ratatui_ruby/widgets/clear.rb +54 -0
- data/lib/ratatui_ruby/widgets/cursor.rb +42 -0
- data/lib/ratatui_ruby/widgets/gauge.rb +72 -0
- data/lib/ratatui_ruby/widgets/line_gauge.rb +80 -0
- data/lib/ratatui_ruby/widgets/list.rb +127 -0
- data/lib/ratatui_ruby/widgets/list_item.rb +43 -0
- data/lib/ratatui_ruby/widgets/overlay.rb +43 -0
- data/lib/ratatui_ruby/widgets/paragraph.rb +99 -0
- data/lib/ratatui_ruby/widgets/ratatui_logo.rb +31 -0
- data/lib/ratatui_ruby/widgets/ratatui_mascot.rb +36 -0
- data/lib/ratatui_ruby/widgets/row.rb +68 -0
- data/lib/ratatui_ruby/widgets/scrollbar.rb +143 -0
- data/lib/ratatui_ruby/widgets/shape/label.rb +68 -0
- data/lib/ratatui_ruby/widgets/sparkline.rb +134 -0
- data/lib/ratatui_ruby/widgets/table.rb +141 -0
- data/lib/ratatui_ruby/widgets/tabs.rb +85 -0
- data/lib/ratatui_ruby/widgets.rb +40 -0
- data/lib/ratatui_ruby.rb +64 -57
- data/sig/examples/app_all_events/view.rbs +1 -1
- data/sig/examples/app_all_events/view_state.rbs +1 -1
- data/sig/examples/app_stateful_interaction/app.rbs +33 -0
- data/sig/examples/widget_block_demo/app.rbs +32 -0
- data/sig/examples/{app_map_demo → widget_map_demo}/app.rbs +2 -2
- data/sig/examples/{app_table_select → widget_table_demo}/app.rbs +2 -2
- data/sig/examples/{widget_table_flex → widget_text_width}/app.rbs +2 -3
- data/sig/ratatui_ruby/event.rbs +11 -1
- data/sig/ratatui_ruby/frame.rbs +2 -0
- data/sig/ratatui_ruby/list_state.rbs +13 -0
- data/sig/ratatui_ruby/ratatui_ruby.rbs +2 -2
- data/sig/ratatui_ruby/schema/bar_chart/bar.rbs +3 -3
- data/sig/ratatui_ruby/schema/gauge.rbs +2 -2
- data/sig/ratatui_ruby/schema/line_gauge.rbs +2 -2
- data/sig/ratatui_ruby/schema/list.rbs +4 -2
- data/sig/ratatui_ruby/schema/list_item.rbs +10 -0
- data/sig/ratatui_ruby/schema/rect.rbs +3 -0
- data/sig/ratatui_ruby/schema/row.rbs +22 -0
- data/sig/ratatui_ruby/schema/style.rbs +3 -3
- data/sig/ratatui_ruby/schema/table.rbs +3 -1
- data/sig/ratatui_ruby/schema/text.rbs +9 -6
- data/sig/ratatui_ruby/scrollbar_state.rbs +18 -0
- data/sig/ratatui_ruby/session.rbs +41 -48
- data/sig/ratatui_ruby/table_state.rbs +15 -0
- data/sig/ratatui_ruby/test_helper/event_injection.rbs +16 -0
- data/sig/ratatui_ruby/test_helper/snapshot.rbs +12 -0
- data/sig/ratatui_ruby/test_helper/style_assertions.rbs +64 -0
- data/sig/ratatui_ruby/test_helper/terminal.rbs +14 -0
- data/sig/ratatui_ruby/test_helper/test_doubles.rbs +22 -0
- data/sig/ratatui_ruby/test_helper.rbs +5 -4
- data/sig/ratatui_ruby/tui/buffer_factories.rbs +10 -0
- data/sig/ratatui_ruby/tui/canvas_factories.rbs +14 -0
- data/sig/ratatui_ruby/tui/core.rbs +14 -0
- data/sig/ratatui_ruby/tui/layout_factories.rbs +19 -0
- data/sig/ratatui_ruby/tui/state_factories.rbs +12 -0
- data/sig/ratatui_ruby/tui/style_factories.rbs +10 -0
- data/sig/ratatui_ruby/tui/text_factories.rbs +14 -0
- data/sig/ratatui_ruby/tui/widget_factories.rbs +39 -0
- data/sig/ratatui_ruby/tui.rbs +19 -0
- data/tasks/autodoc/examples.rb +79 -0
- data/tasks/autodoc.rake +7 -35
- data/tasks/bump/changelog.rb +3 -3
- data/tasks/bump/links.rb +67 -0
- data/tasks/sourcehut.rake +64 -21
- data/tasks/terminal_preview/app_screenshot.rb +13 -3
- data/tasks/terminal_preview/saved_screenshot.rb +4 -3
- metadata +169 -48
- data/doc/contributors/dwim_dx.md +0 -366
- data/doc/images/app_analytics.png +0 -0
- data/doc/images/app_custom_widget.png +0 -0
- data/doc/images/app_mouse_events.png +0 -0
- data/doc/images/app_table_select.png +0 -0
- data/doc/images/widget_block_padding.png +0 -0
- data/doc/images/widget_block_titles.png +0 -0
- data/doc/images/widget_list_styles.png +0 -0
- data/doc/images/widget_table_flex.png +0 -0
- data/examples/app_all_events/model/events.rb +0 -180
- data/examples/app_all_events/model/highlight.rb +0 -57
- data/examples/app_all_events/test/snapshots/after_focus_lost.txt +0 -24
- data/examples/app_all_events/test/snapshots/after_focus_regained.txt +0 -24
- data/examples/app_all_events/test/snapshots/after_horizontal_resize.txt +0 -24
- data/examples/app_all_events/test/snapshots/after_key_a.txt +0 -24
- data/examples/app_all_events/test/snapshots/after_key_ctrl_x.txt +0 -24
- data/examples/app_all_events/test/snapshots/after_mouse_click.txt +0 -24
- data/examples/app_all_events/test/snapshots/after_mouse_drag.txt +0 -24
- data/examples/app_all_events/test/snapshots/after_multiple_events.txt +0 -24
- data/examples/app_all_events/test/snapshots/after_paste.txt +0 -24
- data/examples/app_all_events/test/snapshots/after_resize.txt +0 -24
- data/examples/app_all_events/test/snapshots/after_right_click.txt +0 -24
- data/examples/app_all_events/test/snapshots/after_vertical_resize.txt +0 -24
- data/examples/app_all_events/test/snapshots/initial_state.txt +0 -24
- data/examples/app_all_events/view_state.rb +0 -42
- data/examples/app_color_picker/scene.rb +0 -201
- data/examples/widget_block_padding/app.rb +0 -67
- data/examples/widget_block_titles/app.rb +0 -69
- data/examples/widget_list_styles/app.rb +0 -141
- data/examples/widget_table_flex/app.rb +0 -95
- data/lib/ratatui_ruby/session/autodoc.rb +0 -417
- data/lib/ratatui_ruby/session.rb +0 -163
- data/sig/examples/widget_block_padding/app.rbs +0 -11
- data/sig/examples/widget_block_titles/app.rbs +0 -11
- data/sig/examples/widget_list_styles/app.rbs +0 -11
- data/tasks/autodoc/inventory.rb +0 -61
- data/tasks/autodoc/notice.rb +0 -26
- data/tasks/autodoc/rbs.rb +0 -38
- data/tasks/autodoc/rdoc.rb +0 -45
- data/tasks/bump/comparison_links.rb +0 -41
- /data/doc/images/{app_map_demo.png → widget_map_demo.png} +0 -0
|
@@ -9,15 +9,19 @@ require "ratatui_ruby"
|
|
|
9
9
|
|
|
10
10
|
# A custom widget that fills its area with a checkered pattern using Cell objects.
|
|
11
11
|
class CheckeredBackground
|
|
12
|
+
def initialize(tui)
|
|
13
|
+
@tui = tui
|
|
14
|
+
end
|
|
15
|
+
|
|
12
16
|
def render(area)
|
|
13
|
-
cell =
|
|
17
|
+
cell = @tui.cell(char: "░", fg: :dark_gray)
|
|
14
18
|
commands = []
|
|
15
19
|
area.height.times do |y|
|
|
16
20
|
area.width.times do |x|
|
|
17
21
|
# Checkerboard logic
|
|
18
22
|
if (x + y).even?
|
|
19
23
|
# Use a dim cell for the background pattern
|
|
20
|
-
commands <<
|
|
24
|
+
commands << @tui.draw_cell(area.x + x, area.y + y, cell)
|
|
21
25
|
end
|
|
22
26
|
end
|
|
23
27
|
end
|
|
@@ -26,12 +30,13 @@ class CheckeredBackground
|
|
|
26
30
|
end
|
|
27
31
|
|
|
28
32
|
class WidgetCellDemo
|
|
29
|
-
def
|
|
33
|
+
def run
|
|
30
34
|
RatatuiRuby.run do |tui|
|
|
35
|
+
@tui = tui
|
|
31
36
|
# Define some reusable cells for our table
|
|
32
|
-
ok_cell =
|
|
33
|
-
fail_cell =
|
|
34
|
-
pending_cell =
|
|
37
|
+
ok_cell = @tui.cell(char: "OK", fg: :green)
|
|
38
|
+
fail_cell = @tui.cell(char: "FAIL", fg: :red, modifiers: ["bold"])
|
|
39
|
+
pending_cell = @tui.cell(char: "...", fg: :yellow, modifiers: ["dim"])
|
|
35
40
|
|
|
36
41
|
# A mix of Strings and Cells in rows
|
|
37
42
|
rows = [
|
|
@@ -39,47 +44,47 @@ class WidgetCellDemo
|
|
|
39
44
|
["Cache", ok_cell],
|
|
40
45
|
["Worker", fail_cell],
|
|
41
46
|
["Analytics", pending_cell],
|
|
42
|
-
["Web Server",
|
|
47
|
+
["Web Server", @tui.cell(char: "RESTARTING", fg: :blue, modifiers: ["rapid_blink"])],
|
|
43
48
|
]
|
|
44
49
|
|
|
45
|
-
table =
|
|
46
|
-
header: ["Service",
|
|
50
|
+
table = @tui.table(
|
|
51
|
+
header: ["Service", @tui.cell(char: "Status", modifiers: ["underlined"])],
|
|
47
52
|
rows:,
|
|
48
53
|
widths: [
|
|
49
|
-
|
|
50
|
-
|
|
54
|
+
@tui.constraint_percentage(70),
|
|
55
|
+
@tui.constraint_percentage(30),
|
|
51
56
|
],
|
|
52
|
-
block:
|
|
57
|
+
block: @tui.block(title: "System Status", borders: :all),
|
|
53
58
|
column_spacing: 1
|
|
54
59
|
)
|
|
55
60
|
|
|
56
61
|
# Main loop
|
|
57
62
|
loop do
|
|
58
|
-
tui.draw do |frame|
|
|
63
|
+
@tui.draw do |frame|
|
|
59
64
|
# Create a layout that holds both widgets
|
|
60
65
|
# We use a vertical layout:
|
|
61
66
|
# Top: Custom CheckeredBackground with specific height
|
|
62
67
|
# Bottom: Table using remaining space
|
|
63
|
-
top_area, bottom_area =
|
|
68
|
+
top_area, bottom_area = @tui.layout_split(
|
|
64
69
|
frame.area,
|
|
65
70
|
direction: :vertical,
|
|
66
71
|
constraints: [
|
|
67
|
-
|
|
68
|
-
|
|
72
|
+
@tui.constraint_length(10), # Top section
|
|
73
|
+
@tui.constraint_min(0), # Bottom section
|
|
69
74
|
]
|
|
70
75
|
)
|
|
71
76
|
|
|
72
77
|
# Top Child: An Overlay of Paragraph on top of CheckeredBackground
|
|
73
|
-
overlay =
|
|
78
|
+
overlay = @tui.overlay(
|
|
74
79
|
layers: [
|
|
75
|
-
CheckeredBackground.new,
|
|
76
|
-
|
|
80
|
+
CheckeredBackground.new(@tui),
|
|
81
|
+
@tui.center(
|
|
77
82
|
width_percent: 50,
|
|
78
83
|
height_percent: 50,
|
|
79
|
-
child:
|
|
84
|
+
child: @tui.paragraph(
|
|
80
85
|
text: "Custom Widget Demo\n(CheckeredBackground)",
|
|
81
86
|
alignment: :center,
|
|
82
|
-
block:
|
|
87
|
+
block: @tui.block(borders: :all, title: "Overlay")
|
|
83
88
|
)
|
|
84
89
|
),
|
|
85
90
|
]
|
|
@@ -90,9 +95,11 @@ class WidgetCellDemo
|
|
|
90
95
|
frame.render_widget(table, bottom_area)
|
|
91
96
|
end
|
|
92
97
|
|
|
93
|
-
|
|
94
|
-
|
|
98
|
+
case @tui.poll_event
|
|
99
|
+
in { type: :key, code: "q" } | { type: :key, code: "c", modifiers: ["ctrl"] }
|
|
95
100
|
break
|
|
101
|
+
else
|
|
102
|
+
nil
|
|
96
103
|
end
|
|
97
104
|
end
|
|
98
105
|
end
|
|
@@ -100,5 +107,5 @@ class WidgetCellDemo
|
|
|
100
107
|
end
|
|
101
108
|
|
|
102
109
|
if __FILE__ == $0
|
|
103
|
-
WidgetCellDemo.new.
|
|
110
|
+
WidgetCellDemo.new.run
|
|
104
111
|
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# Center Widget Demo
|
|
2
|
+
|
|
3
|
+
[](app.rb)
|
|
4
|
+
|
|
5
|
+
<!--
|
|
6
|
+
SPDX-FileCopyrightText: 2025 Kerrick Long <me@kerricklong.com>
|
|
7
|
+
SPDX-License-Identifier: CC-BY-SA-4.0
|
|
8
|
+
-->
|
|
9
|
+
|
|
10
|
+
This example demonstrates the `Center` widget, which positions a child widget in the center of the available area.
|
|
11
|
+
|
|
12
|
+
## Key Concepts
|
|
13
|
+
|
|
14
|
+
- **Centering**: The widget automatically calculates the necessary padding to center its child.
|
|
15
|
+
- **Sizing**: You can control the size of the centered area using `width_percent` and `height_percent`.
|
|
16
|
+
- **Composition**: The `Center` widget wraps another widget (the child), making it easy to compose layouts.
|
|
17
|
+
|
|
18
|
+
## Controls
|
|
19
|
+
|
|
20
|
+
| Key | Action |
|
|
21
|
+
| --- | --- |
|
|
22
|
+
| `←` / `→` | Decrease / Increase width percentage |
|
|
23
|
+
| `↑` / `↓` | Increase / Decrease height percentage |
|
|
24
|
+
| `q` | Quit |
|
|
25
|
+
|
|
26
|
+
## Screenshot
|
|
27
|
+
## Source Code
|
|
28
|
+
|
|
29
|
+
- [app.rb](app.rb)
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# SPDX-FileCopyrightText: 2025 Kerrick Long <me@kerricklong.com>
|
|
4
|
+
# SPDX-License-Identifier: AGPL-3.0-or-later
|
|
5
|
+
|
|
6
|
+
$LOAD_PATH.unshift File.expand_path("../../lib", __dir__)
|
|
7
|
+
require "ratatui_ruby"
|
|
8
|
+
|
|
9
|
+
# Demo: Center Widget
|
|
10
|
+
# Demonstrates how to center content horizontally and vertically
|
|
11
|
+
# with adjustable width/height percentages.
|
|
12
|
+
class WidgetCenterDemo
|
|
13
|
+
def initialize
|
|
14
|
+
@width_percent = 50
|
|
15
|
+
@height_percent = 50
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def run
|
|
19
|
+
RatatuiRuby.run do |tui|
|
|
20
|
+
@tui = tui
|
|
21
|
+
loop do
|
|
22
|
+
render
|
|
23
|
+
break if handle_input == :quit
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
private def render
|
|
29
|
+
@tui.draw do |frame|
|
|
30
|
+
layout = @tui.layout_split(
|
|
31
|
+
frame.area,
|
|
32
|
+
direction: :vertical,
|
|
33
|
+
constraints: [
|
|
34
|
+
@tui.constraint_fill(1),
|
|
35
|
+
@tui.constraint_length(3),
|
|
36
|
+
]
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
# 1. Main Area
|
|
40
|
+
# Background block frames the centered content
|
|
41
|
+
bg_block = @tui.block(
|
|
42
|
+
title: "Center Widget Demo",
|
|
43
|
+
borders: [:all],
|
|
44
|
+
style: @tui.style(fg: :gray)
|
|
45
|
+
)
|
|
46
|
+
frame.render_widget(bg_block, layout[0])
|
|
47
|
+
|
|
48
|
+
# 2. Centered Content
|
|
49
|
+
# The content itself is just a block with some text
|
|
50
|
+
content = @tui.paragraph(
|
|
51
|
+
text: [
|
|
52
|
+
@tui.text_line(
|
|
53
|
+
spans: [
|
|
54
|
+
@tui.text_span(content: "Centered Area", style: @tui.style(modifiers: [:bold])),
|
|
55
|
+
],
|
|
56
|
+
alignment: :center
|
|
57
|
+
),
|
|
58
|
+
@tui.text_line(spans: []),
|
|
59
|
+
@tui.text_line(spans: [@tui.text_span(content: "Width: #{@width_percent}%", style: @tui.style(fg: :cyan))], alignment: :center),
|
|
60
|
+
@tui.text_line(spans: [@tui.text_span(content: "Height: #{@height_percent}%", style: @tui.style(fg: :magenta))], alignment: :center),
|
|
61
|
+
],
|
|
62
|
+
block: @tui.block(
|
|
63
|
+
title: "Child Widget",
|
|
64
|
+
borders: [:all],
|
|
65
|
+
style: @tui.style(fg: :white)
|
|
66
|
+
),
|
|
67
|
+
alignment: :center
|
|
68
|
+
)
|
|
69
|
+
|
|
70
|
+
# Create the Center widget
|
|
71
|
+
center_widget = @tui.center(
|
|
72
|
+
child: content,
|
|
73
|
+
width_percent: @width_percent,
|
|
74
|
+
height_percent: @height_percent
|
|
75
|
+
)
|
|
76
|
+
|
|
77
|
+
# Render center widget into the main layout area
|
|
78
|
+
frame.render_widget(center_widget, layout[0])
|
|
79
|
+
|
|
80
|
+
# 3. Controls
|
|
81
|
+
control_text = @tui.paragraph(
|
|
82
|
+
text: [
|
|
83
|
+
@tui.text_line(spans: [
|
|
84
|
+
@tui.text_span(content: "←/→", style: @tui.style(modifiers: [:bold, :underlined])),
|
|
85
|
+
@tui.text_span(content: ": Width "),
|
|
86
|
+
@tui.text_span(content: "↑/↓", style: @tui.style(modifiers: [:bold, :underlined])),
|
|
87
|
+
@tui.text_span(content: ": Height "),
|
|
88
|
+
@tui.text_span(content: "q", style: @tui.style(modifiers: [:bold, :underlined])),
|
|
89
|
+
@tui.text_span(content: ": Quit"),
|
|
90
|
+
]),
|
|
91
|
+
],
|
|
92
|
+
block: @tui.block(borders: [:top], style: @tui.style(bg: :black))
|
|
93
|
+
)
|
|
94
|
+
frame.render_widget(control_text, layout[1])
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
def handle_input
|
|
99
|
+
case @tui.poll_event
|
|
100
|
+
in { type: :key, code: "q" } | { type: :key, code: "c", modifiers: ["ctrl"] }
|
|
101
|
+
:quit
|
|
102
|
+
in { type: :key, code: "left" }
|
|
103
|
+
@width_percent = [@width_percent - 5, 5].max
|
|
104
|
+
in { type: :key, code: "right" }
|
|
105
|
+
@width_percent = [@width_percent + 5, 100].min
|
|
106
|
+
in { type: :key, code: "up" }
|
|
107
|
+
@height_percent = [@height_percent + 5, 100].min
|
|
108
|
+
in { type: :key, code: "down" }
|
|
109
|
+
@height_percent = [@height_percent - 5, 5].max
|
|
110
|
+
else
|
|
111
|
+
# Ignore other events
|
|
112
|
+
end
|
|
113
|
+
end
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
WidgetCenterDemo.new.run if __FILE__ == $0
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
SPDX-FileCopyrightText: 2026 Kerrick Long <me@kerricklong.com>
|
|
3
|
+
SPDX-License-Identifier: CC-BY-SA-4.0
|
|
4
|
+
-->
|
|
5
|
+
|
|
6
|
+
# Chart Widget Example
|
|
7
|
+
|
|
8
|
+
[](app.rb)
|
|
9
|
+
|
|
10
|
+
Demonstrates Cartesian plotting with interactive styling and configuration.
|
|
11
|
+
|
|
12
|
+
Trends and patterns are invisible in raw logs. Charts visualize X/Y datasets to reveal the story behind the data.
|
|
13
|
+
|
|
14
|
+
## Features Demonstrated
|
|
15
|
+
|
|
16
|
+
- **Dataset Types**: Line charts and Scatter plots.
|
|
17
|
+
- **Markers**: Braille patterns, dots, blocks, and bars.
|
|
18
|
+
- **Axis Configuration**: Controlling labels, bounds, and alignment (Left/Center/Right).
|
|
19
|
+
- **Legend**: Positioning the legend in any of the four corners or hiding it based on constraints.
|
|
20
|
+
|
|
21
|
+
## Hotkeys
|
|
22
|
+
|
|
23
|
+
- **m**: Cycle Marker Type (`marker`)
|
|
24
|
+
- **s**: Cycle Dataset Style (`style`)
|
|
25
|
+
- **x**: Cycle X-Axis Alignment (`labels_alignment`)
|
|
26
|
+
- **y**: Cycle Y-Axis Alignment (`labels_alignment`)
|
|
27
|
+
- **l**: Cycle Legend Position (`legend_position`)
|
|
28
|
+
- **q**: Quit
|
|
29
|
+
|
|
30
|
+
## Usage
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
ruby examples/widget_chart_demo/app.rb
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Learning Outcomes
|
|
37
|
+
|
|
38
|
+
Use this example if you need to...
|
|
39
|
+
- Plot real-time data monitoring (CPU history, request latency).
|
|
40
|
+
- Visualize mathematical functions.
|
|
41
|
+
- Compare multiple datasets on the same axis.
|
|
@@ -53,6 +53,11 @@ class WidgetChartDemo
|
|
|
53
53
|
@tui = tui
|
|
54
54
|
init_styles
|
|
55
55
|
|
|
56
|
+
# Support seeded random for deterministic testing
|
|
57
|
+
# Set RATA_SEED=42 for reproducible scatter plot data
|
|
58
|
+
seed = ENV.fetch("RATA_SEED", nil)
|
|
59
|
+
@rng = seed ? Random.new(seed.to_i) : Random.new
|
|
60
|
+
|
|
56
61
|
@marker_index = 0
|
|
57
62
|
@dataset_style_index = 0
|
|
58
63
|
@x_alignment_index = 1
|
|
@@ -89,9 +94,9 @@ class WidgetChartDemo
|
|
|
89
94
|
[x, Math.sin(x)]
|
|
90
95
|
end
|
|
91
96
|
|
|
92
|
-
# Scatter: Random points
|
|
97
|
+
# Scatter: Random points (deterministic when RATA_SEED is set)
|
|
93
98
|
scatter_data = (0..20).map do |_|
|
|
94
|
-
[rand(0.0..10.0), rand(-1.0..1.0)]
|
|
99
|
+
[@rng.rand(0.0..10.0), @rng.rand(-1.0..1.0)]
|
|
95
100
|
end
|
|
96
101
|
|
|
97
102
|
style = @dataset_styles[@dataset_style_index][:style]
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
SPDX-FileCopyrightText: 2026 Kerrick Long <me@kerricklong.com>
|
|
3
|
+
SPDX-License-Identifier: CC-BY-SA-4.0
|
|
4
|
+
-->
|
|
5
|
+
|
|
6
|
+
# Gauge Widget Example
|
|
7
|
+
|
|
8
|
+
[](app.rb)
|
|
9
|
+
|
|
10
|
+
Demonstrates progress bars with interactive configuration.
|
|
11
|
+
|
|
12
|
+
Long-running tasks create anxiety. Users need to know the system is working. Gauges provide visual feedback on completion status.
|
|
13
|
+
|
|
14
|
+
## Features Demonstrated
|
|
15
|
+
|
|
16
|
+
- **Progress styles**: standard block characters or Unicode bars.
|
|
17
|
+
- **Labels**: Customizing the text overlay (Percentage, Ratio, etc.).
|
|
18
|
+
- **Styling**: Independent control of the filled gauge color and the background track.
|
|
19
|
+
- **Thresholds**: Implementing multi-colored gauges based on values.
|
|
20
|
+
|
|
21
|
+
## Hotkeys
|
|
22
|
+
|
|
23
|
+
- **Arrows (←/→)**: Adjust Ratio (`ratio`)
|
|
24
|
+
- **g**: Cycle Gauge Color (`gauge_style`)
|
|
25
|
+
- **b**: Cycle Background Style (`style`)
|
|
26
|
+
- **u**: Toggle Unicode Mode (`use_unicode`)
|
|
27
|
+
- **l**: Cycle Label Mode (`label`)
|
|
28
|
+
- **q**: Quit
|
|
29
|
+
|
|
30
|
+
## Usage
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
ruby examples/widget_gauge_demo/app.rb
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Learning Outcomes
|
|
37
|
+
|
|
38
|
+
Use this example if you need to...
|
|
39
|
+
- Show download or upload progress.
|
|
40
|
+
- Visualize resource quotas (disk space, memory usage).
|
|
41
|
+
- Create "health bars" or status indicators.
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
SPDX-FileCopyrightText: 2026 Kerrick Long <me@kerricklong.com>
|
|
3
|
+
SPDX-License-Identifier: CC-BY-SA-4.0
|
|
4
|
+
-->
|
|
5
|
+
|
|
6
|
+
# Layout Split Example
|
|
7
|
+
|
|
8
|
+
[](app.rb)
|
|
9
|
+
|
|
10
|
+
Demonstrates dynamic geometry management with constraints and flex modes.
|
|
11
|
+
|
|
12
|
+
Terminal screens vary in size. Hardcoded layouts break. `Layout.split` manages space dynamically, ensuring your interface adapts to any window dimension.
|
|
13
|
+
|
|
14
|
+
## Features Demonstrated
|
|
15
|
+
|
|
16
|
+
- **Constraints**:
|
|
17
|
+
- `Fill(n)`: Takes available space proportional to `n`.
|
|
18
|
+
- `Length(n)`: Fixed number of cells.
|
|
19
|
+
- `Percentage(n)`: Percentage of the parent area.
|
|
20
|
+
- `Min(n)`: At least `n` cells.
|
|
21
|
+
- `Ratio(x, y)`: `x/y` of the parent area.
|
|
22
|
+
- **Flex Modes**: Controlling how extra space is distributed (`Start`, `End`, `Center`, `SpaceBetween`, etc.).
|
|
23
|
+
- **Direction**: Splitting Vertically vs Horizontally.
|
|
24
|
+
|
|
25
|
+
## Hotkeys
|
|
26
|
+
|
|
27
|
+
- **d**: Toggle Direction (`direction`)
|
|
28
|
+
- **f**: Cycle Flex Mode (`flex`)
|
|
29
|
+
- **c**: Cycle Constraint Set (`constraints`)
|
|
30
|
+
- **q**: Quit
|
|
31
|
+
|
|
32
|
+
## Usage
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
ruby examples/widget_layout_split/app.rb
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Learning Outcomes
|
|
39
|
+
|
|
40
|
+
Use this example if you need to...
|
|
41
|
+
- Build responsive dashboards.
|
|
42
|
+
- Create 3-column layouts where the middle content fills remaining space.
|
|
43
|
+
- Center a modal dialog on the screen.
|
|
44
|
+
- Distribute buttons evenly across a control bar.
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
SPDX-FileCopyrightText: 2026 Kerrick Long <me@kerricklong.com>
|
|
3
|
+
SPDX-License-Identifier: CC-BY-SA-4.0
|
|
4
|
+
-->
|
|
5
|
+
|
|
6
|
+
# Line Gauge Widget Example
|
|
7
|
+
|
|
8
|
+
[](app.rb)
|
|
9
|
+
|
|
10
|
+
Demonstrates compact progress bars for constrained spaces.
|
|
11
|
+
|
|
12
|
+
Standard block gauges take up vertical space. Sometimes you only have one line to show status. The `LineGauge` provides a compact, high-density progress indicator.
|
|
13
|
+
|
|
14
|
+
## Features Demonstrated
|
|
15
|
+
|
|
16
|
+
- **Compact Rendering**: Visualizing progress in a single character height.
|
|
17
|
+
- **Custom Symbols**: Replacing the standard line with Blocks, Shades, Dashes, or ASCII characters.
|
|
18
|
+
- **Styling**: Independent styling for the filled (progress) and unfilled (track) portions.
|
|
19
|
+
|
|
20
|
+
## Hotkeys
|
|
21
|
+
|
|
22
|
+
- **Arrows (←/→)**: Adjust Ratio (`ratio`)
|
|
23
|
+
- **f**: Cycle Filled Symbol (`filled_symbol`)
|
|
24
|
+
- **u**: Cycle Unfilled Symbol (`unfilled_symbol`)
|
|
25
|
+
- **c**: Cycle Filled Color (`filled_style`)
|
|
26
|
+
- **x**: Cycle Unfilled Color (`unfilled_style`)
|
|
27
|
+
- **b**: Cycle Base Style (`style`)
|
|
28
|
+
- **q**: Cycle Quit
|
|
29
|
+
|
|
30
|
+
## Usage
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
ruby examples/widget_line_gauge_demo/app.rb
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Learning Outcomes
|
|
37
|
+
|
|
38
|
+
Use this example if you need to...
|
|
39
|
+
- Add a progress bar to a list item or table row.
|
|
40
|
+
- Create a status line at the bottom of the screen.
|
|
41
|
+
- Show multiple metrics (CPU, RAM, Net) in a compact list.
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
SPDX-FileCopyrightText: 2026 Kerrick Long <me@kerricklong.com>
|
|
3
|
+
SPDX-License-Identifier: CC-BY-SA-4.0
|
|
4
|
+
-->
|
|
5
|
+
|
|
6
|
+
# List Widget Example
|
|
7
|
+
|
|
8
|
+
[](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
|
+
```bash
|
|
40
|
+
ruby examples/widget_list_demo/app.rb
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Learning Outcomes
|
|
44
|
+
|
|
45
|
+
Use this example if you need to...
|
|
46
|
+
- Create a file explorer.
|
|
47
|
+
- Build a navigation menu.
|
|
48
|
+
- Display a log where users can scroll back to read history.
|
|
49
|
+
- Implement "infinite select" behaviors.
|