ratatui_ruby 0.4.0 → 0.5.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 +87 -171
- data/CHANGELOG.md +38 -1
- data/README.md +8 -3
- data/REUSE.toml +20 -0
- data/doc/application_architecture.md +105 -45
- data/doc/application_testing.md +5 -3
- data/doc/contributors/design/ruby_frontend.md +9 -5
- data/doc/contributors/developing_examples.md +76 -18
- data/doc/contributors/documentation_style.md +7 -0
- data/doc/contributors/index.md +2 -0
- data/doc/event_handling.md +10 -4
- data/doc/images/app_all_events.png +0 -0
- data/doc/images/app_color_picker.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_padding.png +0 -0
- data/doc/images/widget_block_titles.png +0 -0
- data/doc/images/widget_box_demo.png +0 -0
- data/doc/images/widget_calendar_demo.png +0 -0
- data/doc/images/widget_cell_demo.png +0 -0
- data/doc/images/widget_chart_demo.png +0 -0
- data/doc/images/widget_gauge_demo.png +0 -0
- data/doc/images/widget_layout_split.png +0 -0
- data/doc/images/widget_line_gauge_demo.png +0 -0
- data/doc/images/widget_list_demo.png +0 -0
- data/doc/images/widget_ratatui_logo_demo.png +0 -0
- data/doc/images/widget_ratatui_mascot_demo.png +0 -0
- data/doc/images/widget_render.png +0 -0
- data/doc/images/widget_scrollbar_demo.png +0 -0
- data/doc/images/widget_sparkline_demo.png +0 -0
- data/doc/images/widget_style_colors.png +0 -0
- data/doc/images/widget_table_flex.png +0 -0
- data/doc/images/widget_tabs_demo.png +0 -0
- data/doc/interactive_design.md +25 -30
- data/doc/quickstart.md +147 -120
- data/examples/app_all_events/README.md +81 -0
- data/examples/app_all_events/app.rb +93 -0
- data/examples/app_all_events/model/event_color_cycle.rb +41 -0
- data/examples/app_all_events/model/event_entry.rb +75 -0
- data/examples/app_all_events/model/events.rb +180 -0
- data/examples/app_all_events/model/highlight.rb +57 -0
- data/examples/app_all_events/model/timestamp.rb +54 -0
- data/examples/app_all_events/test/snapshots/after_focus_lost.txt +24 -0
- data/examples/app_all_events/test/snapshots/after_focus_regained.txt +24 -0
- data/examples/app_all_events/test/snapshots/after_horizontal_resize.txt +24 -0
- data/examples/app_all_events/test/snapshots/after_key_a.txt +24 -0
- data/examples/app_all_events/test/snapshots/after_key_ctrl_x.txt +24 -0
- data/examples/app_all_events/test/snapshots/after_mouse_click.txt +24 -0
- data/examples/app_all_events/test/snapshots/after_mouse_drag.txt +24 -0
- data/examples/app_all_events/test/snapshots/after_multiple_events.txt +24 -0
- data/examples/app_all_events/test/snapshots/after_paste.txt +24 -0
- data/examples/app_all_events/test/snapshots/after_resize.txt +24 -0
- data/examples/app_all_events/test/snapshots/after_right_click.txt +24 -0
- data/examples/app_all_events/test/snapshots/after_vertical_resize.txt +24 -0
- data/examples/app_all_events/test/snapshots/initial_state.txt +24 -0
- data/examples/app_all_events/view/app_view.rb +78 -0
- data/examples/app_all_events/view/controls_view.rb +50 -0
- data/examples/app_all_events/view/counts_view.rb +55 -0
- data/examples/app_all_events/view/live_view.rb +69 -0
- data/examples/app_all_events/view/log_view.rb +60 -0
- data/examples/app_all_events/view.rb +7 -0
- data/examples/app_all_events/view_state.rb +42 -0
- data/examples/app_color_picker/README.md +94 -0
- data/examples/app_color_picker/app.rb +112 -0
- data/examples/app_color_picker/clipboard.rb +84 -0
- data/examples/app_color_picker/color.rb +191 -0
- data/examples/app_color_picker/copy_dialog.rb +170 -0
- data/examples/app_color_picker/harmony.rb +56 -0
- data/examples/app_color_picker/input.rb +142 -0
- data/examples/app_color_picker/palette.rb +80 -0
- data/examples/app_color_picker/scene.rb +201 -0
- data/examples/{login_form → app_login_form}/app.rb +39 -42
- data/examples/{map_demo → app_map_demo}/app.rb +24 -21
- data/examples/{table_select → app_table_select}/app.rb +68 -65
- data/examples/{quickstart_dsl → verify_quickstart_dsl}/app.rb +15 -6
- data/examples/verify_quickstart_layout/app.rb +69 -0
- data/examples/{quickstart_lifecycle → verify_quickstart_lifecycle}/app.rb +19 -10
- data/examples/verify_readme_usage/app.rb +34 -0
- data/examples/widget_barchart_demo/app.rb +238 -0
- data/examples/{block_padding → widget_block_padding}/app.rb +17 -13
- data/examples/{block_titles → widget_block_titles}/app.rb +25 -17
- data/examples/{box_demo → widget_box_demo}/app.rb +99 -65
- data/examples/widget_calendar_demo/app.rb +109 -0
- data/examples/widget_cell_demo/app.rb +104 -0
- data/examples/widget_chart_demo/app.rb +213 -0
- data/examples/widget_gauge_demo/app.rb +212 -0
- data/examples/widget_layout_split/app.rb +246 -0
- data/examples/widget_line_gauge_demo/app.rb +217 -0
- data/examples/widget_list_demo/app.rb +382 -0
- data/examples/widget_list_styles/app.rb +141 -0
- data/examples/widget_popup_demo/app.rb +104 -0
- data/examples/widget_ratatui_logo_demo/app.rb +103 -0
- data/examples/widget_ratatui_mascot_demo/app.rb +93 -0
- data/examples/widget_rect/app.rb +205 -0
- data/examples/widget_render/app.rb +184 -0
- data/examples/widget_rich_text/app.rb +137 -0
- data/examples/widget_scroll_text/app.rb +108 -0
- data/examples/widget_scrollbar_demo/app.rb +153 -0
- data/examples/widget_sparkline_demo/app.rb +274 -0
- data/examples/widget_style_colors/app.rb +19 -21
- data/examples/widget_table_flex/app.rb +95 -0
- data/examples/widget_tabs_demo/app.rb +167 -0
- data/ext/ratatui_ruby/Cargo.lock +1 -1
- data/ext/ratatui_ruby/Cargo.toml +1 -1
- data/ext/ratatui_ruby/src/events.rs +121 -36
- data/ext/ratatui_ruby/src/frame.rs +115 -0
- data/ext/ratatui_ruby/src/lib.rs +79 -26
- data/ext/ratatui_ruby/src/rendering.rs +8 -4
- data/ext/ratatui_ruby/src/style.rs +138 -57
- data/ext/ratatui_ruby/src/terminal.rs +5 -9
- data/ext/ratatui_ruby/src/text.rs +13 -6
- data/ext/ratatui_ruby/src/widgets/barchart.rs +56 -54
- data/ext/ratatui_ruby/src/widgets/block.rs +7 -6
- data/ext/ratatui_ruby/src/widgets/canvas.rs +21 -3
- data/ext/ratatui_ruby/src/widgets/chart.rs +20 -10
- data/ext/ratatui_ruby/src/widgets/layout.rs +9 -4
- data/ext/ratatui_ruby/src/widgets/list.rs +32 -9
- data/ext/ratatui_ruby/src/widgets/overlay.rs +2 -1
- data/ext/ratatui_ruby/src/widgets/paragraph.rs +1 -1
- data/ext/ratatui_ruby/src/widgets/ratatui_logo.rs +19 -8
- data/ext/ratatui_ruby/src/widgets/ratatui_mascot.rs +17 -10
- data/ext/ratatui_ruby/src/widgets/scrollbar.rs +4 -2
- data/ext/ratatui_ruby/src/widgets/sparkline.rs +14 -11
- data/ext/ratatui_ruby/src/widgets/table.rs +8 -4
- data/ext/ratatui_ruby/src/widgets/tabs.rs +11 -11
- data/lib/ratatui_ruby/cell.rb +3 -3
- data/lib/ratatui_ruby/event/key.rb +1 -1
- data/lib/ratatui_ruby/event/none.rb +43 -0
- data/lib/ratatui_ruby/event.rb +56 -4
- data/lib/ratatui_ruby/frame.rb +87 -0
- data/lib/ratatui_ruby/schema/bar_chart/bar.rb +11 -11
- data/lib/ratatui_ruby/schema/bar_chart/bar_group.rb +1 -5
- data/lib/ratatui_ruby/schema/bar_chart.rb +217 -217
- data/lib/ratatui_ruby/schema/block.rb +163 -168
- data/lib/ratatui_ruby/schema/calendar.rb +66 -67
- data/lib/ratatui_ruby/schema/canvas.rb +63 -63
- data/lib/ratatui_ruby/schema/center.rb +46 -46
- data/lib/ratatui_ruby/schema/chart.rb +135 -143
- data/lib/ratatui_ruby/schema/clear.rb +42 -42
- data/lib/ratatui_ruby/schema/constraint.rb +76 -76
- data/lib/ratatui_ruby/schema/cursor.rb +25 -25
- data/lib/ratatui_ruby/schema/gauge.rb +53 -53
- data/lib/ratatui_ruby/schema/layout.rb +87 -87
- data/lib/ratatui_ruby/schema/line_gauge.rb +62 -62
- data/lib/ratatui_ruby/schema/list.rb +86 -84
- data/lib/ratatui_ruby/schema/overlay.rb +31 -31
- data/lib/ratatui_ruby/schema/paragraph.rb +80 -80
- data/lib/ratatui_ruby/schema/ratatui_logo.rb +10 -6
- data/lib/ratatui_ruby/schema/ratatui_mascot.rb +10 -5
- data/lib/ratatui_ruby/schema/rect.rb +60 -60
- data/lib/ratatui_ruby/schema/scrollbar.rb +119 -119
- data/lib/ratatui_ruby/schema/shape/label.rb +1 -1
- data/lib/ratatui_ruby/schema/sparkline.rb +111 -110
- data/lib/ratatui_ruby/schema/style.rb +46 -46
- data/lib/ratatui_ruby/schema/table.rb +112 -119
- data/lib/ratatui_ruby/schema/tabs.rb +66 -67
- data/lib/ratatui_ruby/session/autodoc.rb +417 -0
- data/lib/ratatui_ruby/session.rb +40 -23
- data/lib/ratatui_ruby/test_helper.rb +185 -19
- data/lib/ratatui_ruby/version.rb +1 -1
- data/lib/ratatui_ruby.rb +65 -39
- data/{examples/sparkline_demo → sig/examples/app_all_events}/app.rbs +3 -2
- data/sig/examples/app_all_events/model/event_entry.rbs +16 -0
- data/sig/examples/app_all_events/model/events.rbs +15 -0
- data/sig/examples/app_all_events/model/timestamp.rbs +11 -0
- data/sig/examples/app_all_events/view/app_view.rbs +8 -0
- data/sig/examples/app_all_events/view/controls_view.rbs +6 -0
- data/sig/examples/app_all_events/view/counts_view.rbs +6 -0
- data/sig/examples/app_all_events/view/live_view.rbs +6 -0
- data/sig/examples/app_all_events/view/log_view.rbs +6 -0
- data/sig/examples/app_all_events/view.rbs +8 -0
- data/sig/examples/app_all_events/view_state.rbs +15 -0
- data/{examples/list_demo → sig/examples/app_color_picker}/app.rbs +2 -2
- data/sig/examples/app_login_form/app.rbs +11 -0
- data/sig/examples/app_map_demo/app.rbs +11 -0
- data/sig/examples/app_table_select/app.rbs +11 -0
- data/sig/examples/verify_quickstart_dsl/app.rbs +11 -0
- data/sig/examples/verify_quickstart_lifecycle/app.rbs +11 -0
- data/sig/examples/verify_readme_usage/app.rbs +11 -0
- data/sig/examples/widget_block_padding/app.rbs +11 -0
- data/sig/examples/widget_block_titles/app.rbs +11 -0
- data/sig/examples/widget_box_demo/app.rbs +11 -0
- data/sig/examples/widget_calendar_demo/app.rbs +11 -0
- data/sig/examples/widget_cell_demo/app.rbs +11 -0
- data/sig/examples/widget_chart_demo/app.rbs +11 -0
- data/{examples/gauge_demo → sig/examples/widget_gauge_demo}/app.rbs +4 -0
- data/sig/examples/widget_layout_split/app.rbs +10 -0
- data/sig/examples/widget_line_gauge_demo/app.rbs +11 -0
- data/sig/examples/widget_list_demo/app.rbs +12 -0
- data/sig/examples/widget_list_styles/app.rbs +11 -0
- data/sig/examples/widget_popup_demo/app.rbs +11 -0
- data/sig/examples/widget_ratatui_logo_demo/app.rbs +11 -0
- data/sig/examples/widget_ratatui_mascot_demo/app.rbs +11 -0
- data/sig/examples/widget_rect/app.rbs +12 -0
- data/sig/examples/widget_render/app.rbs +10 -0
- data/sig/examples/widget_rich_text/app.rbs +11 -0
- data/sig/examples/widget_scroll_text/app.rbs +11 -0
- data/sig/examples/widget_scrollbar_demo/app.rbs +11 -0
- data/sig/examples/widget_sparkline_demo/app.rbs +10 -0
- data/{examples → sig/examples}/widget_style_colors/app.rbs +1 -1
- data/sig/examples/widget_table_flex/app.rbs +11 -0
- data/sig/ratatui_ruby/frame.rbs +9 -0
- data/sig/ratatui_ruby/ratatui_ruby.rbs +3 -2
- data/sig/ratatui_ruby/schema/draw.rbs +4 -0
- data/sig/ratatui_ruby/schema/layout.rbs +1 -1
- data/sig/ratatui_ruby/session.rbs +94 -0
- data/tasks/autodoc/inventory.rb +61 -0
- data/tasks/autodoc/member.rb +56 -0
- data/tasks/autodoc/name.rb +19 -0
- data/tasks/autodoc/notice.rb +26 -0
- data/tasks/autodoc/rbs.rb +38 -0
- data/tasks/autodoc/rdoc.rb +45 -0
- data/tasks/autodoc.rake +47 -0
- data/tasks/bump/history.rb +2 -2
- data/tasks/doc.rake +600 -6
- data/tasks/example_viewer.html.erb +172 -0
- data/tasks/lint.rake +8 -4
- data/tasks/resources/index.html.erb +6 -0
- data/tasks/sourcehut.rake +4 -4
- data/tasks/terminal_preview/app_screenshot.rb +1 -3
- data/tasks/terminal_preview/crash_report.rb +7 -9
- data/tasks/terminal_preview/launcher_script.rb +4 -6
- data/tasks/terminal_preview/preview_collection.rb +4 -6
- data/tasks/terminal_preview/safety_confirmation.rb +3 -5
- data/tasks/terminal_preview/saved_screenshot.rb +7 -9
- data/tasks/terminal_preview/terminal_window.rb +7 -9
- data/tasks/test.rake +1 -1
- data/tasks/website/index_page.rb +3 -3
- data/tasks/website/version.rb +10 -10
- data/tasks/website/version_menu.rb +10 -12
- data/tasks/website/versioned_documentation.rb +49 -17
- data/tasks/website/website.rb +6 -8
- data/tasks/website.rake +4 -4
- metadata +156 -125
- data/LICENSES/BSD-2-Clause.txt +0 -9
- data/doc/contributors/better_dx.md +0 -543
- data/doc/contributors/example_analysis.md +0 -82
- data/doc/images/all_events.png +0 -0
- data/doc/images/block_padding.png +0 -0
- data/doc/images/block_titles.png +0 -0
- data/doc/images/box_demo.png +0 -0
- data/doc/images/calendar_demo.png +0 -0
- data/doc/images/cell_demo.png +0 -0
- data/doc/images/chart_demo.png +0 -0
- data/doc/images/flex_layout.png +0 -0
- data/doc/images/gauge_demo.png +0 -0
- data/doc/images/line_gauge_demo.png +0 -0
- data/doc/images/list_demo.png +0 -0
- data/doc/images/readme_usage.png +0 -0
- data/doc/images/scrollbar_demo.png +0 -0
- data/doc/images/sparkline_demo.png +0 -0
- data/doc/images/table_flex.png +0 -0
- data/examples/all_events/app.rb +0 -169
- data/examples/all_events/app.rbs +0 -7
- data/examples/all_events/test_app.rb +0 -139
- data/examples/analytics/app.rb +0 -258
- data/examples/analytics/app.rbs +0 -7
- data/examples/analytics/test_app.rb +0 -132
- data/examples/block_padding/app.rbs +0 -7
- data/examples/block_padding/test_app.rb +0 -31
- data/examples/block_titles/app.rbs +0 -7
- data/examples/block_titles/test_app.rb +0 -34
- data/examples/box_demo/app.rbs +0 -7
- data/examples/box_demo/test_app.rb +0 -88
- data/examples/calendar_demo/app.rb +0 -101
- data/examples/calendar_demo/app.rbs +0 -7
- data/examples/calendar_demo/test_app.rb +0 -108
- data/examples/cell_demo/app.rb +0 -108
- data/examples/cell_demo/app.rbs +0 -7
- data/examples/cell_demo/test_app.rb +0 -36
- data/examples/chart_demo/app.rb +0 -203
- data/examples/chart_demo/app.rbs +0 -7
- data/examples/chart_demo/test_app.rb +0 -102
- data/examples/custom_widget/app.rb +0 -51
- data/examples/custom_widget/app.rbs +0 -7
- data/examples/custom_widget/test_app.rb +0 -30
- data/examples/flex_layout/app.rb +0 -156
- data/examples/flex_layout/app.rbs +0 -7
- data/examples/flex_layout/test_app.rb +0 -65
- data/examples/gauge_demo/app.rb +0 -182
- data/examples/gauge_demo/test_app.rb +0 -120
- data/examples/hit_test/app.rb +0 -175
- data/examples/hit_test/app.rbs +0 -7
- data/examples/hit_test/test_app.rb +0 -102
- data/examples/line_gauge_demo/app.rb +0 -190
- data/examples/line_gauge_demo/app.rbs +0 -7
- data/examples/line_gauge_demo/test_app.rb +0 -129
- data/examples/list_demo/app.rb +0 -253
- data/examples/list_demo/test_app.rb +0 -237
- data/examples/list_styles/app.rb +0 -140
- data/examples/list_styles/app.rbs +0 -7
- data/examples/list_styles/test_app.rb +0 -157
- data/examples/login_form/app.rbs +0 -7
- data/examples/login_form/test_app.rb +0 -51
- data/examples/map_demo/app.rbs +0 -7
- data/examples/map_demo/test_app.rb +0 -149
- data/examples/mouse_events/app.rb +0 -97
- data/examples/mouse_events/app.rbs +0 -7
- data/examples/mouse_events/test_app.rb +0 -53
- data/examples/popup_demo/app.rb +0 -103
- data/examples/popup_demo/app.rbs +0 -7
- data/examples/popup_demo/test_app.rb +0 -54
- data/examples/quickstart_dsl/app.rbs +0 -7
- data/examples/quickstart_dsl/test_app.rb +0 -29
- data/examples/quickstart_lifecycle/app.rbs +0 -7
- data/examples/quickstart_lifecycle/test_app.rb +0 -29
- data/examples/ratatui_logo_demo/app.rb +0 -79
- data/examples/ratatui_logo_demo/app.rbs +0 -7
- data/examples/ratatui_logo_demo/test_app.rb +0 -51
- data/examples/ratatui_mascot_demo/app.rb +0 -84
- data/examples/ratatui_mascot_demo/app.rbs +0 -7
- data/examples/ratatui_mascot_demo/test_app.rb +0 -47
- data/examples/readme_usage/app.rb +0 -29
- data/examples/readme_usage/app.rbs +0 -7
- data/examples/readme_usage/test_app.rb +0 -29
- data/examples/rich_text/app.rb +0 -141
- data/examples/rich_text/app.rbs +0 -7
- data/examples/rich_text/test_app.rb +0 -166
- data/examples/scroll_text/app.rb +0 -103
- data/examples/scroll_text/app.rbs +0 -7
- data/examples/scroll_text/test_app.rb +0 -110
- data/examples/scrollbar_demo/app.rb +0 -143
- data/examples/scrollbar_demo/app.rbs +0 -7
- data/examples/scrollbar_demo/test_app.rb +0 -77
- data/examples/sparkline_demo/app.rb +0 -240
- data/examples/sparkline_demo/test_app.rb +0 -107
- data/examples/table_flex/app.rb +0 -65
- data/examples/table_flex/app.rbs +0 -7
- data/examples/table_flex/test_app.rb +0 -36
- data/examples/table_select/app.rbs +0 -7
- data/examples/table_select/test_app.rb +0 -180
- data/examples/widget_style_colors/test_app.rb +0 -48
- /data/doc/images/{analytics.png → app_analytics.png} +0 -0
- /data/doc/images/{custom_widget.png → app_custom_widget.png} +0 -0
- /data/doc/images/{login_form.png → app_login_form.png} +0 -0
- /data/doc/images/{map_demo.png → app_map_demo.png} +0 -0
- /data/doc/images/{mouse_events.png → app_mouse_events.png} +0 -0
- /data/doc/images/{table_select.png → app_table_select.png} +0 -0
- /data/doc/images/{quickstart_dsl.png → verify_quickstart_dsl.png} +0 -0
- /data/doc/images/{ratatui_logo_demo.png → verify_quickstart_layout.png} +0 -0
- /data/doc/images/{quickstart_lifecycle.png → verify_quickstart_lifecycle.png} +0 -0
- /data/doc/images/{list_styles.png → widget_list_styles.png} +0 -0
- /data/doc/images/{popup_demo.png → widget_popup_demo.png} +0 -0
- /data/doc/images/{hit_test.png → widget_rect.png} +0 -0
- /data/doc/images/{rich_text.png → widget_rich_text.png} +0 -0
- /data/doc/images/{scroll_text.png → widget_scroll_text.png} +0 -0
data/examples/chart_demo/app.rb
DELETED
|
@@ -1,203 +0,0 @@
|
|
|
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
|
-
# Demonstrates Chart widget with interactive attribute cycling.
|
|
10
|
-
class ChartDemoApp
|
|
11
|
-
def initialize
|
|
12
|
-
@markers = [
|
|
13
|
-
{ name: "Dot (·)", marker: :dot },
|
|
14
|
-
{ name: "Braille", marker: :braille },
|
|
15
|
-
{ name: "Block (█)", marker: :block },
|
|
16
|
-
{ name: "Bar", marker: :bar }
|
|
17
|
-
]
|
|
18
|
-
@marker_index = 0
|
|
19
|
-
|
|
20
|
-
@dataset_styles = [
|
|
21
|
-
{ name: "Yellow", style: RatatuiRuby::Style.new(fg: :yellow) },
|
|
22
|
-
{ name: "Green", style: RatatuiRuby::Style.new(fg: :green) },
|
|
23
|
-
{ name: "Cyan", style: RatatuiRuby::Style.new(fg: :cyan) },
|
|
24
|
-
{ name: "Red", style: RatatuiRuby::Style.new(fg: :red) },
|
|
25
|
-
{ name: "Magenta", style: RatatuiRuby::Style.new(fg: :magenta) },
|
|
26
|
-
{ name: "Bold Blue", style: RatatuiRuby::Style.new(fg: :blue, modifiers: [:bold]) },
|
|
27
|
-
{ name: "Dim White", style: RatatuiRuby::Style.new(fg: :white, modifiers: [:dim]) },
|
|
28
|
-
{ name: "Italic Green", style: RatatuiRuby::Style.new(fg: :green, modifiers: [:italic]) },
|
|
29
|
-
{ name: "Alert (Red/White/Bar)", style: RatatuiRuby::Style.new(fg: :white, bg: :red, modifiers: [:bold]) }
|
|
30
|
-
]
|
|
31
|
-
@dataset_style_index = 0
|
|
32
|
-
|
|
33
|
-
@x_alignments = [
|
|
34
|
-
{ name: "Left", alignment: :left },
|
|
35
|
-
{ name: "Center", alignment: :center },
|
|
36
|
-
{ name: "Right", alignment: :right }
|
|
37
|
-
]
|
|
38
|
-
@x_alignment_index = 1
|
|
39
|
-
|
|
40
|
-
@y_alignments = [
|
|
41
|
-
{ name: "Left", alignment: :left },
|
|
42
|
-
{ name: "Center", alignment: :center },
|
|
43
|
-
{ name: "Right", alignment: :right }
|
|
44
|
-
]
|
|
45
|
-
@y_alignment_index = 2
|
|
46
|
-
|
|
47
|
-
@legend_positions = [
|
|
48
|
-
{ name: "Top Right", position: :top_right },
|
|
49
|
-
{ name: "Top Left", position: :top_left },
|
|
50
|
-
{ name: "Bottom Right", position: :bottom_right },
|
|
51
|
-
{ name: "Bottom Left", position: :bottom_left }
|
|
52
|
-
]
|
|
53
|
-
@legend_position_index = 0
|
|
54
|
-
|
|
55
|
-
@hotkey_style = RatatuiRuby::Style.new(modifiers: [:bold, :underlined])
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
def run
|
|
59
|
-
RatatuiRuby.run do
|
|
60
|
-
loop do
|
|
61
|
-
render
|
|
62
|
-
break if handle_input == :quit
|
|
63
|
-
sleep 0.05
|
|
64
|
-
end
|
|
65
|
-
end
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
private
|
|
69
|
-
|
|
70
|
-
def render
|
|
71
|
-
# Static sample data: sine wave with wider range for better visibility
|
|
72
|
-
line_data = (0..50).map do |i|
|
|
73
|
-
x = i / 5.0
|
|
74
|
-
[x, Math.sin(x)]
|
|
75
|
-
end
|
|
76
|
-
|
|
77
|
-
# Scatter: Random points
|
|
78
|
-
scatter_data = (0..20).map do |_|
|
|
79
|
-
[rand(0.0..10.0), rand(-1.0..1.0)]
|
|
80
|
-
end
|
|
81
|
-
|
|
82
|
-
style = @dataset_styles[@dataset_style_index][:style]
|
|
83
|
-
# Ensure the second dataset has a different style
|
|
84
|
-
scatter_style = @dataset_styles[(@dataset_style_index + 2) % @dataset_styles.length][:style]
|
|
85
|
-
|
|
86
|
-
datasets = [
|
|
87
|
-
RatatuiRuby::Dataset.new(
|
|
88
|
-
name: "Line",
|
|
89
|
-
data: line_data,
|
|
90
|
-
style:,
|
|
91
|
-
marker: style.modifiers.include?(:bold) && style.bg ? :bar : @markers[@marker_index][:marker],
|
|
92
|
-
graph_type: :line
|
|
93
|
-
),
|
|
94
|
-
RatatuiRuby::Dataset.new(
|
|
95
|
-
name: "Scatter",
|
|
96
|
-
data: scatter_data,
|
|
97
|
-
style: scatter_style,
|
|
98
|
-
marker: scatter_style.modifiers.include?(:bold) && scatter_style.bg ? :bar : @markers[@marker_index][:marker],
|
|
99
|
-
graph_type: :scatter
|
|
100
|
-
)
|
|
101
|
-
]
|
|
102
|
-
|
|
103
|
-
x_alignment = @x_alignments[@x_alignment_index][:alignment]
|
|
104
|
-
y_alignment = @y_alignments[@y_alignment_index][:alignment]
|
|
105
|
-
legend_position = @legend_positions[@legend_position_index][:position]
|
|
106
|
-
|
|
107
|
-
chart = RatatuiRuby::Chart.new(
|
|
108
|
-
datasets:,
|
|
109
|
-
x_axis: RatatuiRuby::Axis.new(
|
|
110
|
-
title: "Time",
|
|
111
|
-
bounds: [0.0, 10.0],
|
|
112
|
-
labels: %w[0 5 10],
|
|
113
|
-
style: RatatuiRuby::Style.new(fg: :yellow),
|
|
114
|
-
labels_alignment: x_alignment
|
|
115
|
-
),
|
|
116
|
-
y_axis: RatatuiRuby::Axis.new(
|
|
117
|
-
title: "Amplitude",
|
|
118
|
-
bounds: [-1.0, 1.0],
|
|
119
|
-
labels: %w[-1 0 1],
|
|
120
|
-
style: RatatuiRuby::Style.new(fg: :cyan),
|
|
121
|
-
labels_alignment: y_alignment
|
|
122
|
-
),
|
|
123
|
-
block: RatatuiRuby::Block.new(
|
|
124
|
-
title: "Chart Widget Demo",
|
|
125
|
-
borders: [:all]
|
|
126
|
-
),
|
|
127
|
-
legend_position:,
|
|
128
|
-
hidden_legend_constraints: [
|
|
129
|
-
RatatuiRuby::Constraint.min(20),
|
|
130
|
-
RatatuiRuby::Constraint.min(10)
|
|
131
|
-
]
|
|
132
|
-
)
|
|
133
|
-
|
|
134
|
-
layout = RatatuiRuby::Layout.new(
|
|
135
|
-
direction: :vertical,
|
|
136
|
-
constraints: [
|
|
137
|
-
RatatuiRuby::Constraint.fill(1),
|
|
138
|
-
RatatuiRuby::Constraint.length(5)
|
|
139
|
-
],
|
|
140
|
-
children: [
|
|
141
|
-
chart,
|
|
142
|
-
# Bottom control panel
|
|
143
|
-
RatatuiRuby::Block.new(
|
|
144
|
-
title: "Controls",
|
|
145
|
-
borders: [:all],
|
|
146
|
-
children: [
|
|
147
|
-
RatatuiRuby::Paragraph.new(
|
|
148
|
-
text: [
|
|
149
|
-
# Line 1: Markers & Colors
|
|
150
|
-
RatatuiRuby::Text::Line.new(spans: [
|
|
151
|
-
RatatuiRuby::Text::Span.new(content: "m", style: @hotkey_style),
|
|
152
|
-
RatatuiRuby::Text::Span.new(content: ": Marker (#{@markers[@marker_index][:name]}) "),
|
|
153
|
-
RatatuiRuby::Text::Span.new(content: "s", style: @hotkey_style),
|
|
154
|
-
RatatuiRuby::Text::Span.new(content: ": Style (#{@dataset_styles[@dataset_style_index][:name]})")
|
|
155
|
-
]),
|
|
156
|
-
# Line 2: Axis alignments
|
|
157
|
-
RatatuiRuby::Text::Line.new(spans: [
|
|
158
|
-
RatatuiRuby::Text::Span.new(content: "x", style: @hotkey_style),
|
|
159
|
-
RatatuiRuby::Text::Span.new(content: ": X Align (#{@x_alignments[@x_alignment_index][:name]}) "),
|
|
160
|
-
RatatuiRuby::Text::Span.new(content: "y", style: @hotkey_style),
|
|
161
|
-
RatatuiRuby::Text::Span.new(content: ": Y Align (#{@y_alignments[@y_alignment_index][:name]}) "),
|
|
162
|
-
RatatuiRuby::Text::Span.new(content: "l", style: @hotkey_style),
|
|
163
|
-
RatatuiRuby::Text::Span.new(content: ": Legend (#{@legend_positions[@legend_position_index][:name]})")
|
|
164
|
-
]),
|
|
165
|
-
# Line 3: Quit
|
|
166
|
-
RatatuiRuby::Text::Line.new(spans: [
|
|
167
|
-
RatatuiRuby::Text::Span.new(content: "q", style: @hotkey_style),
|
|
168
|
-
RatatuiRuby::Text::Span.new(content: ": Quit")
|
|
169
|
-
])
|
|
170
|
-
]
|
|
171
|
-
)
|
|
172
|
-
]
|
|
173
|
-
)
|
|
174
|
-
]
|
|
175
|
-
)
|
|
176
|
-
|
|
177
|
-
RatatuiRuby.draw(layout)
|
|
178
|
-
end
|
|
179
|
-
|
|
180
|
-
def handle_input
|
|
181
|
-
event = RatatuiRuby.poll_event
|
|
182
|
-
return unless event
|
|
183
|
-
|
|
184
|
-
case event
|
|
185
|
-
in {type: :key, code: "q"} | {type: :key, code: "c", modifiers: ["ctrl"]}
|
|
186
|
-
:quit
|
|
187
|
-
in type: :key, code: "m"
|
|
188
|
-
@marker_index = (@marker_index + 1) % @markers.length
|
|
189
|
-
in type: :key, code: "s"
|
|
190
|
-
@dataset_style_index = (@dataset_style_index + 1) % @dataset_styles.length
|
|
191
|
-
in type: :key, code: "x"
|
|
192
|
-
@x_alignment_index = (@x_alignment_index + 1) % @x_alignments.length
|
|
193
|
-
in type: :key, code: "y"
|
|
194
|
-
@y_alignment_index = (@y_alignment_index + 1) % @y_alignments.length
|
|
195
|
-
in type: :key, code: "l"
|
|
196
|
-
@legend_position_index = (@legend_position_index + 1) % @legend_positions.length
|
|
197
|
-
else
|
|
198
|
-
nil
|
|
199
|
-
end
|
|
200
|
-
end
|
|
201
|
-
end
|
|
202
|
-
|
|
203
|
-
ChartDemoApp.new.run if __FILE__ == $PROGRAM_NAME
|
data/examples/chart_demo/app.rbs
DELETED
|
@@ -1,102 +0,0 @@
|
|
|
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
|
-
require "ratatui_ruby/test_helper"
|
|
9
|
-
require "minitest/autorun"
|
|
10
|
-
require_relative "app"
|
|
11
|
-
|
|
12
|
-
class TestChartDemo < Minitest::Test
|
|
13
|
-
include RatatuiRuby::TestHelper
|
|
14
|
-
|
|
15
|
-
def setup
|
|
16
|
-
@app = ChartDemoApp.new
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
def test_initial_render
|
|
20
|
-
with_test_terminal do
|
|
21
|
-
inject_key(:q)
|
|
22
|
-
@app.run
|
|
23
|
-
|
|
24
|
-
content = buffer_content.join("\n")
|
|
25
|
-
assert_includes content, "Chart Widget Demo"
|
|
26
|
-
assert_includes content, "Time"
|
|
27
|
-
assert_includes content, "Amplitude"
|
|
28
|
-
assert_includes content, "Line"
|
|
29
|
-
assert_includes content, "Scatter"
|
|
30
|
-
assert_includes content, "Controls"
|
|
31
|
-
# Verify controls are visible
|
|
32
|
-
assert_includes content, "Marker"
|
|
33
|
-
assert_includes content, "Style"
|
|
34
|
-
assert_includes content, "Align"
|
|
35
|
-
end
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
def test_marker_cycling
|
|
39
|
-
with_test_terminal do
|
|
40
|
-
inject_key("m") # Cycle marker
|
|
41
|
-
inject_key(:q)
|
|
42
|
-
@app.run
|
|
43
|
-
|
|
44
|
-
content = buffer_content.join("\n")
|
|
45
|
-
# Should show the chart still renders
|
|
46
|
-
assert_includes content, "Chart Widget Demo"
|
|
47
|
-
assert_includes content, "Time"
|
|
48
|
-
end
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
def test_style_cycling
|
|
52
|
-
with_test_terminal do
|
|
53
|
-
inject_key("s") # Cycle style
|
|
54
|
-
inject_key(:q)
|
|
55
|
-
@app.run
|
|
56
|
-
|
|
57
|
-
content = buffer_content.join("\n")
|
|
58
|
-
assert_includes content, "Chart Widget Demo"
|
|
59
|
-
assert_includes content, "Time"
|
|
60
|
-
end
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
def test_x_alignment_cycling
|
|
64
|
-
with_test_terminal do
|
|
65
|
-
inject_key("x") # Cycle X-axis label alignment
|
|
66
|
-
inject_key(:q)
|
|
67
|
-
@app.run
|
|
68
|
-
|
|
69
|
-
content = buffer_content.join("\n")
|
|
70
|
-
assert_includes content, "Chart Widget Demo"
|
|
71
|
-
assert_includes content, "Time"
|
|
72
|
-
end
|
|
73
|
-
end
|
|
74
|
-
|
|
75
|
-
def test_y_alignment_cycling
|
|
76
|
-
with_test_terminal do
|
|
77
|
-
inject_key("y") # Cycle Y-axis label alignment
|
|
78
|
-
inject_key(:q)
|
|
79
|
-
@app.run
|
|
80
|
-
|
|
81
|
-
content = buffer_content.join("\n")
|
|
82
|
-
assert_includes content, "Chart Widget Demo"
|
|
83
|
-
assert_includes content, "Amplitude"
|
|
84
|
-
end
|
|
85
|
-
end
|
|
86
|
-
|
|
87
|
-
def test_multiple_cycles
|
|
88
|
-
with_test_terminal do
|
|
89
|
-
inject_key("m")
|
|
90
|
-
inject_key("s")
|
|
91
|
-
inject_key("x")
|
|
92
|
-
inject_key("y")
|
|
93
|
-
inject_key(:q)
|
|
94
|
-
@app.run
|
|
95
|
-
|
|
96
|
-
content = buffer_content.join("\n")
|
|
97
|
-
assert_includes content, "Chart Widget Demo"
|
|
98
|
-
# Chart and controls should all render
|
|
99
|
-
assert_includes content, "Controls"
|
|
100
|
-
end
|
|
101
|
-
end
|
|
102
|
-
end
|
|
@@ -1,51 +0,0 @@
|
|
|
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
|
-
# A custom widget that draws a diagonal line.
|
|
10
|
-
class DiagonalWidget
|
|
11
|
-
def render(area)
|
|
12
|
-
# Draw a diagonal line within the area
|
|
13
|
-
(0..10).filter_map do |i|
|
|
14
|
-
next if area.x + i >= area.x + area.width || area.y + i >= area.y + area.height
|
|
15
|
-
|
|
16
|
-
RatatuiRuby::Draw.string(
|
|
17
|
-
area.x + i,
|
|
18
|
-
area.y + i,
|
|
19
|
-
"\\",
|
|
20
|
-
{ fg: :red, modifiers: [:bold] }
|
|
21
|
-
)
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
class CustomWidgetApp
|
|
27
|
-
def run
|
|
28
|
-
RatatuiRuby.run do |tui|
|
|
29
|
-
loop do
|
|
30
|
-
tui.draw(
|
|
31
|
-
RatatuiRuby::Layout.new(
|
|
32
|
-
direction: :vertical,
|
|
33
|
-
constraints: [
|
|
34
|
-
RatatuiRuby::Constraint.percentage(50),
|
|
35
|
-
RatatuiRuby::Constraint.percentage(50),
|
|
36
|
-
],
|
|
37
|
-
children: [
|
|
38
|
-
RatatuiRuby::Paragraph.new(text: "Above custom widget"),
|
|
39
|
-
DiagonalWidget.new,
|
|
40
|
-
]
|
|
41
|
-
)
|
|
42
|
-
)
|
|
43
|
-
|
|
44
|
-
event = RatatuiRuby.poll_event
|
|
45
|
-
break if event == "q" || event == :ctrl_c
|
|
46
|
-
end
|
|
47
|
-
end
|
|
48
|
-
end
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
CustomWidgetApp.new.run if __FILE__ == $PROGRAM_NAME
|
|
@@ -1,30 +0,0 @@
|
|
|
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
|
-
require "ratatui_ruby/test_helper"
|
|
9
|
-
require "minitest/autorun"
|
|
10
|
-
require_relative "app"
|
|
11
|
-
|
|
12
|
-
class TestCustomWidget < Minitest::Test
|
|
13
|
-
include RatatuiRuby::TestHelper
|
|
14
|
-
|
|
15
|
-
def setup
|
|
16
|
-
@app = CustomWidgetApp.new
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
def test_render
|
|
20
|
-
with_test_terminal do
|
|
21
|
-
inject_key(:q)
|
|
22
|
-
@app.run
|
|
23
|
-
|
|
24
|
-
content = buffer_content.join("\n")
|
|
25
|
-
assert_includes content, "Above custom widget"
|
|
26
|
-
# The custom widget draws backslashes
|
|
27
|
-
assert_includes content, "\\"
|
|
28
|
-
end
|
|
29
|
-
end
|
|
30
|
-
end
|
data/examples/flex_layout/app.rb
DELETED
|
@@ -1,156 +0,0 @@
|
|
|
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
|
-
class FlexLayoutApp
|
|
10
|
-
def run
|
|
11
|
-
RatatuiRuby.run do
|
|
12
|
-
loop do
|
|
13
|
-
render
|
|
14
|
-
break if handle_input == :quit
|
|
15
|
-
end
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
private
|
|
20
|
-
|
|
21
|
-
def render
|
|
22
|
-
view_tree = RatatuiRuby::Layout.new(
|
|
23
|
-
direction: :vertical,
|
|
24
|
-
constraints: [
|
|
25
|
-
RatatuiRuby::Constraint.length(3),
|
|
26
|
-
RatatuiRuby::Constraint.fill(1),
|
|
27
|
-
RatatuiRuby::Constraint.fill(1),
|
|
28
|
-
RatatuiRuby::Constraint.fill(1),
|
|
29
|
-
RatatuiRuby::Constraint.fill(1)
|
|
30
|
-
],
|
|
31
|
-
children: [
|
|
32
|
-
RatatuiRuby::Paragraph.new(
|
|
33
|
-
text: "Fill & Flex Layout Demo (press 'q' to quit)",
|
|
34
|
-
block: RatatuiRuby::Block.new(title: "Header", borders: [:all])
|
|
35
|
-
),
|
|
36
|
-
fill_demo_row,
|
|
37
|
-
space_between_demo_row,
|
|
38
|
-
space_evenly_demo_row,
|
|
39
|
-
ratio_demo_row
|
|
40
|
-
]
|
|
41
|
-
)
|
|
42
|
-
|
|
43
|
-
RatatuiRuby.draw(view_tree)
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
def fill_demo_row
|
|
47
|
-
RatatuiRuby::Layout.new(
|
|
48
|
-
direction: :horizontal,
|
|
49
|
-
constraints: [
|
|
50
|
-
RatatuiRuby::Constraint.fill(1),
|
|
51
|
-
RatatuiRuby::Constraint.fill(3)
|
|
52
|
-
],
|
|
53
|
-
children: [
|
|
54
|
-
RatatuiRuby::Block.new(
|
|
55
|
-
title: "Fill(1)",
|
|
56
|
-
borders: [:all],
|
|
57
|
-
border_color: "red"
|
|
58
|
-
),
|
|
59
|
-
RatatuiRuby::Block.new(
|
|
60
|
-
title: "Fill(3)",
|
|
61
|
-
borders: [:all],
|
|
62
|
-
border_color: "blue"
|
|
63
|
-
)
|
|
64
|
-
]
|
|
65
|
-
)
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
def space_between_demo_row
|
|
69
|
-
RatatuiRuby::Layout.new(
|
|
70
|
-
direction: :horizontal,
|
|
71
|
-
flex: :space_between,
|
|
72
|
-
constraints: [
|
|
73
|
-
RatatuiRuby::Constraint.length(12),
|
|
74
|
-
RatatuiRuby::Constraint.length(12),
|
|
75
|
-
RatatuiRuby::Constraint.length(12)
|
|
76
|
-
],
|
|
77
|
-
children: [
|
|
78
|
-
RatatuiRuby::Block.new(
|
|
79
|
-
title: "Block A",
|
|
80
|
-
borders: [:all],
|
|
81
|
-
border_color: "green"
|
|
82
|
-
),
|
|
83
|
-
RatatuiRuby::Block.new(
|
|
84
|
-
title: "Block B",
|
|
85
|
-
borders: [:all],
|
|
86
|
-
border_color: "yellow"
|
|
87
|
-
),
|
|
88
|
-
RatatuiRuby::Block.new(
|
|
89
|
-
title: "Block C",
|
|
90
|
-
borders: [:all],
|
|
91
|
-
border_color: "magenta"
|
|
92
|
-
)
|
|
93
|
-
]
|
|
94
|
-
)
|
|
95
|
-
end
|
|
96
|
-
|
|
97
|
-
def space_evenly_demo_row
|
|
98
|
-
RatatuiRuby::Layout.new(
|
|
99
|
-
direction: :horizontal,
|
|
100
|
-
flex: :space_evenly,
|
|
101
|
-
constraints: [
|
|
102
|
-
RatatuiRuby::Constraint.length(12),
|
|
103
|
-
RatatuiRuby::Constraint.length(12),
|
|
104
|
-
RatatuiRuby::Constraint.length(12)
|
|
105
|
-
],
|
|
106
|
-
children: [
|
|
107
|
-
RatatuiRuby::Block.new(
|
|
108
|
-
title: "Even A",
|
|
109
|
-
borders: [:all],
|
|
110
|
-
border_color: "cyan"
|
|
111
|
-
),
|
|
112
|
-
RatatuiRuby::Block.new(
|
|
113
|
-
title: "Even B",
|
|
114
|
-
borders: [:all],
|
|
115
|
-
border_color: "blue"
|
|
116
|
-
),
|
|
117
|
-
RatatuiRuby::Block.new(
|
|
118
|
-
title: "Even C",
|
|
119
|
-
borders: [:all],
|
|
120
|
-
border_color: "red"
|
|
121
|
-
)
|
|
122
|
-
]
|
|
123
|
-
)
|
|
124
|
-
end
|
|
125
|
-
|
|
126
|
-
def ratio_demo_row
|
|
127
|
-
RatatuiRuby::Layout.new(
|
|
128
|
-
direction: :horizontal,
|
|
129
|
-
constraints: [
|
|
130
|
-
RatatuiRuby::Constraint.ratio(1, 4),
|
|
131
|
-
RatatuiRuby::Constraint.ratio(3, 4)
|
|
132
|
-
],
|
|
133
|
-
children: [
|
|
134
|
-
RatatuiRuby::Block.new(
|
|
135
|
-
title: "Ratio(1, 4)",
|
|
136
|
-
borders: [:all],
|
|
137
|
-
border_color: "green"
|
|
138
|
-
),
|
|
139
|
-
RatatuiRuby::Block.new(
|
|
140
|
-
title: "Ratio(3, 4)",
|
|
141
|
-
borders: [:all],
|
|
142
|
-
border_color: "magenta"
|
|
143
|
-
)
|
|
144
|
-
]
|
|
145
|
-
)
|
|
146
|
-
end
|
|
147
|
-
|
|
148
|
-
def handle_input
|
|
149
|
-
event = RatatuiRuby.poll_event
|
|
150
|
-
return unless event
|
|
151
|
-
|
|
152
|
-
:quit if event == "q" || event == :ctrl_c
|
|
153
|
-
end
|
|
154
|
-
end
|
|
155
|
-
|
|
156
|
-
FlexLayoutApp.new.run if __FILE__ == $0
|
|
@@ -1,65 +0,0 @@
|
|
|
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
|
-
require "ratatui_ruby/test_helper"
|
|
9
|
-
require "minitest/autorun"
|
|
10
|
-
require_relative "app"
|
|
11
|
-
|
|
12
|
-
class TestFlexLayout < Minitest::Test
|
|
13
|
-
include RatatuiRuby::TestHelper
|
|
14
|
-
|
|
15
|
-
def setup
|
|
16
|
-
@app = FlexLayoutApp.new
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
def test_render_header
|
|
20
|
-
with_test_terminal do
|
|
21
|
-
# Queue quit
|
|
22
|
-
inject_key(:q)
|
|
23
|
-
|
|
24
|
-
@app.run
|
|
25
|
-
|
|
26
|
-
assert_includes buffer_content[0], "Header"
|
|
27
|
-
assert buffer_content.any? { |line| line.include?("Fill & Flex Layout Demo") }
|
|
28
|
-
end
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
def test_fill_constraint_ratio
|
|
32
|
-
with_test_terminal do
|
|
33
|
-
# Queue quit
|
|
34
|
-
inject_key(:q)
|
|
35
|
-
|
|
36
|
-
@app.run
|
|
37
|
-
|
|
38
|
-
# Fill(1) and Fill(3) should split horizontally in a 1:3 ratio
|
|
39
|
-
assert buffer_content.any? { |line| line.include?("Fill(1)") }
|
|
40
|
-
assert buffer_content.any? { |line| line.include?("Fill(3)") }
|
|
41
|
-
end
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
def test_space_between_blocks
|
|
45
|
-
with_test_terminal do
|
|
46
|
-
# Queue quit
|
|
47
|
-
inject_key(:q)
|
|
48
|
-
|
|
49
|
-
@app.run
|
|
50
|
-
|
|
51
|
-
# Three blocks with space_between flex should have equal spacing
|
|
52
|
-
assert buffer_content.any? { |line| line.include?("Block A") }
|
|
53
|
-
assert buffer_content.any? { |line| line.include?("Block B") }
|
|
54
|
-
assert buffer_content.any? { |line| line.include?("Block C") }
|
|
55
|
-
end
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
def test_quit_on_q
|
|
59
|
-
with_test_terminal do
|
|
60
|
-
inject_key(:q)
|
|
61
|
-
@app.run
|
|
62
|
-
# Success if it returns
|
|
63
|
-
end
|
|
64
|
-
end
|
|
65
|
-
end
|