Class: Tuile::EventQueue::ColorSchemeEvent

Inherits:
Object
  • Object
show all
Defined in:
lib/tuile/event_queue.rb

Overview

The terminal’s color scheme changed — the user flipped the OS between light and dark appearance. Terminals supporting mode 2031 (kitty, foot, contour, ghostty, …) push the DSR-style report ‘e[?997;1n` (dark) / `e[?997;2n` (light) once Screen#run_event_loop enables the mode via TerminalBackground::NOTIFY_ON; the key thread parses it into this event and Screen#event_loop follows by assigning the matching Theme.

Constant Summary collapse

REPORT =

The DSR-style color-scheme report: ‘e[?997;1n` dark, `e[?997;2n` light.

Returns:

  • (Regexp)
/\A\e\[\?997;([12])n\z/

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#schemeSymbol (readonly)

Returns ‘:light` or `:dark`.

Returns:

  • (Symbol)

    ‘:light` or `:dark`.



197
198
199
200
201
202
203
204
205
206
207
208
209
210
# File 'lib/tuile/event_queue.rb', line 197

class ColorSchemeEvent < Data.define(:scheme)
  # The DSR-style color-scheme report: `\e[?997;1n` dark, `\e[?997;2n`
  # light.
  # @return [Regexp]
  REPORT = /\A\e\[\?997;([12])n\z/

  # @param key [String] key read via {Keys.getkey}.
  # @return [ColorSchemeEvent, nil] nil when `key` is not a
  #   color-scheme report.
  def self.parse(key)
    match = REPORT.match(key)
    match && new(match[1] == "2" ? :light : :dark)
  end
end

Class Method Details

.parse(key) ⇒ ColorSchemeEvent?

Returns nil when ‘key` is not a color-scheme report.

Parameters:

Returns:



206
207
208
209
# File 'lib/tuile/event_queue.rb', line 206

def self.parse(key)
  match = REPORT.match(key)
  match && new(match[1] == "2" ? :light : :dark)
end