Class: AsciinemaWin::Themes::Theme

Inherits:
Data
  • Object
show all
Defined in:
lib/asciinema_win/themes.rb

Overview

Base theme structure

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#backgroundObject (readonly)

Returns the value of attribute background

Returns:

  • (Object)

    the current value of background



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/asciinema_win/themes.rb', line 20

Theme = Data.define(:name, :background, :foreground, :cursor, :palette) do
  # Get color for ANSI color index
  #
  # @param index [Integer] ANSI color index (0-15 for basic, 16-255 for extended)
  # @return [String] Hex color code
  def color(index)
    if index < 16
      palette[index]
    elsif index < 232
      # 216 color cube (6x6x6)
      index -= 16
      r = (index / 36) % 6
      g = (index / 6) % 6
      b = index % 6
      r_val = r == 0 ? 0 : 55 + r * 40
      g_val = g == 0 ? 0 : 55 + g * 40
      b_val = b == 0 ? 0 : 55 + b * 40
      format("#%02x%02x%02x", r_val, g_val, b_val)
    else
      # 24 grayscale colors
      gray = (index - 232) * 10 + 8
      format("#%02x%02x%02x", gray, gray, gray)
    end
  end

  # Get foreground color for ANSI code
  #
  # @param code [Integer] ANSI SGR foreground code (30-37, 90-97)
  # @return [String] Hex color code
  def fg_color(code)
    case code
    when 30..37 then palette[code - 30]
    when 90..97 then palette[code - 90 + 8]
    when 39 then foreground
    else foreground
    end
  end

  # Get background color for ANSI code
  #
  # @param code [Integer] ANSI SGR background code (40-47, 100-107)
  # @return [String] Hex color code
  def bg_color(code)
    case code
    when 40..47 then palette[code - 40]
    when 100..107 then palette[code - 100 + 8]
    when 49 then background
    else background
    end
  end
end

#cursorObject (readonly)

Returns the value of attribute cursor

Returns:

  • (Object)

    the current value of cursor



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/asciinema_win/themes.rb', line 20

Theme = Data.define(:name, :background, :foreground, :cursor, :palette) do
  # Get color for ANSI color index
  #
  # @param index [Integer] ANSI color index (0-15 for basic, 16-255 for extended)
  # @return [String] Hex color code
  def color(index)
    if index < 16
      palette[index]
    elsif index < 232
      # 216 color cube (6x6x6)
      index -= 16
      r = (index / 36) % 6
      g = (index / 6) % 6
      b = index % 6
      r_val = r == 0 ? 0 : 55 + r * 40
      g_val = g == 0 ? 0 : 55 + g * 40
      b_val = b == 0 ? 0 : 55 + b * 40
      format("#%02x%02x%02x", r_val, g_val, b_val)
    else
      # 24 grayscale colors
      gray = (index - 232) * 10 + 8
      format("#%02x%02x%02x", gray, gray, gray)
    end
  end

  # Get foreground color for ANSI code
  #
  # @param code [Integer] ANSI SGR foreground code (30-37, 90-97)
  # @return [String] Hex color code
  def fg_color(code)
    case code
    when 30..37 then palette[code - 30]
    when 90..97 then palette[code - 90 + 8]
    when 39 then foreground
    else foreground
    end
  end

  # Get background color for ANSI code
  #
  # @param code [Integer] ANSI SGR background code (40-47, 100-107)
  # @return [String] Hex color code
  def bg_color(code)
    case code
    when 40..47 then palette[code - 40]
    when 100..107 then palette[code - 100 + 8]
    when 49 then background
    else background
    end
  end
end

#foregroundObject (readonly)

Returns the value of attribute foreground

Returns:

  • (Object)

    the current value of foreground



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/asciinema_win/themes.rb', line 20

Theme = Data.define(:name, :background, :foreground, :cursor, :palette) do
  # Get color for ANSI color index
  #
  # @param index [Integer] ANSI color index (0-15 for basic, 16-255 for extended)
  # @return [String] Hex color code
  def color(index)
    if index < 16
      palette[index]
    elsif index < 232
      # 216 color cube (6x6x6)
      index -= 16
      r = (index / 36) % 6
      g = (index / 6) % 6
      b = index % 6
      r_val = r == 0 ? 0 : 55 + r * 40
      g_val = g == 0 ? 0 : 55 + g * 40
      b_val = b == 0 ? 0 : 55 + b * 40
      format("#%02x%02x%02x", r_val, g_val, b_val)
    else
      # 24 grayscale colors
      gray = (index - 232) * 10 + 8
      format("#%02x%02x%02x", gray, gray, gray)
    end
  end

  # Get foreground color for ANSI code
  #
  # @param code [Integer] ANSI SGR foreground code (30-37, 90-97)
  # @return [String] Hex color code
  def fg_color(code)
    case code
    when 30..37 then palette[code - 30]
    when 90..97 then palette[code - 90 + 8]
    when 39 then foreground
    else foreground
    end
  end

  # Get background color for ANSI code
  #
  # @param code [Integer] ANSI SGR background code (40-47, 100-107)
  # @return [String] Hex color code
  def bg_color(code)
    case code
    when 40..47 then palette[code - 40]
    when 100..107 then palette[code - 100 + 8]
    when 49 then background
    else background
    end
  end
