Class: Rich::TerminalTheme

Inherits:
Object
  • Object
show all
Defined in:
lib/rich/terminal_theme.rb

Overview

Terminal color theme configuration. Defines the actual RGB values for ANSI colors as rendered by a terminal.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(foreground:, background:, ansi_colors:) ⇒ TerminalTheme

Create a new terminal theme

Parameters:

Raises:

  • (ArgumentError)


23
24
25
26
27
28
29
30
# File 'lib/rich/terminal_theme.rb', line 23

def initialize(foreground:, background:, ansi_colors:)
  raise ArgumentError, "ansi_colors must have exactly 16 colors" unless ansi_colors.length == 16

  @foreground = foreground
  @background = background
  @ansi_colors = ansi_colors.freeze
  freeze
end

Instance Attribute Details

#ansi_colorsArray<ColorTriplet> (readonly)

Returns 16 ANSI colors (indices 0-15).

Returns:



17
18
19
# File 'lib/rich/terminal_theme.rb', line 17

def ansi_colors
  @ansi_colors
end

#backgroundColorTriplet (readonly)

Returns Default background color.

Returns:



14
15
16
# File 'lib/rich/terminal_theme.rb', line 14

def background
  @background
end

#foregroundColorTriplet (readonly)

Returns Default foreground color.

Returns:



11
12
13
# File 'lib/rich/terminal_theme.rb', line 11

def foreground
  @foreground
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?

Check equality with another theme



33
34
35
36
37
38
39
# File 'lib/rich/terminal_theme.rb', line 33

def ==(other)
  return false unless other.is_a?(TerminalTheme)

  @foreground == other.foreground &&
    @background == other.background &&
    @ansi_colors == other.ansi_colors
end

#hashObject



43
44
45
# File 'lib/rich/terminal_theme.rb', line 43

def hash
  [@foreground, @background, @ansi_colors].hash
end