module RatatuiRuby::Tea::Router::ClassMethods
Class methods added when Router is included.
Public Instance Methods
Source
# File lib/ratatui_ruby/tea/router.rb, line 91 def action(name, handler) actions[name.to_s.to_sym] = handler end
Declares a named action.
Actions are shared handlers that keymap and mousemap can reference. This avoids duplicating logic for keys and mouse events that do the same thing.
- name
-
Symbol or String identifying the action (normalized via
.to_s.to_sym). - handler
-
Callable that returns a command or message.
Source
# File lib/ratatui_ruby/tea/router.rb, line 96 def actions @actions ||= {} end
Returns the registered actions hash.
Source
# File lib/ratatui_ruby/tea/router.rb, line 151 def from_router RouterUpdate.new( routes:, actions:, key_handlers:, scroll_handlers:, click_handler: ) end
Generates an UPDATE lambda from routes, keymap, and mousemap.
The generated UPDATE:
-
Routes prefixed messages to child UPDATEs
-
Handles keyboard events via keymap
-
Handles mouse events via mousemap
-
Returns model unchanged for unhandled messages
Source
# File lib/ratatui_ruby/tea/router.rb, line 108 def keymap(&) builder = KeymapBuilder.new builder.instance_eval(&) @key_handlers = builder.handlers end
Declares key handlers in a block.
Example
keymap do key "q", -> { Command.exit } key :up, :scroll_up # Delegate to action end
Source
# File lib/ratatui_ruby/tea/router.rb, line 122 def mousemap(&) builder = MousemapBuilder.new builder.instance_eval(&) @scroll_handlers = builder.scroll_handlers @click_handler = builder.click_handler end
Declares mouse handlers in a block.
Example
mousemap do click -> (x, y) { [:clicked, x, y] } scroll :up, :scroll_up # Delegate to action end
Source
# File lib/ratatui_ruby/tea/router.rb, line 74 def route(prefix, to:) routes[prefix.to_s.to_sym] = to end
Declares a route to a child.
- prefix
-
Symbol or String identifying the route (normalized via
.to_s.to_sym). - to
-
The child module (must have UPDATE and INITIAL constants).
Source
# File lib/ratatui_ruby/tea/router.rb, line 79 def routes @routes ||= {} end
Returns the registered routes hash.