end

#nameObject (readonly)

Returns the value of attribute name

Returns:

  • (Object)

    the current value of name



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/asciinema_win/themes.rb', line 20

Theme = Data.define(:name, :background, :foreground, :cursor, :palette) do
  # Get color for ANSI color index
  #
  # @param index [Integer] ANSI color index (0-15 for basic, 16-255 for extended)
  # @return [String] Hex color code
  def color(index)
    if index < 16
      palette[index]
    elsif index < 232
      # 216 color cube (6x6x6)
      index -= 16
      r = (index / 36) % 6
      g = (index / 6) % 6
      b = index % 6
      r_val = r == 0 ? 0 : 55 + r * 40
      g_val = g == 0 ? 0 : 55 + g * 40
      b_val = b == 0 ? 0 : 55 + b * 40
      format("#%02x%02x%02x", r_val, g_val, b_val)
    else
      # 24 grayscale colors
      gray = (index - 232) * 10 + 8
      format("#%02x%02x%02x", gray, gray, gray)
    end
  end

  # Get foreground color for ANSI code
  #
  # @param code [Integer] ANSI SGR foreground code (30-37, 90-97)
  # @return [String] Hex color code
  def fg_color(code)
    case code
    when 30..37 then palette[code - 30]
    when 90..97 then palette[code - 90 + 8]
    when 39 then foreground
    else foreground
    end
  end

  # Get background color for ANSI code
  #
  # @param code [Integer] ANSI SGR background code (40-47, 100-107)
  # @return [String] Hex color code
  def bg_color(code)
    case code
    when 40..47 then palette[code - 40]
    when 100..107 then palette[code - 100 + 8]
    when 49 then background
    else background
    end
  end
end

#paletteObject (readonly)

Returns the value of attribute palette

Returns:

  • (Object)

    the current value of palette



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/asciinema_win/themes.rb', line 20

Theme = Data.define(:name, :background, :foreground, :cursor, :palette) do
  # Get color for ANSI color index
  #
  # @param index [Integer] ANSI color index (0-15 for basic, 16-255 for extended)
  # @return [String] Hex color code
  def color(index)
    if index < 16
      palette[index]
    elsif index < 232
      # 216 color cube (6x6x6)
      index -= 16
      r = (index / 36) % 6
      g = (index / 6) % 6
      b = index % 6
      r_val = r == 0 ? 0 : 55 + r * 40
      g_val = g == 0 ? 0 : 55 + g * 40
      b_val = b == 0 ? 0 : 55 + b * 40
      format("#%02x%02x%02x", r_val, g_val, b_val)
    else
      # 24 grayscale colors
      gray = (index - 232) * 10 + 8
      format("#%02x%02x%02x", gray, gray, gray)
    end
  end

  # Get foreground color for ANSI code
  #
  # @param code [Integer] ANSI SGR foreground code (30-37, 90-97)
  # @return [String] Hex color code
  def fg_color(code)
    case code
    when 30..37 then palette[code - 30]
    when 90..97 then palette[code - 90 + 8]
    when 39 then foreground
    else foreground
    end
  end

  # Get background color for ANSI code
  #
  # @param code [Integer] ANSI SGR background code (40-47, 100-107)
  # @return [String] Hex color code
  def bg_color(code)
    case code
    when 40..47 then palette[code - 40]
    when 100..107 then palette[code - 100 + 8]
    when 49 then background
    else background
    end
  end
end

Instance Method Details

#bg_color(code) ⇒ String

Get background color for ANSI code

Parameters:

  • code (Integer)

    ANSI SGR background code (40-47, 100-107)

Returns:

  • (String)

    Hex color code



62
63
64
65
66
67
68
69
# File 'lib/asciinema_win/themes.rb', line 62

def bg_color(code)
  case code
  when 40..47 then palette[code - 40]
  when 100..107 then palette[code - 100 + 8]
  when 49 then background
  else background
  end
end

#color(index) ⇒ String

Get color for ANSI color index

Parameters:

  • index (Integer)

    ANSI color index (0-15 for basic, 16-255 for extended)

Returns:

  • (String)

    Hex color code



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/asciinema_win/themes.rb', line 25

def color(index)
  if index < 16
    palette[index]
  elsif index < 232
    # 216 color cube (6x6x6)
    index -= 16
    r = (index / 36) % 6
    g = (index / 6) % 6
    b = index % 6
    r_val = r == 0 ? 0 : 55 + r * 40
    g_val = g == 0 ? 0 : 55 + g * 40
    b_val = b == 0 ? 0 : 55 + b * 40
    format("#%02x%02x%02x", r_val, g_val, b_val)
  else
    # 24 grayscale colors
    gray = (index - 232) * 10 + 8
    format("#%02x%02x%02x", gray, gray, gray)
  end
end

#fg_color(code) ⇒ String

Get foreground color for ANSI code

Parameters:

  • code (Integer)

    ANSI SGR foreground code (30-37, 90-97)

Returns:

  • (String)

    Hex color code



49
50
51
52
53
54
55
56
# File 'lib/asciinema_win/themes.rb', line 49

def fg_color(code)
  case code
  when 30..37 then palette[code - 30]
  when 90..97 then palette[code - 90 + 8]
  when 39 then foreground
  else foreground
  end
end