Class: RatatuiRuby::Event::Resize

Inherits:
RatatuiRuby::Event show all
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

Instance Method Summary collapse

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

#heightObject (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

#widthObject (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 other is a Symbol, compares against #to_sym.

  • If other is a Resize, 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

Returns true if both dimensions meet or exceed 80x24.

Event::Resize.new(width: 120, height: 40).at_least_vt100? # => true

Returns:

  • (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?

Returns true if either dimension falls below VT100 standard.

Event::Resize.new(width: 60, height: 24).cramped? # => true

Returns:

  • (Boolean)


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

Returns true if width exceeds height.

Event::Resize.new(width: 120, height: 24).landscape? # => true

Returns:

  • (Boolean)


179
180
181
# File 'lib/ratatui_ruby/event/resize.rb', line 179

def landscape?
  @width > @height
end

#over_vt100?Boolean

Returns true if both dimensions exceed 80x24.

Event::Resize.new(width: 81, height: 25).over_vt100? # => true

Returns:

  • (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

Returns true if height exceeds or equals width.

Event::Resize.new(width: 40, height: 80).portrait? # => true

Returns:

  • (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 ++

Returns:

  • (Boolean)


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

Returns:

  • (Boolean)


158
159
160
# File 'lib/ratatui_ruby/event/resize.rb', line 158

def sigwinch?
  true
end

#to_symObject

Converts the event to a Symbol representation.

Always returns :resize.

Example

– SPDX-SnippetBegin SPDX-FileCopyrightText: 2026 Kerrick Long SPDX-License-Identifier: MIT-0 ++

event = Event::Resize.new(width: 80, height: 24)
event.to_sym # => :resize

– SPDX-SnippetEnd ++



123
124
125
# File 'lib/ratatui_ruby/event/resize.rb', line 123

def to_sym
  :resize
end

#vt100?Boolean

Returns true if dimensions are exactly 80x24.

Event::Resize.new(width: 80, height: 24).vt100? # => true

Returns:

  • (Boolean)


193
194
195
# File 'lib/ratatui_ruby/event/resize.rb', line 193

def vt100?
  @width == VT100_WIDTH && @height == VT100_HEIGHT
end