ratatui_ruby 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/ext/ratatui_ruby/Cargo.lock +1 -1
- data/ext/ratatui_ruby/Cargo.toml +1 -1
- data/lib/ratatui_ruby/version.rb +1 -1
- metadata +1 -232
- data/.builds/ruby-3.2.yml +0 -54
- data/.builds/ruby-3.3.yml +0 -54
- data/.builds/ruby-3.4.yml +0 -54
- data/.builds/ruby-4.0.0.yml +0 -54
- data/.pre-commit-config.yaml +0 -16
- data/.rubocop.yml +0 -10
- data/AGENTS.md +0 -146
- data/CHANGELOG.md +0 -710
- data/README.md +0 -187
- data/README.rdoc +0 -302
- data/Rakefile +0 -11
- data/Steepfile +0 -49
- data/doc/concepts/application_architecture.md +0 -321
- data/doc/concepts/application_testing.md +0 -193
- data/doc/concepts/async.md +0 -190
- data/doc/concepts/custom_widgets.md +0 -247
- data/doc/concepts/debugging.md +0 -401
- data/doc/concepts/event_handling.md +0 -162
- data/doc/concepts/interactive_design.md +0 -146
- data/doc/contributors/auditing/parity.md +0 -239
- data/doc/contributors/design/ruby_frontend.md +0 -420
- data/doc/contributors/design/rust_backend.md +0 -422
- data/doc/contributors/design.md +0 -11
- data/doc/contributors/developing_examples.md +0 -400
- data/doc/contributors/documentation_style.md +0 -121
- data/doc/contributors/index.md +0 -21
- data/doc/contributors/todo/align/api_completeness_audit-finished.md +0 -375
- data/doc/contributors/todo/align/api_completeness_audit-unfinished.md +0 -206
- data/doc/contributors/todo/align/terminal.md +0 -647
- data/doc/contributors/todo/future_work.md +0 -169
- data/doc/contributors/upstream_requests/tab_rects.md +0 -173
- data/doc/contributors/upstream_requests/title_rects.md +0 -132
- data/doc/custom.css +0 -22
- data/doc/getting_started/quickstart.md +0 -291
- data/doc/getting_started/why.md +0 -93
- data/doc/images/app_all_events.png +0 -0
- data/doc/images/app_cli_rich_moments.gif +0 -0
- data/doc/images/app_color_picker.png +0 -0
- data/doc/images/app_debugging_showcase.gif +0 -0
- data/doc/images/app_debugging_showcase.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.png +0 -0
- data/doc/images/widget_block.png +0 -0
- data/doc/images/widget_box.png +0 -0
- data/doc/images/widget_calendar.png +0 -0
- data/doc/images/widget_canvas.png +0 -0
- data/doc/images/widget_cell.png +0 -0
- data/doc/images/widget_center.png +0 -0
- data/doc/images/widget_chart.png +0 -0
- data/doc/images/widget_gauge.png +0 -0
- data/doc/images/widget_layout_split.png +0 -0
- data/doc/images/widget_line_gauge.png +0 -0
- data/doc/images/widget_list.png +0 -0
- data/doc/images/widget_map.png +0 -0
- data/doc/images/widget_overlay.png +0 -0
- data/doc/images/widget_popup.png +0 -0
- data/doc/images/widget_ratatui_logo.png +0 -0
- data/doc/images/widget_ratatui_mascot.png +0 -0
- data/doc/images/widget_rect.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.png +0 -0
- data/doc/images/widget_sparkline.png +0 -0
- data/doc/images/widget_style_colors.png +0 -0
- data/doc/images/widget_table.png +0 -0
- data/doc/images/widget_tabs.png +0 -0
- data/doc/images/widget_text_width.png +0 -0
- data/doc/index.md +0 -39
- data/doc/troubleshooting/async.md +0 -4
- data/doc/troubleshooting/terminal_limitations.md +0 -131
- data/doc/troubleshooting/tui_output.md +0 -197
- data/examples/app_all_events/README.md +0 -114
- data/examples/app_all_events/app.rb +0 -98
- data/examples/app_all_events/model/app_model.rb +0 -159
- data/examples/app_all_events/model/event_color_cycle.rb +0 -43
- data/examples/app_all_events/model/event_entry.rb +0 -94
- data/examples/app_all_events/model/msg.rb +0 -39
- data/examples/app_all_events/model/timestamp.rb +0 -56
- data/examples/app_all_events/update.rb +0 -75
- data/examples/app_all_events/view/app_view.rb +0 -80
- data/examples/app_all_events/view/controls_view.rb +0 -54
- data/examples/app_all_events/view/counts_view.rb +0 -61
- data/examples/app_all_events/view/live_view.rb +0 -72
- data/examples/app_all_events/view/log_view.rb +0 -57
- data/examples/app_all_events/view.rb +0 -9
- data/examples/app_cli_rich_moments/README.md +0 -81
- data/examples/app_cli_rich_moments/app.rb +0 -189
- data/examples/app_color_picker/README.md +0 -156
- data/examples/app_color_picker/app.rb +0 -76
- data/examples/app_color_picker/clipboard.rb +0 -86
- data/examples/app_color_picker/color.rb +0 -193
- data/examples/app_color_picker/controls.rb +0 -92
- data/examples/app_color_picker/copy_dialog.rb +0 -168
- data/examples/app_color_picker/export_pane.rb +0 -128
- data/examples/app_color_picker/harmony.rb +0 -58
- data/examples/app_color_picker/input.rb +0 -176
- data/examples/app_color_picker/main_container.rb +0 -180
- data/examples/app_color_picker/palette.rb +0 -111
- data/examples/app_debugging_showcase/README.md +0 -119
- data/examples/app_debugging_showcase/app.rb +0 -318
- data/examples/app_login_form/README.md +0 -58
- data/examples/app_login_form/app.rb +0 -109
- data/examples/app_stateful_interaction/README.md +0 -35
- data/examples/app_stateful_interaction/app.rb +0 -328
- data/examples/timeout_demo.rb +0 -45
- data/examples/verify_quickstart_dsl/README.md +0 -55
- data/examples/verify_quickstart_dsl/app.rb +0 -49
- data/examples/verify_quickstart_layout/README.md +0 -77
- data/examples/verify_quickstart_layout/app.rb +0 -73
- data/examples/verify_quickstart_lifecycle/README.md +0 -68
- data/examples/verify_quickstart_lifecycle/app.rb +0 -62
- data/examples/verify_readme_usage/README.md +0 -49
- data/examples/verify_readme_usage/app.rb +0 -42
- data/examples/verify_website_managed/README.md +0 -48
- data/examples/verify_website_managed/app.rb +0 -36
- data/examples/verify_website_menu/README.md +0 -60
- data/examples/verify_website_menu/app.rb +0 -84
- data/examples/verify_website_spinner/README.md +0 -44
- data/examples/verify_website_spinner/app.rb +0 -34
- data/examples/widget_barchart/README.md +0 -58
- data/examples/widget_barchart/app.rb +0 -240
- data/examples/widget_block/README.md +0 -44
- data/examples/widget_block/app.rb +0 -258
- data/examples/widget_box/README.md +0 -54
- data/examples/widget_box/app.rb +0 -255
- data/examples/widget_calendar/README.md +0 -48
- data/examples/widget_calendar/app.rb +0 -115
- data/examples/widget_canvas/README.md +0 -31
- data/examples/widget_canvas/app.rb +0 -130
- data/examples/widget_cell/README.md +0 -45
- data/examples/widget_cell/app.rb +0 -112
- data/examples/widget_center/README.md +0 -33
- data/examples/widget_center/app.rb +0 -118
- data/examples/widget_chart/README.md +0 -50
- data/examples/widget_chart/app.rb +0 -220
- data/examples/widget_gauge/README.md +0 -50
- data/examples/widget_gauge/app.rb +0 -229
- data/examples/widget_layout_split/README.md +0 -53
- data/examples/widget_layout_split/app.rb +0 -260
- data/examples/widget_line_gauge/README.md +0 -50
- data/examples/widget_line_gauge/app.rb +0 -219
- data/examples/widget_list/README.md +0 -58
- data/examples/widget_list/app.rb +0 -384
- data/examples/widget_map/README.md +0 -48
- data/examples/widget_map/app.rb +0 -95
- data/examples/widget_overlay/README.md +0 -45
- data/examples/widget_overlay/app.rb +0 -250
- data/examples/widget_popup/README.md +0 -45
- data/examples/widget_popup/app.rb +0 -106
- data/examples/widget_ratatui_logo/README.md +0 -43
- data/examples/widget_ratatui_logo/app.rb +0 -104
- data/examples/widget_ratatui_mascot/README.md +0 -43
- data/examples/widget_ratatui_mascot/app.rb +0 -95
- data/examples/widget_rect/README.md +0 -53
- data/examples/widget_rect/app.rb +0 -222
- data/examples/widget_render/README.md +0 -46
- data/examples/widget_render/app.rb +0 -186
- data/examples/widget_render/app.rbs +0 -41
- data/examples/widget_rich_text/README.md +0 -44
- data/examples/widget_rich_text/app.rb +0 -193
- data/examples/widget_scroll_text/README.md +0 -46
- data/examples/widget_scroll_text/app.rb +0 -109
- data/examples/widget_scrollbar/README.md +0 -46
- data/examples/widget_scrollbar/app.rb +0 -155
- data/examples/widget_sparkline/README.md +0 -51
- data/examples/widget_sparkline/app.rb +0 -277
- data/examples/widget_style_colors/README.md +0 -43
- data/examples/widget_style_colors/app.rb +0 -83
- data/examples/widget_table/README.md +0 -57
- data/examples/widget_table/app.rb +0 -279
- data/examples/widget_tabs/README.md +0 -50
- data/examples/widget_tabs/app.rb +0 -183
- data/examples/widget_text_width/README.md +0 -44
- data/examples/widget_text_width/app.rb +0 -117
- data/migrate_to_buffer.rb +0 -145
- data/mise.toml +0 -8
- data/tasks/autodoc/examples.rb +0 -87
- data/tasks/autodoc/member.rb +0 -58
- data/tasks/autodoc/name.rb +0 -21
- data/tasks/autodoc.rake +0 -21
- data/tasks/bump/cargo_lockfile.rb +0 -21
- data/tasks/bump/changelog.rb +0 -47
- data/tasks/bump/header.rb +0 -32
- data/tasks/bump/history.rb +0 -32
- data/tasks/bump/links.rb +0 -69
- data/tasks/bump/manifest.rb +0 -33
- data/tasks/bump/ruby_gem.rb +0 -49
- data/tasks/bump/sem_ver.rb +0 -40
- data/tasks/bump/unreleased_section.rb +0 -56
- data/tasks/bump.rake +0 -51
- data/tasks/doc.rake +0 -887
- data/tasks/example_viewer.html.erb +0 -172
- data/tasks/extension.rake +0 -14
- data/tasks/license/headers_md.rb +0 -223
- data/tasks/license/headers_rb.rb +0 -210
- data/tasks/license/license_utils.rb +0 -130
- data/tasks/license/snippets_md.rb +0 -315
- data/tasks/license/snippets_rdoc.rb +0 -150
- data/tasks/license.rake +0 -91
- data/tasks/lint.rake +0 -170
- data/tasks/rdoc_config.rb +0 -29
- data/tasks/resources/build.yml.erb +0 -60
- data/tasks/resources/index.html.erb +0 -141
- data/tasks/resources/rubies.yml +0 -7
- data/tasks/sourcehut.rake +0 -110
- data/tasks/steep.rake +0 -11
- data/tasks/terminal_preview/app_screenshot.rb +0 -45
- data/tasks/terminal_preview/crash_report.rb +0 -54
- data/tasks/terminal_preview/example_app.rb +0 -27
- data/tasks/terminal_preview/launcher_script.rb +0 -48
- data/tasks/terminal_preview/preview_collection.rb +0 -60
- data/tasks/terminal_preview/preview_timing.rb +0 -24
- data/tasks/terminal_preview/safety_confirmation.rb +0 -58
- data/tasks/terminal_preview/saved_screenshot.rb +0 -56
- data/tasks/terminal_preview/system_appearance.rb +0 -13
- data/tasks/terminal_preview/terminal_window.rb +0 -138
- data/tasks/terminal_preview/window_id.rb +0 -16
- data/tasks/terminal_preview.rake +0 -30
- data/tasks/test.rake +0 -33
- data/tasks/website/index_page.rb +0 -30
- data/tasks/website/version.rb +0 -127
- data/tasks/website/version_menu.rb +0 -68
- data/tasks/website/versioned_documentation.rb +0 -83
- data/tasks/website/website.rb +0 -53
- data/tasks/website.rake +0 -28
|
@@ -1,197 +0,0 @@
|
|
|
1
|
-
<!--
|
|
2
|
-
SPDX-FileCopyrightText: 2026 Kerrick Long <me@kerricklong.com>
|
|
3
|
-
SPDX-License-Identifier: CC-BY-SA-4.0
|
|
4
|
-
-->
|
|
5
|
-
|
|
6
|
-
# Terminal Output During TUI Sessions
|
|
7
|
-
|
|
8
|
-
## The Problem
|
|
9
|
-
|
|
10
|
-
Writing to stdout or stderr during a TUI session **corrupts the display**.
|
|
11
|
-
|
|
12
|
-
When your application is running inside `RatatuiRuby.run`, the terminal is in "raw mode" and RatatuiRuby has taken control of the display buffer. Any output via `puts`, `warn`, `p`, `print`, or direct writes to `$stdout`/`$stderr` will:
|
|
13
|
-
|
|
14
|
-
1. **Corrupt the screen layout** - Characters appear in random positions
|
|
15
|
-
2. **Mix with TUI output** - Text interleaves with your widgets unpredictably
|
|
16
|
-
3. **Trigger escape sequence errors** - Partial ANSI codes can break rendering
|
|
17
|
-
|
|
18
|
-
## Why This Happens
|
|
19
|
-
|
|
20
|
-
In raw mode:
|
|
21
|
-
- The terminal doesn't process newlines or carriage returns normally
|
|
22
|
-
- Output bypasses the TUI's controlled buffer
|
|
23
|
-
- Cursor position is undefined from the TUI's perspective
|
|
24
|
-
|
|
25
|
-
## Safe Patterns
|
|
26
|
-
|
|
27
|
-
### Use `guard_io` to swallow output from gems
|
|
28
|
-
|
|
29
|
-
If you're using a gem that might write to stdout/stderr, wrap its calls:
|
|
30
|
-
|
|
31
|
-
<!-- SPDX-SnippetBegin -->
|
|
32
|
-
<!--
|
|
33
|
-
SPDX-FileCopyrightText: 2026 Kerrick Long
|
|
34
|
-
SPDX-License-Identifier: MIT-0
|
|
35
|
-
-->
|
|
36
|
-
```ruby
|
|
37
|
-
RatatuiRuby.run do |tui|
|
|
38
|
-
RatatuiRuby.guard_io do
|
|
39
|
-
SomeChattyGem.do_something # Any puts/warn calls are swallowed
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
# Outside guard_io, you can still debug intentionally:
|
|
43
|
-
# Object::STDERR.puts "debug: something" # Escape hatch (corrupts display!)
|
|
44
|
-
end
|
|
45
|
-
```
|
|
46
|
-
<!-- SPDX-SnippetEnd -->
|
|
47
|
-
|
|
48
|
-
### Defer output until after the TUI exits
|
|
49
|
-
|
|
50
|
-
<!-- SPDX-SnippetBegin -->
|
|
51
|
-
<!--
|
|
52
|
-
SPDX-FileCopyrightText: 2026 Kerrick Long
|
|
53
|
-
SPDX-License-Identifier: MIT-0
|
|
54
|
-
-->
|
|
55
|
-
```ruby
|
|
56
|
-
messages = []
|
|
57
|
-
|
|
58
|
-
RatatuiRuby.run do |tui|
|
|
59
|
-
# Collect messages instead of printing them
|
|
60
|
-
messages << "Something happened"
|
|
61
|
-
|
|
62
|
-
# ... TUI logic ...
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
# Now safe to print
|
|
66
|
-
messages.each { |msg| puts msg }
|
|
67
|
-
```
|
|
68
|
-
<!-- SPDX-SnippetEnd -->
|
|
69
|
-
|
|
70
|
-
### Use Logger to write to a file
|
|
71
|
-
|
|
72
|
-
The `Logger` class from Ruby's standard library is the idiomatic solution:
|
|
73
|
-
|
|
74
|
-
<!-- SPDX-SnippetBegin -->
|
|
75
|
-
<!--
|
|
76
|
-
SPDX-FileCopyrightText: 2026 Kerrick Long
|
|
77
|
-
SPDX-License-Identifier: MIT-0
|
|
78
|
-
-->
|
|
79
|
-
```ruby
|
|
80
|
-
require "logger"
|
|
81
|
-
require "tmpdir"
|
|
82
|
-
|
|
83
|
-
LOG = Logger.new(File.join(Dir.tmpdir, "my_app.log"))
|
|
84
|
-
LOG.level = Logger::DEBUG
|
|
85
|
-
|
|
86
|
-
RatatuiRuby.run do |tui|
|
|
87
|
-
LOG.info "Application started"
|
|
88
|
-
LOG.debug "Processing event: #{event.inspect}"
|
|
89
|
-
|
|
90
|
-
# ... TUI logic ...
|
|
91
|
-
end
|
|
92
|
-
```
|
|
93
|
-
<!-- SPDX-SnippetEnd -->
|
|
94
|
-
|
|
95
|
-
### Display messages in the TUI itself
|
|
96
|
-
|
|
97
|
-
<!-- SPDX-SnippetBegin -->
|
|
98
|
-
<!--
|
|
99
|
-
SPDX-FileCopyrightText: 2026 Kerrick Long
|
|
100
|
-
SPDX-License-Identifier: MIT-0
|
|
101
|
-
-->
|
|
102
|
-
```ruby
|
|
103
|
-
RatatuiRuby.run do |tui|
|
|
104
|
-
@status_message = "Something happened"
|
|
105
|
-
|
|
106
|
-
tui.draw do |frame|
|
|
107
|
-
# Show status in the UI
|
|
108
|
-
frame.render_widget(
|
|
109
|
-
tui.paragraph(text: @status_message),
|
|
110
|
-
status_area
|
|
111
|
-
)
|
|
112
|
-
end
|
|
113
|
-
end
|
|
114
|
-
```
|
|
115
|
-
<!-- SPDX-SnippetEnd -->
|
|
116
|
-
|
|
117
|
-
## Library Behavior
|
|
118
|
-
|
|
119
|
-
RatatuiRuby automatically defers its own warnings (like experimental feature notices) during TUI sessions. They are queued and printed after `restore_terminal` is called.
|
|
120
|
-
|
|
121
|
-
You don't need to do anything special for library warnings—they're handled automatically.
|
|
122
|
-
|
|
123
|
-
## Bypassing guard_io
|
|
124
|
-
|
|
125
|
-
If you need to write to stdout/stderr even when `guard_io` is active (e.g., for [pipeline integration](#headless-mode-batchpipelinecli) or IPC), use the original IO constants:
|
|
126
|
-
|
|
127
|
-
<!-- SPDX-SnippetBegin -->
|
|
128
|
-
<!--
|
|
129
|
-
SPDX-FileCopyrightText: 2026 Kerrick Long
|
|
130
|
-
SPDX-License-Identifier: MIT-0
|
|
131
|
-
-->
|
|
132
|
-
```ruby
|
|
133
|
-
RatatuiRuby.guard_io do
|
|
134
|
-
SomeChattyGem.do_something # This is swallowed
|
|
135
|
-
|
|
136
|
-
# But this gets through:
|
|
137
|
-
Object::STDOUT.puts "structured output for downstream tools"
|
|
138
|
-
end
|
|
139
|
-
```
|
|
140
|
-
<!-- SPDX-SnippetEnd -->
|
|
141
|
-
|
|
142
|
-
This works regardless of whether `guard_io` is active. During a TUI session, the display will be corrupted—but the output will reach its destination.
|
|
143
|
-
|
|
144
|
-
## Headless Mode (Batch/Pipeline/CLI)
|
|
145
|
-
|
|
146
|
-
If your app supports both TUI and non-TUI modes (e.g., `my_app --no-tui`), call `headless!` at startup to silence `guard_io` warnings:
|
|
147
|
-
|
|
148
|
-
<!-- SPDX-SnippetBegin -->
|
|
149
|
-
<!--
|
|
150
|
-
SPDX-FileCopyrightText: 2026 Kerrick Long
|
|
151
|
-
SPDX-License-Identifier: MIT-0
|
|
152
|
-
-->
|
|
153
|
-
```ruby
|
|
154
|
-
if ARGV.include?("--no-tui")
|
|
155
|
-
RatatuiRuby.headless!
|
|
156
|
-
# guard_io calls are now silent no-ops
|
|
157
|
-
process_batch_work
|
|
158
|
-
else
|
|
159
|
-
RatatuiRuby.run do |tui|
|
|
160
|
-
# TUI mode - guard_io works normally
|
|
161
|
-
end
|
|
162
|
-
end
|
|
163
|
-
```
|
|
164
|
-
<!-- SPDX-SnippetEnd -->
|
|
165
|
-
|
|
166
|
-
When headless, `guard_io` becomes a no-op (output flows normally), and calling `run` or `init_terminal` raises an error.
|
|
167
|
-
|
|
168
|
-
## Temporarily Exiting TUI Mode
|
|
169
|
-
|
|
170
|
-
Some apps need to temporarily leave TUI mode for user interaction—like lazygit does when opening an external editor for commit messages. Use `restore_terminal` and `init_terminal`:
|
|
171
|
-
|
|
172
|
-
<!-- SPDX-SnippetBegin -->
|
|
173
|
-
<!--
|
|
174
|
-
SPDX-FileCopyrightText: 2026 Kerrick Long
|
|
175
|
-
SPDX-License-Identifier: MIT-0
|
|
176
|
-
-->
|
|
177
|
-
```ruby
|
|
178
|
-
RatatuiRuby.run do |tui|
|
|
179
|
-
# ... TUI is active ...
|
|
180
|
-
|
|
181
|
-
if user_wants_external_editor
|
|
182
|
-
RatatuiRuby.restore_terminal
|
|
183
|
-
|
|
184
|
-
# Now in normal terminal mode
|
|
185
|
-
system("$EDITOR", filename)
|
|
186
|
-
puts "Press Enter to return to the TUI..."
|
|
187
|
-
gets
|
|
188
|
-
|
|
189
|
-
RatatuiRuby.init_terminal
|
|
190
|
-
end
|
|
191
|
-
|
|
192
|
-
# ... TUI is active again ...
|
|
193
|
-
end
|
|
194
|
-
```
|
|
195
|
-
<!-- SPDX-SnippetEnd -->
|
|
196
|
-
|
|
197
|
-
This pattern lets you hand control back to the user or spawn external processes that need normal terminal access.
|
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
<!--
|
|
2
|
-
SPDX-FileCopyrightText: 2026 Kerrick Long <me@kerricklong.com>
|
|
3
|
-
SPDX-License-Identifier: CC-BY-SA-4.0
|
|
4
|
-
-->
|
|
5
|
-
|
|
6
|
-
# App All Events Example
|
|
7
|
-
|
|
8
|
-
[](app.rb)
|
|
9
|
-
|
|
10
|
-
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 Model-View-Update architectural pattern.
|
|
11
|
-
|
|
12
|
-
## Architecture: Model-View-Update
|
|
13
|
-
|
|
14
|
-
This application demonstrates **unidirectional data flow** inspired by The Elm Architecture. This separation ensures that state management is predictable and easy to test.
|
|
15
|
-
|
|
16
|
-
### 1. Model (`model/app_model.rb`)
|
|
17
|
-
A single immutable `Data.define` object holding **all** application state:
|
|
18
|
-
* Event log entries
|
|
19
|
-
* Focus state
|
|
20
|
-
* Window size
|
|
21
|
-
* Highlight timestamps
|
|
22
|
-
* Color cycle index
|
|
23
|
-
|
|
24
|
-
State changes use `.with(...)` to return a new Model instance.
|
|
25
|
-
|
|
26
|
-
### 2. Msg (`model/msg.rb`)
|
|
27
|
-
Semantic value objects that decouple raw terminal events from business logic:
|
|
28
|
-
* `Msg::Input` — keyboard, mouse, or paste events
|
|
29
|
-
* `Msg::Resize` — terminal size changes
|
|
30
|
-
* `Msg::Focus` — focus gained/lost
|
|
31
|
-
* `Msg::Quit` — exit signal
|
|
32
|
-
|
|
33
|
-
### 3. Update (`update.rb`)
|
|
34
|
-
A **pure function** that computes the next state:
|
|
35
|
-
|
|
36
|
-
<!-- SPDX-SnippetBegin -->
|
|
37
|
-
<!--
|
|
38
|
-
SPDX-FileCopyrightText: 2026 Kerrick Long
|
|
39
|
-
SPDX-License-Identifier: MIT-0
|
|
40
|
-
-->
|
|
41
|
-
```ruby
|
|
42
|
-
Update.call(msg, model) -> Model
|
|
43
|
-
```
|
|
44
|
-
<!-- SPDX-SnippetEnd -->
|
|
45
|
-
|
|
46
|
-
All logic previously in `Events.record` now lives here. The function never mutates, never draws, never performs IO.
|
|
47
|
-
|
|
48
|
-
### 4. View (`view/`)
|
|
49
|
-
Pure rendering logic. Views accept the immutable `AppModel` and draw to the screen.
|
|
50
|
-
* **`View::App`**: Root view handling high-level layout
|
|
51
|
-
* **Sub-views**: `Counts`, `Live`, `Log`, `Controls`
|
|
52
|
-
|
|
53
|
-
### 5. Runtime (`app.rb`)
|
|
54
|
-
The MVU loop:
|
|
55
|
-
|
|
56
|
-
<!-- SPDX-SnippetBegin -->
|
|
57
|
-
<!--
|
|
58
|
-
SPDX-FileCopyrightText: 2026 Kerrick Long
|
|
59
|
-
SPDX-License-Identifier: MIT-0
|
|
60
|
-
-->
|
|
61
|
-
```ruby
|
|
62
|
-
loop do
|
|
63
|
-
tui.draw { |f| view.call(model, tui, f, f.area) }
|
|
64
|
-
msg = map_event_to_msg(tui.poll_event, model)
|
|
65
|
-
break if msg.is_a?(Msg::Quit)
|
|
66
|
-
model = Update.call(msg, model)
|
|
67
|
-
end
|
|
68
|
-
```
|
|
69
|
-
<!-- SPDX-SnippetEnd -->
|
|
70
|
-
|
|
71
|
-
## Library Features Showcased
|
|
72
|
-
|
|
73
|
-
Reading this code will teach you how to:
|
|
74
|
-
|
|
75
|
-
* **Handle All Events**:
|
|
76
|
-
* **Keyboard**: Capture normal keys and modifiers (`Ctrl+c`, `q`).
|
|
77
|
-
* **Mouse**: track clicks, drags, and scroll events.
|
|
78
|
-
* **Focus**: React to the terminal window gaining or losing focus (`FocusGained`/`FocusLost`).
|
|
79
|
-
* **Resize**: Dynamically adapt layouts when the terminal size changes.
|
|
80
|
-
* **Paste**: Handle bracketed paste events (if supported by the terminal).
|
|
81
|
-
* **Layouts**: Use `tui.layout_split` with constraints (`Length`, `Fill`) to create complex, responsive dashboards.
|
|
82
|
-
* **Styling**: Apply dynamic styles (bold, colors) based on application state.
|
|
83
|
-
* **Structure**: Organize a non-trivial CLI tool into small, single-purpose classes.
|
|
84
|
-
|
|
85
|
-
## What Problems Does This Solve?
|
|
86
|
-
|
|
87
|
-
### "What key code is my terminal sending?"
|
|
88
|
-
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?).
|
|
89
|
-
|
|
90
|
-
### "How do I structure a real app?"
|
|
91
|
-
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?"
|
|
92
|
-
|
|
93
|
-
### "How do I test my business logic?"
|
|
94
|
-
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.
|
|
95
|
-
|
|
96
|
-
## Comparison: Choosing an Architecture
|
|
97
|
-
|
|
98
|
-
Complex applications require structured state habits. `AppAllEvents` and the [Color Picker](../app_color_picker/README.md) demonstrate two different approaches.
|
|
99
|
-
|
|
100
|
-
### The Dashboard Approach (AppAllEvents)
|
|
101
|
-
|
|
102
|
-
Dashboards display data. They rarely require complex mouse interaction. Model-View-Update works best here. State is immutable. Logic is pure. Updates are predictable. This simplifies testing.
|
|
103
|
-
|
|
104
|
-
Use this pattern for logs, monitors, and data viewers.
|
|
105
|
-
|
|
106
|
-
### The Tool Approach (Color Picker)
|
|
107
|
-
|
|
108
|
-
Tools require interaction. Users click buttons and drag sliders. Each UI component needs to know where it exists on screen for hit testing.
|
|
109
|
-
|
|
110
|
-
The Color Picker uses a Component-Based pattern. Each component encapsulates its own rendering, state, and event handling. The Container routes events and coordinates cross-component effects.
|
|
111
|
-
|
|
112
|
-
Use this pattern for forms, editors, and mouse-driven tools.
|
|
113
|
-
|
|
114
|
-
[Read the source code →](app.rb)
|
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
#--
|
|
4
|
-
# SPDX-FileCopyrightText: 2026 Kerrick Long <me@kerricklong.com>
|
|
5
|
-
# SPDX-License-Identifier: AGPL-3.0-or-later
|
|
6
|
-
#++
|
|
7
|
-
|
|
8
|
-
$LOAD_PATH.unshift File.expand_path("../../lib", __dir__)
|
|
9
|
-
$LOAD_PATH.unshift File.expand_path(__dir__)
|
|
10
|
-
|
|
11
|
-
require "ratatui_ruby"
|
|
12
|
-
require_relative "model/app_model"
|
|
13
|
-
require_relative "model/msg"
|
|
14
|
-
require_relative "update"
|
|
15
|
-
require_relative "view/app_view"
|
|
16
|
-
|
|
17
|
-
# Demonstrates the full range of terminal events supported by RatatuiRuby.
|
|
18
|
-
#
|
|
19
|
-
# Developers need a comprehensive example to understand how keys, mouse, resize, and focus events behave.
|
|
20
|
-
# Testing event handling across different terminal emulators and platforms can be unpredictable.
|
|
21
|
-
#
|
|
22
|
-
# This application captures and logs every event received from the backend, providing real-time feedback and history.
|
|
23
|
-
#
|
|
24
|
-
# Use it to verify your terminal's capabilities or as a reference for complex event handling.
|
|
25
|
-
#
|
|
26
|
-
# === Architecture
|
|
27
|
-
#
|
|
28
|
-
# This example uses the Model-View-Update pattern:
|
|
29
|
-
# - **Model**: Immutable AppModel holds all state
|
|
30
|
-
# - **Msg**: Semantic message types decouple events from logic
|
|
31
|
-
# - **Update**: Pure function computes next state
|
|
32
|
-
# - **View**: Renders Model to screen
|
|
33
|
-
#
|
|
34
|
-
# === Examples
|
|
35
|
-
#
|
|
36
|
-
# # Run from the command line:
|
|
37
|
-
# # ruby examples/app_all_events/app.rb
|
|
38
|
-
#
|
|
39
|
-
# app = AppAllEvents.new
|
|
40
|
-
# app.run
|
|
41
|
-
class AppAllEvents
|
|
42
|
-
# List of all event types tracked by this application.
|
|
43
|
-
EVENT_TYPES = %i[key mouse resize paste focus none].freeze
|
|
44
|
-
|
|
45
|
-
# Creates a new AppAllEvents instance and initializes its view.
|
|
46
|
-
def initialize
|
|
47
|
-
@view = View::App.new
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
# Starts the application event loop.
|
|
51
|
-
#
|
|
52
|
-
# Implements the MVU (Model-View-Update) runtime:
|
|
53
|
-
# 1. **View**: Render current model
|
|
54
|
-
# 2. **Poll**: Get next event
|
|
55
|
-
# 3. **Map**: Convert raw event to semantic Msg
|
|
56
|
-
# 4. **Update**: Compute next model
|
|
57
|
-
#
|
|
58
|
-
# === Example
|
|
59
|
-
#
|
|
60
|
-
# app.run
|
|
61
|
-
def run
|
|
62
|
-
RatatuiRuby.run do |tui|
|
|
63
|
-
model = AppModel.initial
|
|
64
|
-
|
|
65
|
-
loop do
|
|
66
|
-
tui.draw { |frame| @view.call(model, tui, frame, frame.area) }
|
|
67
|
-
|
|
68
|
-
event = tui.poll_event
|
|
69
|
-
msg = map_event_to_msg(event, model)
|
|
70
|
-
break if msg.is_a?(Msg::Quit)
|
|
71
|
-
|
|
72
|
-
model = Update.call(msg, model)
|
|
73
|
-
end
|
|
74
|
-
end
|
|
75
|
-
end
|
|
76
|
-
|
|
77
|
-
private def map_event_to_msg(event, model)
|
|
78
|
-
case event
|
|
79
|
-
when RatatuiRuby::Event::Key
|
|
80
|
-
return Msg::Quit.new if event.code == "q"
|
|
81
|
-
return Msg::Quit.new if event.code == "c" && event.modifiers.include?("ctrl")
|
|
82
|
-
|
|
83
|
-
Msg::Input.new(event:)
|
|
84
|
-
when RatatuiRuby::Event::Resize
|
|
85
|
-
Msg::Resize.new(width: event.width, height: event.height, previous_size: model.window_size)
|
|
86
|
-
when RatatuiRuby::Event::FocusGained
|
|
87
|
-
Msg::Focus.new(gained: true)
|
|
88
|
-
when RatatuiRuby::Event::FocusLost
|
|
89
|
-
Msg::Focus.new(gained: false)
|
|
90
|
-
when RatatuiRuby::Event::None
|
|
91
|
-
Msg::NoneEvent.new
|
|
92
|
-
else
|
|
93
|
-
Msg::Input.new(event:)
|
|
94
|
-
end
|
|
95
|
-
end
|
|
96
|
-
end
|
|
97
|
-
|
|
98
|
-
AppAllEvents.new.run if __FILE__ == $PROGRAM_NAME
|
|
@@ -1,159 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
#--
|
|
4
|
-
# SPDX-FileCopyrightText: 2026 Kerrick Long <me@kerricklong.com>
|
|
5
|
-
# SPDX-License-Identifier: AGPL-3.0-or-later
|
|
6
|
-
#++
|
|
7
|
-
|
|
8
|
-
require_relative "timestamp"
|
|
9
|
-
require_relative "event_entry"
|
|
10
|
-
require_relative "event_color_cycle"
|
|
11
|
-
|
|
12
|
-
# Immutable application state for the Model-View-Update architecture.
|
|
13
|
-
#
|
|
14
|
-
# The Elm Architecture requires a single immutable Model. State changes return
|
|
15
|
-
# a new Model instance. This consolidates all app state into one place.
|
|
16
|
-
#
|
|
17
|
-
# Use `AppModel.initial` to create the starting state, and `model.with(...)`
|
|
18
|
-
# to create updated states.
|
|
19
|
-
#
|
|
20
|
-
# === Attributes
|
|
21
|
-
#
|
|
22
|
-
# [entries] Array of EventEntry objects (event log)
|
|
23
|
-
# [focused] Boolean window focus state
|
|
24
|
-
# [window_size] Array [width, height] of terminal dimensions
|
|
25
|
-
# [lit_types] Hash mapping event types to Timestamp (for highlight expiry)
|
|
26
|
-
# [none_count] Integer count of :none events (not logged)
|
|
27
|
-
# [color_cycle_index] Integer index into EventColorCycle::COLORS
|
|
28
|
-
#
|
|
29
|
-
# === Example
|
|
30
|
-
#
|
|
31
|
-
# model = AppModel.initial
|
|
32
|
-
# model.count(:key) #=> 0
|
|
33
|
-
# model.focused #=> true
|
|
34
|
-
class AppModel < Data.define(:entries, :focused, :window_size, :lit_types, :none_count, :color_cycle_index)
|
|
35
|
-
# Highlight duration in milliseconds.
|
|
36
|
-
HIGHLIGHT_DURATION_MS = 300
|
|
37
|
-
|
|
38
|
-
# Creates the initial application state.
|
|
39
|
-
#
|
|
40
|
-
# === Example
|
|
41
|
-
#
|
|
42
|
-
# AppModel.initial #=> #<data AppModel entries=[] focused=true ...>
|
|
43
|
-
def self.initial
|
|
44
|
-
new(
|
|
45
|
-
entries: [],
|
|
46
|
-
focused: true,
|
|
47
|
-
window_size: [80, 24],
|
|
48
|
-
lit_types: {},
|
|
49
|
-
none_count: 0,
|
|
50
|
-
color_cycle_index: 0
|
|
51
|
-
)
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
# Returns the count of events for a given type.
|
|
55
|
-
#
|
|
56
|
-
# [type] Symbol event type (:key, :mouse, :resize, :paste, :focus, :none)
|
|
57
|
-
#
|
|
58
|
-
# === Example
|
|
59
|
-
#
|
|
60
|
-
# model.count(:key) #=> 5
|
|
61
|
-
def count(type)
|
|
62
|
-
return none_count if type == :none
|
|
63
|
-
|
|
64
|
-
entries.count { |e| e.matches_type?(type) }
|
|
65
|
-
end
|
|
66
|
-
|
|
67
|
-
# Returns counts grouped by subtype (kind or modifier status).
|
|
68
|
-
#
|
|
69
|
-
# [type] Symbol event type.
|
|
70
|
-
#
|
|
71
|
-
# === Example
|
|
72
|
-
#
|
|
73
|
-
# model.sub_counts(:mouse) #=> { "down" => 1, "up" => 2 }
|
|
74
|
-
def sub_counts(type)
|
|
75
|
-
return {} if type == :none
|
|
76
|
-
|
|
77
|
-
matching = entries.select { |e| e.matches_type?(type) }
|
|
78
|
-
defaults = {
|
|
79
|
-
key: %w[standard function media system modifier],
|
|
80
|
-
focus: %w[gained lost],
|
|
81
|
-
mouse: %w[down up drag moved scroll_up scroll_down],
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
matching.each_with_object(defaults.fetch(type, []).to_h { |k| [k, 0] }) do |entry, counts|
|
|
85
|
-
group = subtype_for(entry, type)
|
|
86
|
-
counts[group] += 1 if group
|
|
87
|
-
end
|
|
88
|
-
end
|
|
89
|
-
|
|
90
|
-
# Checks if an event type should be highlighted.
|
|
91
|
-
#
|
|
92
|
-
# [type] Symbol event type.
|
|
93
|
-
#
|
|
94
|
-
# === Example
|
|
95
|
-
#
|
|
96
|
-
# model.lit?(:key) #=> true
|
|
97
|
-
def lit?(type)
|
|
98
|
-
timestamp = lit_types[type]
|
|
99
|
-
return false unless timestamp
|
|
100
|
-
|
|
101
|
-
!timestamp.elapsed?(HIGHLIGHT_DURATION_MS)
|
|
102
|
-
end
|
|
103
|
-
|
|
104
|
-
# Returns the most recent entries up to the given limit.
|
|
105
|
-
#
|
|
106
|
-
# [max_entries] Integer maximum number of entries to return.
|
|
107
|
-
#
|
|
108
|
-
# === Example
|
|
109
|
-
#
|
|
110
|
-
# model.visible(10) #=> [#<EventEntry ...>, ...]
|
|
111
|
-
def visible(max_entries)
|
|
112
|
-
entries.last(max_entries)
|
|
113
|
-
end
|
|
114
|
-
|
|
115
|
-
# Checks if any events have been recorded.
|
|
116
|
-
#
|
|
117
|
-
# === Example
|
|
118
|
-
#
|
|
119
|
-
# model.empty? #=> true
|
|
120
|
-
def empty?
|
|
121
|
-
entries.empty?
|
|
122
|
-
end
|
|
123
|
-
|
|
124
|
-
# Returns the most recent live event data for a type.
|
|
125
|
-
#
|
|
126
|
-
# [type] Symbol event type.
|
|
127
|
-
#
|
|
128
|
-
# === Example
|
|
129
|
-
#
|
|
130
|
-
# model.live_event(:key) #=> { time: Time, description: "..." }
|
|
131
|
-
def live_event(type)
|
|
132
|
-
entry = entries.reverse.find { |e| e.live_type == type }
|
|
133
|
-
return nil unless entry
|
|
134
|
-
|
|
135
|
-
{ time: Time.at(entry.timestamp.milliseconds / 1000.0), description: entry.description }
|
|
136
|
-
end
|
|
137
|
-
|
|
138
|
-
# Returns the next color in the cycle for a new event.
|
|
139
|
-
#
|
|
140
|
-
# === Example
|
|
141
|
-
#
|
|
142
|
-
# model.next_color #=> :cyan
|
|
143
|
-
def next_color
|
|
144
|
-
EventColorCycle::COLORS[color_cycle_index]
|
|
145
|
-
end
|
|
146
|
-
|
|
147
|
-
private def subtype_for(entry, type)
|
|
148
|
-
case type
|
|
149
|
-
when :key
|
|
150
|
-
# Key events: group by category kind (standard/function/media/modifier/system)
|
|
151
|
-
entry.event.kind.to_s if entry.event.respond_to?(:kind)
|
|
152
|
-
when :mouse
|
|
153
|
-
# Mouse events: group by event kind (down/up/drag/moved/scroll_up/scroll_down)
|
|
154
|
-
entry.event.kind.to_s if entry.event.respond_to?(:kind)
|
|
155
|
-
when :focus
|
|
156
|
-
entry.type.to_s.sub("focus_", "")
|
|
157
|
-
end
|
|
158
|
-
end
|
|
159
|
-
end
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
#--
|
|
4
|
-
# SPDX-FileCopyrightText: 2026 Kerrick Long <me@kerricklong.com>
|
|
5
|
-
# SPDX-License-Identifier: AGPL-3.0-or-later
|
|
6
|
-
#++
|
|
7
|
-
|
|
8
|
-
# Cycles through a set of colors for event logging.
|
|
9
|
-
#
|
|
10
|
-
# Sequential events in a log are hard to distinguish if they all look the same.
|
|
11
|
-
# Manually assigning colors to every event type or entry is repetitive.
|
|
12
|
-
#
|
|
13
|
-
# This class automatically cycles through a predefined list of vibrant colors.
|
|
14
|
-
#
|
|
15
|
-
# Use it to give each event in a log a distinct visual identity.
|
|
16
|
-
#
|
|
17
|
-
# === Examples
|
|
18
|
-
#
|
|
19
|
-
# cycler = EventColorCycle.new
|
|
20
|
-
# cycler.next_color #=> :cyan
|
|
21
|
-
# cycler.next_color #=> :magenta
|
|
22
|
-
# cycler.next_color #=> :yellow
|
|
23
|
-
# cycler.next_color #=> :cyan
|
|
24
|
-
class EventColorCycle
|
|
25
|
-
# List of colors to cycle through.
|
|
26
|
-
COLORS = %i[cyan magenta yellow].freeze
|
|
27
|
-
|
|
28
|
-
# Creates a new EventColorCycle.
|
|
29
|
-
def initialize
|
|
30
|
-
@index = 0
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
# Returns the next color in the cycle.
|
|
34
|
-
#
|
|
35
|
-
# === Example
|
|
36
|
-
#
|
|
37
|
-
# cycler.next_color #=> :cyan
|
|
38
|
-
def next_color
|
|
39
|
-
color = COLORS[@index]
|
|
40
|
-
@index = (@index + 1) % COLORS.length
|
|
41
|
-
color
|
|
42
|
-
end
|
|
43
|
-
end
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
#--
|
|
4
|
-
# SPDX-FileCopyrightText: 2026 Kerrick Long <me@kerricklong.com>
|
|
5
|
-
# SPDX-License-Identifier: AGPL-3.0-or-later
|
|
6
|
-
#++
|
|
7
|
-
|
|
8
|
-
require_relative "timestamp"
|
|
9
|
-
require "ratatui_ruby"
|
|
10
|
-
|
|
11
|
-
# Stores details about a single event in the history log.
|
|
12
|
-
#
|
|
13
|
-
# Event logs need to store diverse data including types, keys, colors, and timestamps.
|
|
14
|
-
# Managing loose hashes or arrays for event history is error-prone and hard to query.
|
|
15
|
-
#
|
|
16
|
-
# This class provides a structured data object for every recorded event.
|
|
17
|
-
#
|
|
18
|
-
# Use it to represent mouse clicks, key presses, or resize events in a log.
|
|
19
|
-
#
|
|
20
|
-
# === Examples
|
|
21
|
-
#
|
|
22
|
-
# # Typically created via Events.record
|
|
23
|
-
# entry = EventEntry.create(key_event, :cyan, Timestamp.now)
|
|
24
|
-
# puts entry.type #=> :key
|
|
25
|
-
# puts entry.description #=> '#<RatatuiRuby::Event::Key ...>'
|
|
26
|
-
class EventEntry < Data.define(:event, :color, :timestamp)
|
|
27
|
-
# Creates a new EventEntry.
|
|
28
|
-
#
|
|
29
|
-
# [event] RatatuiRuby::Event object.
|
|
30
|
-
# [color] Symbol color for the log display.
|
|
31
|
-
# [timestamp] Timestamp of when the event occurred.
|
|
32
|
-
def self.create(event, color, timestamp)
|
|
33
|
-
new(
|
|
34
|
-
event:,
|
|
35
|
-
color:,
|
|
36
|
-
timestamp:
|
|
37
|
-
)
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
# Returns the event type.
|
|
41
|
-
#
|
|
42
|
-
# === Example
|
|
43
|
-
#
|
|
44
|
-
# entry.type #=> :key
|
|
45
|
-
def type
|
|
46
|
-
case event
|
|
47
|
-
when RatatuiRuby::Event::Key then :key
|
|
48
|
-
when RatatuiRuby::Event::Mouse then :mouse
|
|
49
|
-
when RatatuiRuby::Event::Resize then :resize
|
|
50
|
-
when RatatuiRuby::Event::Paste then :paste
|
|
51
|
-
when RatatuiRuby::Event::FocusGained then :focus_gained
|
|
52
|
-
when RatatuiRuby::Event::FocusLost then :focus_lost
|
|
53
|
-
else :unknown
|
|
54
|
-
end
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
# Returns the event description using inspect.
|
|
58
|
-
#
|
|
59
|
-
# === Example
|
|
60
|
-
#
|
|
61
|
-
# entry.description #=> '#<RatatuiRuby::Event::Key code="a" modifiers=[]>'
|
|
62
|
-
def description
|
|
63
|
-
event.inspect
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
# Checks if the entry matches the given type.
|
|
67
|
-
#
|
|
68
|
-
# [check_type] Symbol type to check against.
|
|
69
|
-
#
|
|
70
|
-
# === Example
|
|
71
|
-
#
|
|
72
|
-
# entry.matches_type?(:key) #=> true
|
|
73
|
-
def matches_type?(check_type)
|
|
74
|
-
return true if check_type == :focus && (type == :focus_gained || type == :focus_lost)
|
|
75
|
-
|
|
76
|
-
type == check_type
|
|
77
|
-
end
|
|
78
|
-
|
|
79
|
-
# Returns the display type for live event grouping.
|
|
80
|
-
#
|
|
81
|
-
# Normalizes focus_gained and focus_lost to :focus.
|
|
82
|
-
#
|
|
83
|
-
# === Example
|
|
84
|
-
#
|
|
85
|
-
# entry.live_type #=> :focus
|
|
86
|
-
def live_type
|
|
87
|
-
case type
|
|
88
|
-
when :focus_gained, :focus_lost
|
|
89
|
-
:focus
|
|
90
|
-
else
|
|
91
|
-
type
|
|
92
|
-
end
|
|
93
|
-
end
|
|
94
|
-
end
|