class RatatuiRuby::Event::Resize
Signals a change in terminal dimensions.
The terminal window is dynamic, not static. The user changes its dimensions at will, usually breaking a fixed layout.
This event captures the new state. It delivers the updated width and height immediately after the change.
Use these dimensions to drive your layout logic. Recalculate constraints. Reallocate space. Fill the new canvas completely to maintain a responsive design.
Examples
Using predicates:
if event.resize? puts "Resized to #{event.width}x#{event.height}" end
Using pattern matching:
case event in type: :resize, width:, height: puts "Resized to #{width}x#{height}" end
Attributes
New terminal height in rows.
puts event.height # => 24
New terminal width in columns.
puts event.width # => 80
Public Class Methods
Source
# File lib/ratatui_ruby/event/resize.rb, line 83 def initialize(width:, height:) @width = width @height = height end
Creates a new Resize event.
- width
-
New width (Integer).
- height
-
New height (Integer).
Public Instance Methods
Source
# File lib/ratatui_ruby/event/resize.rb, line 147 def ==(other) case other when Symbol then to_sym == other when Resize then width == other.width && height == other.height else false end end
Source
# File lib/ratatui_ruby/event/resize.rb, line 200 def at_least_vt100? @width >= VT100_WIDTH && @height >= VT100_HEIGHT end
Returns true if both dimensions meet or exceed 80x24.
Event::Resize.new(width: 120, height: 40).at_least_vt100? # => true
Source
# File lib/ratatui_ruby/event/resize.rb, line 214 def cramped? @width < VT100_WIDTH || @height < VT100_HEIGHT end
Returns true if either dimension falls below VT100 standard.
Event::Resize.new(width: 60, height: 24).cramped? # => true
Source
# File lib/ratatui_ruby/event/resize.rb, line 102 def deconstruct_keys(keys) { type: :resize, width: @width, height: @height } end
Deconstructs the event for pattern matching.
case event in type: :resize, width:, height: puts "Resized to #{width}x#{height}" end
Source
# File lib/ratatui_ruby/event/resize.rb, line 179 def landscape? @width > @height end
Returns true if width exceeds height.
Event::Resize.new(width: 120, height: 24).landscape? # => true
Source
# File lib/ratatui_ruby/event/resize.rb, line 207 def over_vt100? @width > VT100_WIDTH && @height > VT100_HEIGHT end
Returns true if both dimensions exceed 80x24.
Event::Resize.new(width: 81, height: 25).over_vt100? # => true
Source
# File lib/ratatui_ruby/event/resize.rb, line 186 def portrait? @height >= @width end
Returns true if height exceeds or equals width.
Event::Resize.new(width: 40, height: 80).portrait? # => true
Source
# File lib/ratatui_ruby/event/resize.rb, line 73 def resize? true end
Returns true for Resize events.
event.resize? # => true event.key? # => false event.mouse? # => false
Source
# File lib/ratatui_ruby/event/resize.rb, line 158 def sigwinch? true end
Returns true. Unix SIGWINCH triggers terminal resize.
event.sigwinch? # => true
Source
# File lib/ratatui_ruby/event/resize.rb, line 123 def to_sym :resize end
Converts the event to a Symbol representation.
Always returns :resize.
Example
event = Event::Resize.new(width: 80, height: 24) event.to_sym # => :resize
Source
# File lib/ratatui_ruby/event/resize.rb, line 193 def vt100? @width == VT100_WIDTH && @height == VT100_HEIGHT end
Returns true if dimensions are exactly 80x24.
Event::Resize.new(width: 80, height: 24).vt100? # => true