Class: RatatuiRuby::Event::Resize
- Inherits:
-
RatatuiRuby::Event
- Object
- RatatuiRuby::Event
- RatatuiRuby::Event::Resize
- Defined in:
- lib/ratatui_ruby/event/resize.rb
Overview
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: – SPDX-SnippetBegin SPDX-FileCopyrightText: 2025 Kerrick Long SPDX-License-Identifier: MIT-0 ++
if event.resize?
puts "Resized to #{event.width}x#{event.height}"
end
– SPDX-SnippetEnd ++ Using pattern matching: – SPDX-SnippetBegin SPDX-FileCopyrightText: 2025 Kerrick Long SPDX-License-Identifier: MIT-0 ++
case event
in type: :resize, width:, height:
puts "Resized to #{width}x#{height}"
end
– SPDX-SnippetEnd ++
Constant Summary collapse
- VT100_WIDTH =
:nodoc:
80- VT100_HEIGHT =
:nodoc:
24
Instance Attribute Summary collapse
-
#height ⇒ Object
readonly
New terminal height in rows.
-
#width ⇒ Object
readonly
New terminal width in columns.
Instance Method Summary collapse
-
#==(other) ⇒ Object
Compares the event with another object.
-
#at_least_vt100? ⇒ Boolean
Returns true if both dimensions meet or exceed 80x24.
-
#cramped? ⇒ Boolean
(also: #constrained?)
Returns true if either dimension falls below VT100 standard.
-
#deconstruct_keys(keys) ⇒ Object
Deconstructs the event for pattern matching.
-
#initialize(width:, height:) ⇒ Resize
constructor
Creates a new Resize event.
-
#landscape? ⇒ Boolean
Returns true if width exceeds height.
-
#over_vt100? ⇒ Boolean
Returns true if both dimensions exceed 80x24.
-
#portrait? ⇒ Boolean
Returns true if height exceeds or equals width.
-
#resize? ⇒ Boolean
(also: #terminal_resize?, #window_resize?, #window_change?, #viewport_resize?, #viewport_change?, #size_change?, #resized?)
Returns true for Resize events.
-
#sigwinch? ⇒ Boolean
(also: #winch?, #sig_winch?)
Returns true.
-
#to_sym ⇒ Object
Converts the event to a Symbol representation.
-
#vt100? ⇒ Boolean
Returns true if dimensions are exactly 80x24.
Methods inherited from RatatuiRuby::Event
#focus_gained?, #focus_lost?, #key?, #method_missing, #mouse?, #none?, #paste?, #respond_to_missing?, #sync?
Constructor Details
#initialize(width:, height:) ⇒ Resize
Creates a new Resize event.
- width
-
New width (Integer).
- height
-
New height (Integer).
83 84 85 86 |
# File 'lib/ratatui_ruby/event/resize.rb', line 83 def initialize(width:, height:) @width = width @height = height end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class RatatuiRuby::Event
Instance Attribute Details
#height ⇒ Object (readonly)
New terminal height in rows.
puts event.height # => 24
58 59 60 |
# File 'lib/ratatui_ruby/event/resize.rb', line 58 def height @height end |
#width ⇒ Object (readonly)
New terminal width in columns.
puts event.width # => 80
53 54 55 |
# File 'lib/ratatui_ruby/event/resize.rb', line 53 def width @width end |
Instance Method Details
#==(other) ⇒ Object
Compares the event with another object.
-
If
otheris aSymbol, compares against #to_sym. -
If
otheris aResize, compares as a value object. -
Otherwise, returns
false.
Example
– SPDX-SnippetBegin SPDX-FileCopyrightText: 2026 Kerrick Long SPDX-License-Identifier: MIT-0 ++
if event == :resize
handle_resize(event)
end
– SPDX-SnippetEnd ++
147 148 149 150 151 152 153 |
# 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 |
#at_least_vt100? ⇒ Boolean
200 201 202 |
# File 'lib/ratatui_ruby/event/resize.rb', line 200 def at_least_vt100? @width >= VT100_WIDTH && @height >= VT100_HEIGHT end |
#cramped? ⇒ Boolean Also known as: constrained?
214 215 216 |
# File 'lib/ratatui_ruby/event/resize.rb', line 214 def cramped? @width < VT100_WIDTH || @height < VT100_HEIGHT end |
#deconstruct_keys(keys) ⇒ Object
Deconstructs the event for pattern matching.
– SPDX-SnippetBegin SPDX-FileCopyrightText: 2025 Kerrick Long SPDX-License-Identifier: MIT-0 ++
case event
in type: :resize, width:, height:
puts "Resized to #{width}x#{height}"
end
– SPDX-SnippetEnd ++
102 103 104 |
# File 'lib/ratatui_ruby/event/resize.rb', line 102 def deconstruct_keys(keys) { type: :resize, width: @width, height: @height } end |
#landscape? ⇒ Boolean
179 180 181 |
# File 'lib/ratatui_ruby/event/resize.rb', line 179 def landscape? @width > @height end |
#over_vt100? ⇒ Boolean
207 208 209 |
# File 'lib/ratatui_ruby/event/resize.rb', line 207 def over_vt100? @width > VT100_WIDTH && @height > VT100_HEIGHT end |
#portrait? ⇒ Boolean
186 187 188 |
# File 'lib/ratatui_ruby/event/resize.rb', line 186 def portrait? @height >= @width end |
#resize? ⇒ Boolean Also known as: terminal_resize?, window_resize?, window_change?, viewport_resize?, viewport_change?, size_change?, resized?
Returns true for Resize events.
– SPDX-SnippetBegin SPDX-FileCopyrightText: 2025 Kerrick Long SPDX-License-Identifier: MIT-0 ++
event.resize? # => true
event.key? # => false
event.mouse? # => false
– SPDX-SnippetEnd ++
73 74 75 |
# File 'lib/ratatui_ruby/event/resize.rb', line 73 def resize? true end |
#sigwinch? ⇒ Boolean Also known as: winch?, sig_winch?
Returns true. Unix SIGWINCH triggers terminal resize.
event.sigwinch? # => true
158 159 160 |
# File 'lib/ratatui_ruby/event/resize.rb', line 158 def sigwinch? true end |
#to_sym ⇒ Object
123 124 125 |
# File 'lib/ratatui_ruby/event/resize.rb', line 123 def to_sym :resize end |
#vt100? ⇒ Boolean
193 194 195 |
# File 'lib/ratatui_ruby/event/resize.rb', line 193 def vt100? @width == VT100_WIDTH && @height == VT100_HEIGHT end |