Class: RatatuiRuby::Event::FocusLost

Inherits:
RatatuiRuby::Event show all
Defined in:
lib/ratatui_ruby/event/focus_lost.rb

Overview

Signals that the application is in the background.

The user has switched context. Your application is no longer the primary focus.

This event warns of inactivity. It fires when the terminal window loses focus.

Respond by conserving resources. Pause animations. Stop heavy polling. dim the UI to indicate a background state.

Only supported by some terminals (e.g. iTerm2, Kitty, newer xterm).

Example

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

if event.focus_lost?
  puts "Focus lost"
end

– SPDX-SnippetEnd ++

Instance Method Summary collapse

Methods inherited from RatatuiRuby::Event

#focus_gained?, #key?, #method_missing, #mouse?, #none?, #paste?, #resize?, #respond_to_missing?, #sync?

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class RatatuiRuby::Event

Instance Method Details

#==(other) ⇒ Object

Compares this event with another for equality.



71
72
73
# File 'lib/ratatui_ruby/event/focus_lost.rb', line 71

def ==(other)
  other.is_a?(FocusLost)
end

#active?Boolean Also known as: foreground?

Returns false. The application is not active.

event.active? # => false

Returns:

  • (Boolean)


121
122
123
# File 'lib/ratatui_ruby/event/focus_lost.rb', line 121

def active?
  false
end

#blur?Boolean Also known as: blurred?

Returns true. The terminal has lost focus (blur).

event.blur? # => true

Returns:

  • (Boolean)


82
83
84
# File 'lib/ratatui_ruby/event/focus_lost.rb', line 82

def blur?
  true
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: :focus_lost
  puts "Application lost focus"
end

– SPDX-SnippetEnd ++



65
66
67
# File 'lib/ratatui_ruby/event/focus_lost.rb', line 65

def deconstruct_keys(keys)
  { type: :focus_lost }
end

#focus?Boolean Also known as: focused?

Returns false. This is not a focus gained event.

event.focus? # => false

Returns:

  • (Boolean)


98
99
100
# File 'lib/ratatui_ruby/event/focus_lost.rb', line 98

def focus?
  false
end

#focus_lost?Boolean

Returns true for FocusLost events.

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

event.focus_lost? # => true
event.key?        # => false

– SPDX-SnippetEnd ++

Returns:

  • (Boolean)


47
48
49
# File 'lib/ratatui_ruby/event/focus_lost.rb', line 47

def focus_lost?
  true
end

#gained?Boolean

Returns false. This is not a gained event.

event.gained? # => false

Returns:

  • (Boolean)


106
107
108
# File 'lib/ratatui_ruby/event/focus_lost.rb', line 106

def gained?
  false
end

#inactive?Boolean Also known as: background?

Returns true. The application is inactive.

event.inactive? # => true

Returns:

  • (Boolean)


113
114
115
# File 'lib/ratatui_ruby/event/focus_lost.rb', line 113

def inactive?
  true
end

#lost?Boolean Also known as: unfocused?

Returns true. The application lost focus.

event.lost? # => true

Returns:

  • (Boolean)


90
91
92
# File 'lib/ratatui_ruby/event/focus_lost.rb', line 90

def lost?
  true
end