Class: AsciinemaWin::Themes::Theme
- Inherits:
-
Data
- Object
- Data
- AsciinemaWin::Themes::Theme
- Defined in:
- lib/asciinema_win/themes.rb
Overview
Base theme structure
Instance Attribute Summary collapse
-
#background ⇒ Object
readonly
Returns the value of attribute background.
-
#cursor ⇒ Object
readonly
Returns the value of attribute cursor.
-
#foreground ⇒ Object
readonly
Returns the value of attribute foreground.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#palette ⇒ Object
readonly
Returns the value of attribute palette.
Instance Method Summary collapse
-
#bg_color(code) ⇒ String
Get background color for ANSI code.
-
#color(index) ⇒ String
Get color for ANSI color index.
-
#fg_color(code) ⇒ String
Get foreground color for ANSI code.
Instance Attribute Details
#background ⇒ Object (readonly)
Returns the value of attribute 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 |
#cursor ⇒ Object (readonly)
Returns the value of attribute 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 |
#foreground ⇒ Object (readonly)
Returns the value of attribute 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 |
#name ⇒ Object (readonly)
Returns the value of attribute 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 |
#palette ⇒ Object (readonly)
Returns the value of attribute 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
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
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
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 |