ratatui_ruby 0.4.0 → 0.6.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 +98 -176
- data/CHANGELOG.md +80 -6
- data/README.md +19 -7
- data/REUSE.toml +15 -0
- data/doc/application_architecture.md +179 -45
- data/doc/application_testing.md +80 -32
- data/doc/contributors/design/ruby_frontend.md +48 -8
- data/doc/contributors/design/rust_backend.md +1 -0
- data/doc/contributors/developing_examples.md +191 -48
- data/doc/contributors/documentation_style.md +7 -0
- data/doc/contributors/examples_audit/p1_high.md +21 -0
- data/doc/contributors/examples_audit/p2_moderate.md +81 -0
- data/doc/contributors/examples_audit.md +41 -0
- data/doc/contributors/index.md +2 -0
- data/doc/event_handling.md +21 -7
- 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_box_demo.png +0 -0
- data/doc/images/widget_calendar_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_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_overlay_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_rich_text.png +0 -0
- data/doc/images/widget_scroll_text.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_demo.png +0 -0
- data/doc/images/widget_table_flex.png +0 -0
- data/doc/images/widget_tabs_demo.png +0 -0
- data/doc/images/widget_text_width.png +0 -0
- data/doc/interactive_design.md +25 -30
- data/doc/quickstart.md +150 -130
- data/doc/terminal_limitations.md +92 -0
- data/examples/app_all_events/README.md +99 -0
- data/examples/app_all_events/app.rb +96 -0
- data/examples/app_all_events/model/app_model.rb +157 -0
- data/examples/app_all_events/model/event_color_cycle.rb +41 -0
- data/examples/app_all_events/model/event_entry.rb +92 -0
- data/examples/app_all_events/model/msg.rb +37 -0
- data/examples/app_all_events/model/timestamp.rb +54 -0
- data/examples/app_all_events/update.rb +73 -0
- data/examples/app_all_events/view/app_view.rb +78 -0
- data/examples/app_all_events/view/controls_view.rb +52 -0
- data/examples/app_all_events/view/counts_view.rb +59 -0
- data/examples/app_all_events/view/live_view.rb +70 -0
- data/examples/app_all_events/view/log_view.rb +55 -0
- data/examples/app_all_events/view.rb +7 -0
- data/examples/app_color_picker/README.md +134 -0
- data/examples/app_color_picker/app.rb +74 -0
- data/examples/app_color_picker/clipboard.rb +84 -0
- data/examples/app_color_picker/color.rb +191 -0
- data/examples/app_color_picker/controls.rb +90 -0
- data/examples/app_color_picker/copy_dialog.rb +166 -0
- data/examples/app_color_picker/export_pane.rb +126 -0
- data/examples/app_color_picker/harmony.rb +56 -0
- data/examples/app_color_picker/input.rb +174 -0
- data/examples/app_color_picker/main_container.rb +178 -0
- data/examples/app_color_picker/palette.rb +109 -0
- data/examples/app_login_form/README.md +47 -0
- data/examples/{login_form → app_login_form}/app.rb +38 -42
- data/examples/app_stateful_interaction/README.md +31 -0
- data/examples/app_stateful_interaction/app.rb +272 -0
- data/examples/timeout_demo.rb +43 -0
- data/examples/verify_quickstart_dsl/README.md +48 -0
- data/examples/{quickstart_dsl → verify_quickstart_dsl}/app.rb +17 -6
- data/examples/verify_quickstart_layout/README.md +71 -0
- data/examples/verify_quickstart_layout/app.rb +71 -0
- data/examples/verify_quickstart_lifecycle/README.md +56 -0
- data/examples/verify_quickstart_lifecycle/app.rb +54 -0
- data/examples/verify_readme_usage/README.md +43 -0
- data/examples/verify_readme_usage/app.rb +40 -0
- data/examples/widget_barchart_demo/README.md +49 -0
- data/examples/widget_barchart_demo/app.rb +238 -0
- data/examples/widget_block_demo/README.md +34 -0
- data/examples/widget_block_demo/app.rb +256 -0
- data/examples/widget_box_demo/README.md +45 -0
- data/examples/{box_demo → widget_box_demo}/app.rb +99 -65
- data/examples/widget_calendar_demo/README.md +39 -0
- data/examples/widget_calendar_demo/app.rb +109 -0
- 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 +111 -0
- 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 +218 -0
- data/examples/widget_gauge_demo/README.md +41 -0
- data/examples/widget_gauge_demo/app.rb +212 -0
- data/examples/widget_layout_split/README.md +44 -0
- data/examples/widget_layout_split/app.rb +246 -0
- data/examples/widget_line_gauge_demo/README.md +41 -0
- data/examples/widget_line_gauge_demo/app.rb +217 -0
- data/examples/widget_list_demo/README.md +49 -0
- data/examples/widget_list_demo/app.rb +366 -0
- data/examples/widget_map_demo/README.md +39 -0
- data/examples/{map_demo → widget_map_demo}/app.rb +24 -21
- data/examples/widget_overlay_demo/app.rb +248 -0
- data/examples/widget_popup_demo/README.md +36 -0
- data/examples/widget_popup_demo/app.rb +104 -0
- data/examples/widget_ratatui_logo_demo/README.md +34 -0
- data/examples/widget_ratatui_logo_demo/app.rb +103 -0
- data/examples/widget_ratatui_mascot_demo/README.md +34 -0
- data/examples/widget_ratatui_mascot_demo/app.rb +93 -0
- data/examples/widget_rect/README.md +38 -0
- data/examples/widget_rect/app.rb +205 -0
- data/examples/widget_render/README.md +37 -0
- data/examples/widget_render/app.rb +184 -0
- data/examples/widget_rich_text/README.md +35 -0
- data/examples/widget_rich_text/app.rb +166 -0
- data/examples/widget_scroll_text/README.md +37 -0
- data/examples/widget_scroll_text/app.rb +107 -0
- data/examples/widget_scrollbar_demo/README.md +37 -0
- data/examples/widget_scrollbar_demo/app.rb +153 -0
- data/examples/widget_sparkline_demo/README.md +42 -0
- data/examples/widget_sparkline_demo/app.rb +275 -0
- data/examples/widget_style_colors/README.md +34 -0
- data/examples/widget_style_colors/app.rb +19 -21
- data/examples/widget_table_demo/README.md +48 -0
- data/examples/widget_table_demo/app.rb +239 -0
- data/examples/widget_tabs_demo/README.md +41 -0
- data/examples/widget_tabs_demo/app.rb +181 -0
- data/examples/widget_text_width/README.md +35 -0
- data/examples/widget_text_width/app.rb +106 -0
- data/ext/ratatui_ruby/Cargo.lock +11 -4
- data/ext/ratatui_ruby/Cargo.toml +2 -1
- data/ext/ratatui_ruby/src/events.rs +359 -62
- data/ext/ratatui_ruby/src/frame.rs +227 -0
- data/ext/ratatui_ruby/src/lib.rs +110 -27
- data/ext/ratatui_ruby/src/rendering.rs +8 -4
- data/ext/ratatui_ruby/src/string_width.rs +101 -0
- data/ext/ratatui_ruby/src/style.rs +138 -57
- data/ext/ratatui_ruby/src/terminal.rs +42 -22
- data/ext/ratatui_ruby/src/text.rs +14 -7
- data/ext/ratatui_ruby/src/widgets/barchart.rs +74 -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/gauge.rs +9 -2
- data/ext/ratatui_ruby/src/widgets/layout.rs +9 -4
- data/ext/ratatui_ruby/src/widgets/line_gauge.rs +9 -2
- data/ext/ratatui_ruby/src/widgets/list.rs +211 -12
- 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/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 +97 -3
- data/ext/ratatui_ruby/src/widgets/scrollbar_state.rs +169 -0
- data/ext/ratatui_ruby/src/widgets/sparkline.rs +14 -11
- data/ext/ratatui_ruby/src/widgets/table.rs +121 -5
- data/ext/ratatui_ruby/src/widgets/table_state.rs +121 -0
- data/ext/ratatui_ruby/src/widgets/tabs.rs +11 -11
- data/lib/ratatui_ruby/cell.rb +7 -7
- 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 +112 -52
- data/lib/ratatui_ruby/event/mouse.rb +3 -3
- data/lib/ratatui_ruby/event/none.rb +43 -0
- data/lib/ratatui_ruby/event/paste.rb +1 -1
- data/lib/ratatui_ruby/event.rb +56 -4
- data/lib/ratatui_ruby/frame.rb +183 -0
- data/lib/ratatui_ruby/list_state.rb +88 -0
- data/lib/ratatui_ruby/schema/bar_chart/bar.rb +13 -13
- 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 +30 -25
- data/lib/ratatui_ruby/schema/gauge.rb +54 -52
- 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 +103 -80
- data/lib/ratatui_ruby/schema/list_item.rb +41 -0
- 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 +99 -56
- 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 +66 -46
- data/lib/ratatui_ruby/schema/table.rb +126 -115
- data/lib/ratatui_ruby/schema/tabs.rb +66 -67
- data/lib/ratatui_ruby/schema/text.rb +69 -1
- data/lib/ratatui_ruby/scrollbar_state.rb +112 -0
- data/lib/ratatui_ruby/session/autodoc.rb +482 -0
- data/lib/ratatui_ruby/session.rb +55 -23
- 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 +390 -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 +66 -193
- data/lib/ratatui_ruby/version.rb +1 -1
- data/lib/ratatui_ruby.rb +100 -51
- 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_stateful_interaction/app.rbs +33 -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_demo/app.rbs +32 -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_map_demo/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_demo/app.rbs +11 -0
- data/sig/examples/widget_text_width/app.rbs +10 -0
- data/sig/ratatui_ruby/event.rbs +11 -1
- data/sig/ratatui_ruby/frame.rbs +11 -0
- data/sig/ratatui_ruby/list_state.rbs +13 -0
- data/sig/ratatui_ruby/ratatui_ruby.rbs +5 -4
- data/sig/ratatui_ruby/schema/bar_chart/bar.rbs +3 -3
- data/sig/ratatui_ruby/schema/draw.rbs +4 -0
- data/sig/ratatui_ruby/schema/gauge.rbs +2 -2
- data/sig/ratatui_ruby/schema/layout.rbs +1 -1
- 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/style.rbs +3 -3
- data/sig/ratatui_ruby/schema/table.rbs +3 -1
- data/sig/ratatui_ruby/schema/text.rbs +8 -6
- data/sig/ratatui_ruby/scrollbar_state.rbs +18 -0
- data/sig/ratatui_ruby/session.rbs +107 -0
- 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/tasks/autodoc/examples.rb +79 -0
- data/tasks/autodoc/inventory.rb +63 -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 +53 -0
- data/tasks/bump/changelog.rb +3 -3
- data/tasks/bump/history.rb +2 -2
- data/tasks/bump/links.rb +67 -0
- 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 +70 -30
- data/tasks/terminal_preview/app_screenshot.rb +14 -6
- 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 +10 -11
- 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 +232 -127
- 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/list_styles.png +0 -0
- data/doc/images/login_form.png +0 -0
- data/doc/images/quickstart_dsl.png +0 -0
- data/doc/images/quickstart_lifecycle.png +0 -0
- data/doc/images/readme_usage.png +0 -0
- data/doc/images/rich_text.png +0 -0
- data/doc/images/scroll_text.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/doc/images/table_select.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.rb +0 -63
- data/examples/block_padding/app.rbs +0 -7
- data/examples/block_padding/test_app.rb +0 -31
- data/examples/block_titles/app.rb +0 -61
- 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.rb +0 -39
- 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.rb +0 -198
- 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/tasks/bump/comparison_links.rb +0 -41
- /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/{mouse_events.png → app_mouse_events.png} +0 -0
- /data/doc/images/{map_demo.png → widget_map_demo.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/ratatui_logo_demo.png → exe/.gitkeep} +0 -0
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
SPDX-FileCopyrightText: 2025 Kerrick Long <me@kerricklong.com>
|
|
3
|
+
SPDX-License-Identifier: CC-BY-SA-4.0
|
|
4
|
+
-->
|
|
5
|
+
|
|
6
|
+
# App All Events Example
|
|
7
|
+
|
|
8
|
+
This example application captures and visualizes every event supported by `ratatui_ruby`. It serves as a comprehensive reference for event handling and a demonstration of the Proto-TEA architectural pattern.
|
|
9
|
+
|
|
10
|
+
## Architecture: Proto-TEA (Model-View-Update)
|
|
11
|
+
|
|
12
|
+
This application demonstrates **unidirectional data flow** inspired by The Elm Architecture. This separation ensures that state management is predictable and easy to test.
|
|
13
|
+
|
|
14
|
+
### 1. Model (`model/app_model.rb`)
|
|
15
|
+
A single immutable `Data.define` object holding **all** application state:
|
|
16
|
+
* Event log entries
|
|
17
|
+
* Focus state
|
|
18
|
+
* Window size
|
|
19
|
+
* Highlight timestamps
|
|
20
|
+
* Color cycle index
|
|
21
|
+
|
|
22
|
+
State changes use `.with(...)` to return a new Model instance.
|
|
23
|
+
|
|
24
|
+
### 2. Msg (`model/msg.rb`)
|
|
25
|
+
Semantic value objects that decouple raw terminal events from business logic:
|
|
26
|
+
* `Msg::Input` — keyboard, mouse, or paste events
|
|
27
|
+
* `Msg::Resize` — terminal size changes
|
|
28
|
+
* `Msg::Focus` — focus gained/lost
|
|
29
|
+
* `Msg::Quit` — exit signal
|
|
30
|
+
|
|
31
|
+
### 3. Update (`update.rb`)
|
|
32
|
+
A **pure function** that computes the next state:
|
|
33
|
+
|
|
34
|
+
```ruby
|
|
35
|
+
Update.call(msg, model) -> Model
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
All logic previously in `Events.record` now lives here. The function never mutates, never draws, never performs IO.
|
|
39
|
+
|
|
40
|
+
### 4. View (`view/`)
|
|
41
|
+
Pure rendering logic. Views accept the immutable `AppModel` and draw to the screen.
|
|
42
|
+
* **`View::App`**: Root view handling high-level layout
|
|
43
|
+
* **Sub-views**: `Counts`, `Live`, `Log`, `Controls`
|
|
44
|
+
|
|
45
|
+
### 5. Runtime (`app.rb`)
|
|
46
|
+
The MVU loop:
|
|
47
|
+
|
|
48
|
+
```ruby
|
|
49
|
+
loop do
|
|
50
|
+
tui.draw { |f| view.call(model, tui, f, f.area) }
|
|
51
|
+
msg = map_event_to_msg(tui.poll_event, model)
|
|
52
|
+
break if msg.is_a?(Msg::Quit)
|
|
53
|
+
model = Update.call(msg, model)
|
|
54
|
+
end
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## Library Features Showcased
|
|
58
|
+
|
|
59
|
+
Reading this code will teach you how to:
|
|
60
|
+
|
|
61
|
+
* **Handle All Events**:
|
|
62
|
+
* **Keyboard**: Capture normal keys and modifiers (`Ctrl+c`, `q`).
|
|
63
|
+
* **Mouse**: track clicks, drags, and scroll events.
|
|
64
|
+
* **Focus**: React to the terminal window gaining or losing focus (`FocusGained`/`FocusLost`).
|
|
65
|
+
* **Resize**: Dynamically adapt layouts when the terminal size changes.
|
|
66
|
+
* **Paste**: Handle bracketed paste events (if supported by the terminal).
|
|
67
|
+
* **Layouts**: Use `tui.layout_split` with constraints (`Length`, `Fill`) to create complex, responsive dashboards.
|
|
68
|
+
* **Styling**: Apply dynamic styles (bold, colors) based on application state.
|
|
69
|
+
* **Structure**: Organize a non-trivial CLI tool into small, single-purpose classes.
|
|
70
|
+
|
|
71
|
+
## What Problems Does This Solve?
|
|
72
|
+
|
|
73
|
+
### "What key code is my terminal sending?"
|
|
74
|
+
If you are building an app and your logic isn't catching `Ctrl+Left`, run this app and press the keys. You will see exactly how `ratatui_ruby` parses that input (e.g., is it a `Key` event? What are the modifiers?).
|
|
75
|
+
|
|
76
|
+
### "How do I structure a real app?"
|
|
77
|
+
Hello World examples are great, but they don't scale. This example shows how to structure an application that can grow. By using immutable state and pure functions, it solves the problem of "where does my state live and how does it change?"
|
|
78
|
+
|
|
79
|
+
### "How do I test my business logic?"
|
|
80
|
+
The `Update` function is pure. You can test it by constructing a `Msg`, calling `Update.call(msg, model)`, and asserting on the returned `Model`. No mocking required.
|
|
81
|
+
|
|
82
|
+
## Comparison: Choosing an Architecture
|
|
83
|
+
|
|
84
|
+
Complex applications require structured state habits. `AppAllEvents` and the [Color Picker](../app_color_picker/README.md) demonstrate two different approaches.
|
|
85
|
+
|
|
86
|
+
### The Dashboard Approach (AppAllEvents)
|
|
87
|
+
|
|
88
|
+
Dashboards display data. They rarely require complex mouse interaction. Proto-TEA works best here. State is immutable. Logic is pure. Updates are predictable. This simplifies testing.
|
|
89
|
+
|
|
90
|
+
Use this pattern for logs, monitors, and data viewers.
|
|
91
|
+
|
|
92
|
+
### The Tool Approach (Color Picker)
|
|
93
|
+
|
|
94
|
+
Tools require interaction. Users click buttons and drag sliders. Each UI component needs to know where it exists on screen for hit testing.
|
|
95
|
+
|
|
96
|
+
The Color Picker uses a "Proto-Kit (Component-Based)" pattern. Each component encapsulates its own rendering, state, and event handling. The Container routes events and coordinates cross-component effects.
|
|
97
|
+
|
|
98
|
+
Use this pattern for forms, editors, and mouse-driven tools.
|
|
99
|
+
|
|
@@ -0,0 +1,96 @@
|
|
|
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
|
+
$LOAD_PATH.unshift File.expand_path(__dir__)
|
|
8
|
+
|
|
9
|
+
require "ratatui_ruby"
|
|
10
|
+
require_relative "model/app_model"
|
|
11
|
+
require_relative "model/msg"
|
|
12
|
+
require_relative "update"
|
|
13
|
+
require_relative "view/app_view"
|
|
14
|
+
|
|
15
|
+
# Demonstrates the full range of terminal events supported by RatatuiRuby.
|
|
16
|
+
#
|
|
17
|
+
# Developers need a comprehensive example to understand how keys, mouse, resize, and focus events behave.
|
|
18
|
+
# Testing event handling across different terminal emulators and platforms can be unpredictable.
|
|
19
|
+
#
|
|
20
|
+
# This application captures and logs every event received from the backend, providing real-time feedback and history.
|
|
21
|
+
#
|
|
22
|
+
# Use it to verify your terminal's capabilities or as a reference for complex event handling.
|
|
23
|
+
#
|
|
24
|
+
# === Architecture
|
|
25
|
+
#
|
|
26
|
+
# This example uses the Proto-TEA (Model-View-Update) pattern:
|
|
27
|
+
# - **Model**: Immutable AppModel holds all state
|
|
28
|
+
# - **Msg**: Semantic message types decouple events from logic
|
|
29
|
+
# - **Update**: Pure function computes next state
|
|
30
|
+
# - **View**: Renders Model to screen
|
|
31
|
+
#
|
|
32
|
+
# === Examples
|
|
33
|
+
#
|
|
34
|
+
# # Run from the command line:
|
|
35
|
+
# # ruby examples/app_all_events/app.rb
|
|
36
|
+
#
|
|
37
|
+
# app = AppAllEvents.new
|
|
38
|
+
# app.run
|
|
39
|
+
class AppAllEvents
|
|
40
|
+
# List of all event types tracked by this application.
|
|
41
|
+
EVENT_TYPES = %i[key mouse resize paste focus none].freeze
|
|
42
|
+
|
|
43
|
+
# Creates a new AppAllEvents instance and initializes its view.
|
|
44
|
+
def initialize
|
|
45
|
+
@view = View::App.new
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
# Starts the application event loop.
|
|
49
|
+
#
|
|
50
|
+
# Implements the MVU (Model-View-Update) runtime:
|
|
51
|
+
# 1. **View**: Render current model
|
|
52
|
+
# 2. **Poll**: Get next event
|
|
53
|
+
# 3. **Map**: Convert raw event to semantic Msg
|
|
54
|
+
# 4. **Update**: Compute next model
|
|
55
|
+
#
|
|
56
|
+
# === Example
|
|
57
|
+
#
|
|
58
|
+
# app.run
|
|
59
|
+
def run
|
|
60
|
+
RatatuiRuby.run do |tui|
|
|
61
|
+
model = AppModel.initial
|
|
62
|
+
|
|
63
|
+
loop do
|
|
64
|
+
tui.draw { |frame| @view.call(model, tui, frame, frame.area) }
|
|
65
|
+
|
|
66
|
+
event = tui.poll_event
|
|
67
|
+
msg = map_event_to_msg(event, model)
|
|
68
|
+
break if msg.is_a?(Msg::Quit)
|
|
69
|
+
|
|
70
|
+
model = Update.call(msg, model)
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
private def map_event_to_msg(event, model)
|
|
76
|
+
case event
|
|
77
|
+
when RatatuiRuby::Event::Key
|
|
78
|
+
return Msg::Quit.new if event.code == "q"
|
|
79
|
+
return Msg::Quit.new if event.code == "c" && event.modifiers.include?("ctrl")
|
|
80
|
+
|
|
81
|
+
Msg::Input.new(event:)
|
|
82
|
+
when RatatuiRuby::Event::Resize
|
|
83
|
+
Msg::Resize.new(width: event.width, height: event.height, previous_size: model.window_size)
|
|
84
|
+
when RatatuiRuby::Event::FocusGained
|
|
85
|
+
Msg::Focus.new(gained: true)
|
|
86
|
+
when RatatuiRuby::Event::FocusLost
|
|
87
|
+
Msg::Focus.new(gained: false)
|
|
88
|
+
when RatatuiRuby::Event::None
|
|
89
|
+
Msg::NoneEvent.new
|
|
90
|
+
else
|
|
91
|
+
Msg::Input.new(event:)
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
AppAllEvents.new.run if __FILE__ == $PROGRAM_NAME
|
|
@@ -0,0 +1,157 @@
|
|
|
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
|
+
require_relative "timestamp"
|
|
7
|
+
require_relative "event_entry"
|
|
8
|
+
require_relative "event_color_cycle"
|
|
9
|
+
|
|
10
|
+
# Immutable application state for the Proto-TEA architecture.
|
|
11
|
+
#
|
|
12
|
+
# The Elm Architecture requires a single immutable Model. State changes return
|
|
13
|
+
# a new Model instance. This consolidates all app state into one place.
|
|
14
|
+
#
|
|
15
|
+
# Use `AppModel.initial` to create the starting state, and `model.with(...)`
|
|
16
|
+
# to create updated states.
|
|
17
|
+
#
|
|
18
|
+
# === Attributes
|
|
19
|
+
#
|
|
20
|
+
# [entries] Array of EventEntry objects (event log)
|
|
21
|
+
# [focused] Boolean window focus state
|
|
22
|
+
# [window_size] Array [width, height] of terminal dimensions
|
|
23
|
+
# [lit_types] Hash mapping event types to Timestamp (for highlight expiry)
|
|
24
|
+
# [none_count] Integer count of :none events (not logged)
|
|
25
|
+
# [color_cycle_index] Integer index into EventColorCycle::COLORS
|
|
26
|
+
#
|
|
27
|
+
# === Example
|
|
28
|
+
#
|
|
29
|
+
# model = AppModel.initial
|
|
30
|
+
# model.count(:key) #=> 0
|
|
31
|
+
# model.focused #=> true
|
|
32
|
+
class AppModel < Data.define(:entries, :focused, :window_size, :lit_types, :none_count, :color_cycle_index)
|
|
33
|
+
# Highlight duration in milliseconds.
|
|
34
|
+
HIGHLIGHT_DURATION_MS = 300
|
|
35
|
+
|
|
36
|
+
# Creates the initial application state.
|
|
37
|
+
#
|
|
38
|
+
# === Example
|
|
39
|
+
#
|
|
40
|
+
# AppModel.initial #=> #<data AppModel entries=[] focused=true ...>
|
|
41
|
+
def self.initial
|
|
42
|
+
new(
|
|
43
|
+
entries: [],
|
|
44
|
+
focused: true,
|
|
45
|
+
window_size: [80, 24],
|
|
46
|
+
lit_types: {},
|
|
47
|
+
none_count: 0,
|
|
48
|
+
color_cycle_index: 0
|
|
49
|
+
)
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
# Returns the count of events for a given type.
|
|
53
|
+
#
|
|
54
|
+
# [type] Symbol event type (:key, :mouse, :resize, :paste, :focus, :none)
|
|
55
|
+
#
|
|
56
|
+
# === Example
|
|
57
|
+
#
|
|
58
|
+
# model.count(:key) #=> 5
|
|
59
|
+
def count(type)
|
|
60
|
+
return none_count if type == :none
|
|
61
|
+
|
|
62
|
+
entries.count { |e| e.matches_type?(type) }
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
# Returns counts grouped by subtype (kind or modifier status).
|
|
66
|
+
#
|
|
67
|
+
# [type] Symbol event type.
|
|
68
|
+
#
|
|
69
|
+
# === Example
|
|
70
|
+
#
|
|
71
|
+
# model.sub_counts(:mouse) #=> { "down" => 1, "up" => 2 }
|
|
72
|
+
def sub_counts(type)
|
|
73
|
+
return {} if type == :none
|
|
74
|
+
|
|
75
|
+
matching = entries.select { |e| e.matches_type?(type) }
|
|
76
|
+
defaults = {
|
|
77
|
+
key: %w[standard function media system modifier],
|
|
78
|
+
focus: %w[gained lost],
|
|
79
|
+
mouse: %w[down up drag moved scroll_up scroll_down],
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
matching.each_with_object(defaults.fetch(type, []).to_h { |k| [k, 0] }) do |entry, counts|
|
|
83
|
+
group = subtype_for(entry, type)
|
|
84
|
+
counts[group] += 1 if group
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
# Checks if an event type should be highlighted.
|
|
89
|
+
#
|
|
90
|
+
# [type] Symbol event type.
|
|
91
|
+
#
|
|
92
|
+
# === Example
|
|
93
|
+
#
|
|
94
|
+
# model.lit?(:key) #=> true
|
|
95
|
+
def lit?(type)
|
|
96
|
+
timestamp = lit_types[type]
|
|
97
|
+
return false unless timestamp
|
|
98
|
+
|
|
99
|
+
!timestamp.elapsed?(HIGHLIGHT_DURATION_MS)
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
# Returns the most recent entries up to the given limit.
|
|
103
|
+
#
|
|
104
|
+
# [max_entries] Integer maximum number of entries to return.
|
|
105
|
+
#
|
|
106
|
+
# === Example
|
|
107
|
+
#
|
|
108
|
+
# model.visible(10) #=> [#<EventEntry ...>, ...]
|
|
109
|
+
def visible(max_entries)
|
|
110
|
+
entries.last(max_entries)
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
# Checks if any events have been recorded.
|
|
114
|
+
#
|
|
115
|
+
# === Example
|
|
116
|
+
#
|
|
117
|
+
# model.empty? #=> true
|
|
118
|
+
def empty?
|
|
119
|
+
entries.empty?
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
# Returns the most recent live event data for a type.
|
|
123
|
+
#
|
|
124
|
+
# [type] Symbol event type.
|
|
125
|
+
#
|
|
126
|
+
# === Example
|
|
127
|
+
#
|
|
128
|
+
# model.live_event(:key) #=> { time: Time, description: "..." }
|
|
129
|
+
def live_event(type)
|
|
130
|
+
entry = entries.reverse.find { |e| e.live_type == type }
|
|
131
|
+
return nil unless entry
|
|
132
|
+
|
|
133
|
+
{ time: Time.at(entry.timestamp.milliseconds / 1000.0), description: entry.description }
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
# Returns the next color in the cycle for a new event.
|
|
137
|
+
#
|
|
138
|
+
# === Example
|
|
139
|
+
#
|
|
140
|
+
# model.next_color #=> :cyan
|
|
141
|
+
def next_color
|
|
142
|
+
EventColorCycle::COLORS[color_cycle_index]
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
private def subtype_for(entry, type)
|
|
146
|
+
case type
|
|
147
|
+
when :key
|
|
148
|
+
# Key events: group by category kind (standard/function/media/modifier/system)
|
|
149
|
+
entry.event.kind.to_s if entry.event.respond_to?(:kind)
|
|
150
|
+
when :mouse
|
|
151
|
+
# Mouse events: group by event kind (down/up/drag/moved/scroll_up/scroll_down)
|
|
152
|
+
entry.event.kind.to_s if entry.event.respond_to?(:kind)
|
|
153
|
+
when :focus
|
|
154
|
+
entry.type.to_s.sub("focus_", "")
|
|
155
|
+
end
|
|
156
|
+
end
|
|
157
|
+
end
|
|
@@ -0,0 +1,41 @@
|
|
|
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
|
+
# Cycles through a set of colors for event logging.
|
|
7
|
+
#
|
|
8
|
+
# Sequential events in a log are hard to distinguish if they all look the same.
|
|
9
|
+
# Manually assigning colors to every event type or entry is repetitive.
|
|
10
|
+
#
|
|
11
|
+
# This class automatically cycles through a predefined list of vibrant colors.
|
|
12
|
+
#
|
|
13
|
+
# Use it to give each event in a log a distinct visual identity.
|
|
14
|
+
#
|
|
15
|
+
# === Examples
|
|
16
|
+
#
|
|
17
|
+
# cycler = EventColorCycle.new
|
|
18
|
+
# cycler.next_color #=> :cyan
|
|
19
|
+
# cycler.next_color #=> :magenta
|
|
20
|
+
# cycler.next_color #=> :yellow
|
|
21
|
+
# cycler.next_color #=> :cyan
|
|
22
|
+
class EventColorCycle
|
|
23
|
+
# List of colors to cycle through.
|
|
24
|
+
COLORS = %i[cyan magenta yellow].freeze
|
|
25
|
+
|
|
26
|
+
# Creates a new EventColorCycle.
|
|
27
|
+
def initialize
|
|
28
|
+
@index = 0
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# Returns the next color in the cycle.
|
|
32
|
+
#
|
|
33
|
+
# === Example
|
|
34
|
+
#
|
|
35
|
+
# cycler.next_color #=> :cyan
|
|
36
|
+
def next_color
|
|
37
|
+
color = COLORS[@index]
|
|
38
|
+
@index = (@index + 1) % COLORS.length
|
|
39
|
+
color
|
|
40
|
+
end
|
|
41
|
+
end
|
|
@@ -0,0 +1,92 @@
|
|
|
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
|
+
require_relative "timestamp"
|
|
7
|
+
require "ratatui_ruby"
|
|
8
|
+
|
|
9
|
+
# Stores details about a single event in the history log.
|
|
10
|
+
#
|
|
11
|
+
# Event logs need to store diverse data including types, keys, colors, and timestamps.
|
|
12
|
+
# Managing loose hashes or arrays for event history is error-prone and hard to query.
|
|
13
|
+
#
|
|
14
|
+
# This class provides a structured data object for every recorded event.
|
|
15
|
+
#
|
|
16
|
+
# Use it to represent mouse clicks, key presses, or resize events in a log.
|
|
17
|
+
#
|
|
18
|
+
# === Examples
|
|
19
|
+
#
|
|
20
|
+
# # Typically created via Events.record
|
|
21
|
+
# entry = EventEntry.create(key_event, :cyan, Timestamp.now)
|
|
22
|
+
# puts entry.type #=> :key
|
|
23
|
+
# puts entry.description #=> '#<RatatuiRuby::Event::Key ...>'
|
|
24
|
+
class EventEntry < Data.define(:event, :color, :timestamp)
|
|
25
|
+
# Creates a new EventEntry.
|
|
26
|
+
#
|
|
27
|
+
# [event] RatatuiRuby::Event object.
|
|
28
|
+
# [color] Symbol color for the log display.
|
|
29
|
+
# [timestamp] Timestamp of when the event occurred.
|
|
30
|
+
def self.create(event, color, timestamp)
|
|
31
|
+
new(
|
|
32
|
+
event:,
|
|
33
|
+
color:,
|
|
34
|
+
timestamp:
|
|
35
|
+
)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# Returns the event type.
|
|
39
|
+
#
|
|
40
|
+
# === Example
|
|
41
|
+
#
|
|
42
|
+
# entry.type #=> :key
|
|
43
|
+
def type
|
|
44
|
+
case event
|
|
45
|
+
when RatatuiRuby::Event::Key then :key
|
|
46
|
+
when RatatuiRuby::Event::Mouse then :mouse
|
|
47
|
+
when RatatuiRuby::Event::Resize then :resize
|
|
48
|
+
when RatatuiRuby::Event::Paste then :paste
|
|
49
|
+
when RatatuiRuby::Event::FocusGained then :focus_gained
|
|
50
|
+
when RatatuiRuby::Event::FocusLost then :focus_lost
|
|
51
|
+
else :unknown
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
# Returns the event description using inspect.
|
|
56
|
+
#
|
|
57
|
+
# === Example
|
|
58
|
+
#
|
|
59
|
+
# entry.description #=> '#<RatatuiRuby::Event::Key code="a" modifiers=[]>'
|
|
60
|
+
def description
|
|
61
|
+
event.inspect
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
# Checks if the entry matches the given type.
|
|
65
|
+
#
|
|
66
|
+
# [check_type] Symbol type to check against.
|
|
67
|
+
#
|
|
68
|
+
# === Example
|
|
69
|
+
#
|
|
70
|
+
# entry.matches_type?(:key) #=> true
|
|
71
|
+
def matches_type?(check_type)
|
|
72
|
+
return true if check_type == :focus && (type == :focus_gained || type == :focus_lost)
|
|
73
|
+
|
|
74
|
+
type == check_type
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
# Returns the display type for live event grouping.
|
|
78
|
+
#
|
|
79
|
+
# Normalizes focus_gained and focus_lost to :focus.
|
|
80
|
+
#
|
|
81
|
+
# === Example
|
|
82
|
+
#
|
|
83
|
+
# entry.live_type #=> :focus
|
|
84
|
+
def live_type
|
|
85
|
+
case type
|
|
86
|
+
when :focus_gained, :focus_lost
|
|
87
|
+
:focus
|
|
88
|
+
else
|
|
89
|
+
type
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
end
|
|
@@ -0,0 +1,37 @@
|
|
|
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
|
+
# Semantic message types for the Proto-TEA architecture.
|
|
7
|
+
#
|
|
8
|
+
# Raw events from the terminal are converted to semantic Msg types. This
|
|
9
|
+
# decouples the Update function from the event system, making it easier
|
|
10
|
+
# to test and reason about.
|
|
11
|
+
#
|
|
12
|
+
# === Example
|
|
13
|
+
#
|
|
14
|
+
# msg = Msg::Input.new(event: key_event)
|
|
15
|
+
# msg = Msg::Quit.new
|
|
16
|
+
module Msg
|
|
17
|
+
# A keyboard, mouse, or paste event to record.
|
|
18
|
+
Input = Data.define(:event)
|
|
19
|
+
|
|
20
|
+
# A terminal resize event.
|
|
21
|
+
#
|
|
22
|
+
# [width] Integer new terminal width
|
|
23
|
+
# [height] Integer new terminal height
|
|
24
|
+
# [previous_size] Array [width, height] before resize
|
|
25
|
+
Resize = Data.define(:width, :height, :previous_size)
|
|
26
|
+
|
|
27
|
+
# A focus change event.
|
|
28
|
+
#
|
|
29
|
+
# [gained] Boolean true if focus was gained, false if lost
|
|
30
|
+
Focus = Data.define(:gained)
|
|
31
|
+
|
|
32
|
+
# A none/timeout event (no input received).
|
|
33
|
+
NoneEvent = Data.define
|
|
34
|
+
|
|
35
|
+
# A quit signal.
|
|
36
|
+
Quit = Data.define
|
|
37
|
+
end
|
|
@@ -0,0 +1,54 @@
|
|
|
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
|
+
# Represents a high-resolution point in time.
|
|
7
|
+
#
|
|
8
|
+
# Comparing events and calculating durations requires consistent time measurement.
|
|
9
|
+
# Standard Time objects are often too granular or complex for simple millisecond offsets.
|
|
10
|
+
#
|
|
11
|
+
# This class provides a millisecond-precision timestamp for event measurement.
|
|
12
|
+
#
|
|
13
|
+
# Use it to track event timing, calculate elapsed time, or trigger debouncing.
|
|
14
|
+
#
|
|
15
|
+
# === Examples
|
|
16
|
+
#
|
|
17
|
+
# timestamp = Timestamp.now
|
|
18
|
+
# puts timestamp.milliseconds
|
|
19
|
+
#
|
|
20
|
+
# if timestamp.elapsed?(300)
|
|
21
|
+
# puts "More than 300ms have passed."
|
|
22
|
+
# end
|
|
23
|
+
class Timestamp < Data.define(:milliseconds)
|
|
24
|
+
# Returns a new Timestamp representing the current time.
|
|
25
|
+
#
|
|
26
|
+
# === Example
|
|
27
|
+
#
|
|
28
|
+
# Timestamp.now #=> #<struct Timestamp milliseconds=123456789>
|
|
29
|
+
def self.now
|
|
30
|
+
new(milliseconds: (Time.now.to_f * 1000).to_i)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# Checks if a duration has passed since this timestamp.
|
|
34
|
+
#
|
|
35
|
+
# [duration_ms] Integer duration in milliseconds.
|
|
36
|
+
#
|
|
37
|
+
# === Example
|
|
38
|
+
#
|
|
39
|
+
# timestamp = Timestamp.now
|
|
40
|
+
# sleep(0.5)
|
|
41
|
+
# timestamp.elapsed?(300) #=> true
|
|
42
|
+
def elapsed?(duration_ms)
|
|
43
|
+
Timestamp.now.milliseconds >= milliseconds + duration_ms
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
# Returns the current time in milliseconds.
|
|
47
|
+
#
|
|
48
|
+
# === Example
|
|
49
|
+
#
|
|
50
|
+
# Timestamp.current #=> 123456789
|
|
51
|
+
def self.current
|
|
52
|
+
now.milliseconds
|
|
53
|
+
end
|
|
54
|
+
end
|
|
@@ -0,0 +1,73 @@
|
|
|
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
|
+
require_relative "model/app_model"
|
|
7
|
+
require_relative "model/msg"
|
|
8
|
+
require_relative "model/event_entry"
|
|
9
|
+
require_relative "model/timestamp"
|
|
10
|
+
require_relative "model/event_color_cycle"
|
|
11
|
+
|
|
12
|
+
# Pure update function for the Proto-TEA architecture.
|
|
13
|
+
#
|
|
14
|
+
# Given a Msg and the current AppModel, returns the next AppModel.
|
|
15
|
+
# This function is pure: it does not mutate arguments, draw to the screen,
|
|
16
|
+
# or perform IO. It simply calculates the next state.
|
|
17
|
+
#
|
|
18
|
+
# === Example
|
|
19
|
+
#
|
|
20
|
+
# model = AppModel.initial
|
|
21
|
+
# msg = Msg::Input.new(event: key_event)
|
|
22
|
+
# new_model = Update.call(msg, model)
|
|
23
|
+
module Update
|
|
24
|
+
extend self
|
|
25
|
+
|
|
26
|
+
# Processes a message and returns the next model.
|
|
27
|
+
#
|
|
28
|
+
# [msg] A Msg value object
|
|
29
|
+
# [model] The current AppModel
|
|
30
|
+
#
|
|
31
|
+
# === Example
|
|
32
|
+
#
|
|
33
|
+
# Update.call(Msg::Quit.new, model) #=> model (unchanged)
|
|
34
|
+
def call(msg, model)
|
|
35
|
+
case msg
|
|
36
|
+
in Msg::Quit
|
|
37
|
+
model
|
|
38
|
+
in Msg::NoneEvent
|
|
39
|
+
model.with(none_count: model.none_count + 1)
|
|
40
|
+
in Msg::Focus(gained:)
|
|
41
|
+
event = gained ? RatatuiRuby::Event::FocusGained.new : RatatuiRuby::Event::FocusLost.new
|
|
42
|
+
entry = create_entry(event, model)
|
|
43
|
+
add_entry(model, entry, :focus).with(focused: gained)
|
|
44
|
+
in Msg::Resize(width:, height:, previous_size: _)
|
|
45
|
+
event = RatatuiRuby::Event::Resize.new(width:, height:)
|
|
46
|
+
entry = create_entry(event, model)
|
|
47
|
+
add_entry(model, entry, :resize).with(window_size: [width, height])
|
|
48
|
+
in Msg::Input(event:)
|
|
49
|
+
entry = create_entry(event, model)
|
|
50
|
+
add_entry(model, entry, entry.live_type)
|
|
51
|
+
else
|
|
52
|
+
model
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
# Creates an EventEntry with the next color and current timestamp.
|
|
57
|
+
def create_entry(event, model)
|
|
58
|
+
EventEntry.create(event, model.next_color, Timestamp.now)
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
# Adds an entry to the model, updates highlights, and advances the color cycle.
|
|
62
|
+
def add_entry(model, entry, live_type)
|
|
63
|
+
new_entries = model.entries + [entry]
|
|
64
|
+
new_lit_types = model.lit_types.merge(live_type => Timestamp.now)
|
|
65
|
+
new_color_index = (model.color_cycle_index + 1) % EventColorCycle::COLORS.length
|
|
66
|
+
|
|
67
|
+
model.with(
|
|
68
|
+
entries: new_entries,
|
|
69
|
+
lit_types: new_lit_types,
|
|
70
|
+
color_cycle_index: new_color_index
|
|
71
|
+
)
|
|
72
|
+
end
|
|
73
|
+
end
|