class

TermBuf::ColorStack

Inherits Reference < Object

Stability: stable — changes only in a major release.

The terminal's own colours: the default foreground and background, the cursor, and the 256 entry palette everything indexed resolves through.

These are not cell attributes. Changing one repaints nothing and shows up everywhere at once, including in text this shard never wrote.

Which is why it is all gated on Capability::KittyColorStack. The stack is what makes a change reversible: push, change what you like, pop, and the terminal is as it was. Without somewhere to put the old values there is no way to give them back, and a shard that leaves a terminal a different colour than it found it is worse than one that leaves the colours alone.

terminal.colors.push
terminal.colors.background = Color.rgb(20, 20, 30)
# ...
terminal.colors.pop

Terminal#close pops whatever is still pushed, so an application that forgets, or that stops on a signal, still gives the terminal back.

Constants

OSC = "\e]"
POP = "#{OSC}30101#{ST}"
PUSH = "#{OSC}30001#{ST}"

What kitty's colour stack listens for: OSC 30001 ST saves, OSC 30101 ST restores. These are the sequences the capability is named for. xterm later took the idea with CSI # P and CSI # Q, and kitty accepts those too on paper, but kitty 0.48.2 was seen to ignore the xterm form and answer its own.

ST = "\e\\"

Constructors

new(capabilities : Capabilities, &sink : Bytes -> Nil)
Source

Instance methods

[]=(index : Int32, color : Color) : Color

Sets one entry of the 256 colour palette.

Source
available?

Whether the terminal will take any of this.

Source
background=(color : Color) : Color

Sets the terminal's background colour.

Source
capabilities

What the terminal can do, which for everything here means one flag.

Source
cursor=(color : Color) : Color

Sets the terminal's cursor colour.

Source
depth

How deep the stack is, counting only what this object pushed.

Source
foreground=(color : Color) : Color

Sets the terminal's foreground colour.

Source
pop

Restores the colours saved by the matching #push. Does nothing when nothing is pushed, so an extra pop cannot walk off the end of a stack something else was using.

Source
pop_all

Pops everything this object pushed.

Source
push

Saves the terminal's current colours so #pop can put them back.

Source
reset

Puts the palette and the default colours back to what the terminal was configured with, which is not the same as what was pushed.

Source
saved

Runs the block with the colours saved, and puts them back however it ends.

Source
selection_background=(color : Color) : Color

Sets the terminal's selection background colour.

Source
selection_foreground=(color : Color) : Color

Sets the terminal's selection foreground colour.

Source