Class: Tuile::EventQueue::ColorSchemeEvent

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

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)

@return:light or :dark.

Returns:

  • (Symbol)


218
219
220
221
222
223
224
225
226
227
228
229
230
231
# File 'lib/tuile/event_queue.rb', line 218

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?

@param key — key read via Keys.getkey.

@return — nil when key is not a color-scheme report.

Parameters:

  • key (String)

Returns:



227
228
229
230
# File 'lib/tuile/event_queue.rb', line 227

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