class RatatuiRuby::Event::Mouse
Reports a mouse interaction.
Modern terminals support rich pointer input, but the protocols are complex and varied. Handling clicks, drags, and scrolls requires robust parsing.
This event simplifies the complexity. It tells you exactly what happened (kind), where it happened (x, y), and which button was involved.
Use this to build interactive UIs. Implement click handlers, draggable sliders, or scrollable viewports with confidence.
Example
if event.mouse? && event.down? && event.button == "left" puts "Left click at #{event.x}, #{event.y}" end
Attributes
The kind of event ("down", "up", "drag", "moved", "scroll_up", "scroll_down").
puts event.kind # => "down"
List of active modifiers.
puts event.modifiers # => ["ctrl"]
X coordinate (column).
puts event.x # => 10
Y coordinate (row).
puts event.y # => 5
Public Class Methods
Source
# File lib/ratatui_ruby/event/mouse.rb, line 71 def initialize(kind:, x:, y:, button:, modifiers: []) @kind = kind.freeze @x = x @y = y @button = (button || "none").freeze @modifiers = modifiers.map(&:freeze).sort.freeze end
Public Instance Methods
Source
# File lib/ratatui_ruby/event/mouse.rb, line 120 def ==(other) return false unless other.is_a?(Mouse) kind == other.kind && x == other.x && y == other.y && button == other.button && modifiers == other.modifiers end
Compares this event with another for equality.
Source
# File lib/ratatui_ruby/event/mouse.rb, line 114 def deconstruct_keys(keys) { type: :mouse, kind: @kind, x: @x, y: @y, button: @button, modifiers: @modifiers } end
Deconstructs the event for pattern matching.
case event in type: :mouse, kind: "down", x:, y: puts "Click at #{x}, #{y}" end
Source
# File lib/ratatui_ruby/event/mouse.rb, line 80 def down? @kind == "down" end
Returns true if mouse button was pressed down.
Source
# File lib/ratatui_ruby/event/mouse.rb, line 90 def drag? @kind == "drag" end
Returns true if mouse is being dragged.
Source
# File lib/ratatui_ruby/event/mouse.rb, line 55 def mouse? true end
Returns true for Mouse events.
event.mouse? # => true event.key? # => false event.resize? # => false
Source
# File lib/ratatui_ruby/event/mouse.rb, line 104 def scroll_down? @kind == "scroll_down" end
Returns true if scroll wheel moved down.
if event.scroll_down? scroll_offset += 1 end
Source
# File lib/ratatui_ruby/event/mouse.rb, line 95 def scroll_up? @kind == "scroll_up" end
Returns true if scroll wheel moved up.
Source
# File lib/ratatui_ruby/event/mouse.rb, line 85 def up? @kind == "up" end
Returns true if mouse button was released.