rich-ruby 1.0.1 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,126 +1,126 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "color_triplet"
4
- require_relative "_palettes"
5
-
6
- module Rich
7
- # Terminal color theme configuration.
8
- # Defines the actual RGB values for ANSI colors as rendered by a terminal.
9
- class TerminalTheme
10
- # @return [ColorTriplet] Default foreground color
11
- attr_reader :foreground
12
-
13
- # @return [ColorTriplet] Default background color
14
- attr_reader :background
15
-
16
- # @return [Array<ColorTriplet>] 16 ANSI colors (indices 0-15)
17
- attr_reader :ansi_colors
18
-
19
- # Create a new terminal theme
20
- # @param foreground [ColorTriplet] Default foreground color
21
- # @param background [ColorTriplet] Default background color
22
- # @param ansi_colors [Array<ColorTriplet>] 16 ANSI colors
23
- def initialize(foreground:, background:, ansi_colors:)
24
- raise ArgumentError, "ansi_colors must have exactly 16 colors" unless ansi_colors.length == 16
25
-
26
- @foreground = foreground
27
- @background = background
28
- @ansi_colors = ansi_colors.freeze
29
- freeze
30
- end
31
-
32
- # Check equality with another theme
33
- def ==(other)
34
- return false unless other.is_a?(TerminalTheme)
35
-
36
- @foreground == other.foreground &&
37
- @background == other.background &&
38
- @ansi_colors == other.ansi_colors
39
- end
40
-
41
- alias eql? ==
42
-
43
- def hash
44
- [@foreground, @background, @ansi_colors].hash
45
- end
46
- end
47
-
48
- # Default terminal theme (based on typical dark terminal)
49
- DEFAULT_TERMINAL_THEME = TerminalTheme.new(
50
- foreground: ColorTriplet.new(230, 230, 230),
51
- background: ColorTriplet.new(12, 12, 12),
52
- ansi_colors: [
53
- ColorTriplet.new(12, 12, 12), # 0: Black
54
- ColorTriplet.new(205, 49, 49), # 1: Red
55
- ColorTriplet.new(13, 188, 121), # 2: Green
56
- ColorTriplet.new(229, 229, 16), # 3: Yellow
57
- ColorTriplet.new(36, 114, 200), # 4: Blue
58
- ColorTriplet.new(188, 63, 188), # 5: Magenta
59
- ColorTriplet.new(17, 168, 205), # 6: Cyan
60
- ColorTriplet.new(229, 229, 229), # 7: White
61
- ColorTriplet.new(102, 102, 102), # 8: Bright Black
62
- ColorTriplet.new(241, 76, 76), # 9: Bright Red
63
- ColorTriplet.new(35, 209, 139), # 10: Bright Green
64
- ColorTriplet.new(245, 245, 67), # 11: Bright Yellow
65
- ColorTriplet.new(59, 142, 234), # 12: Bright Blue
66
- ColorTriplet.new(214, 112, 214), # 13: Bright Magenta
67
- ColorTriplet.new(41, 184, 219), # 14: Bright Cyan
68
- ColorTriplet.new(255, 255, 255) # 15: Bright White
69
- ]
70
- )
71
-
72
- # Monokai-inspired theme
73
- MONOKAI_THEME = TerminalTheme.new(
74
- foreground: ColorTriplet.new(248, 248, 242),
75
- background: ColorTriplet.new(39, 40, 34),
76
- ansi_colors: [
77
- ColorTriplet.new(39, 40, 34), # 0: Black
78
- ColorTriplet.new(249, 38, 114), # 1: Red
79
- ColorTriplet.new(166, 226, 46), # 2: Green
80
- ColorTriplet.new(244, 191, 117), # 3: Yellow
81
- ColorTriplet.new(102, 217, 239), # 4: Blue
82
- ColorTriplet.new(174, 129, 255), # 5: Magenta
83
- ColorTriplet.new(161, 239, 228), # 6: Cyan
84
- ColorTriplet.new(248, 248, 242), # 7: White
85
- ColorTriplet.new(117, 113, 94), # 8: Bright Black
86
- ColorTriplet.new(249, 38, 114), # 9: Bright Red
87
- ColorTriplet.new(166, 226, 46), # 10: Bright Green
88
- ColorTriplet.new(244, 191, 117), # 11: Bright Yellow
89
- ColorTriplet.new(102, 217, 239), # 12: Bright Blue
90
- ColorTriplet.new(174, 129, 255), # 13: Bright Magenta
91
- ColorTriplet.new(161, 239, 228), # 14: Bright Cyan
92
- ColorTriplet.new(248, 248, 242) # 15: Bright White
93
- ]
94
- )
95
-
96
- # Dimmed Monokai for SVG/HTML export
97
- SVG_EXPORT_THEME = TerminalTheme.new(
98
- foreground: ColorTriplet.new(248, 248, 242),
99
- background: ColorTriplet.new(50, 48, 47),
100
- ansi_colors: [
101
- ColorTriplet.new(50, 48, 47), # 0: Black
102
- ColorTriplet.new(255, 98, 134), # 1: Red
103
- ColorTriplet.new(164, 238, 92), # 2: Green
104
- ColorTriplet.new(255, 216, 102), # 3: Yellow
105
- ColorTriplet.new(98, 209, 255), # 4: Blue
106
- ColorTriplet.new(189, 147, 249), # 5: Magenta
107
- ColorTriplet.new(128, 255, 234), # 6: Cyan
108
- ColorTriplet.new(248, 248, 242), # 7: White
109
- ColorTriplet.new(98, 94, 76), # 8: Bright Black
110
- ColorTriplet.new(255, 98, 134), # 9: Bright Red
111
- ColorTriplet.new(164, 238, 92), # 10: Bright Green
112
- ColorTriplet.new(255, 216, 102), # 11: Bright Yellow
113
- ColorTriplet.new(98, 209, 255), # 12: Bright Blue
114
- ColorTriplet.new(189, 147, 249), # 13: Bright Magenta
115
- ColorTriplet.new(128, 255, 234), # 14: Bright Cyan
116
- ColorTriplet.new(248, 248, 242) # 15: Bright White
117
- ]
118
- )
119
-
120
- # Windows Terminal default theme
121
- WINDOWS_TERMINAL_THEME = TerminalTheme.new(
122
- foreground: ColorTriplet.new(204, 204, 204),
123
- background: ColorTriplet.new(12, 12, 12),
124
- ansi_colors: Palettes::WINDOWS_PALETTE.dup
125
- )
126
- end
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "color_triplet"
4
+ require_relative "_palettes"
5
+
6
+ module Rich
7
+ # Terminal color theme configuration.
8
+ # Defines the actual RGB values for ANSI colors as rendered by a terminal.
9
+ class TerminalTheme
10
+ # @return [ColorTriplet] Default foreground color
11
+ attr_reader :foreground
12
+
13
+ # @return [ColorTriplet] Default background color
14
+ attr_reader :background
15
+
16
+ # @return [Array<ColorTriplet>] 16 ANSI colors (indices 0-15)
17
+ attr_reader :ansi_colors
18
+
19
+ # Create a new terminal theme
20
+ # @param foreground [ColorTriplet] Default foreground color
21
+ # @param background [ColorTriplet] Default background color
22
+ # @param ansi_colors [Array<ColorTriplet>] 16 ANSI colors
23
+ def initialize(foreground:, background:, ansi_colors:)
24
+ raise ArgumentError, "ansi_colors must have exactly 16 colors" unless ansi_colors.length == 16
25
+
26
+ @foreground = foreground
27
+ @background = background
28
+ @ansi_colors = ansi_colors.freeze
29
+ freeze
30
+ end
31
+
32
+ # Check equality with another theme
33
+ def ==(other)
34
+ return false unless other.is_a?(TerminalTheme)
35
+
36
+ @foreground == other.foreground &&
37
+ @background == other.background &&
38
+ @ansi_colors == other.ansi_colors
39
+ end
40
+
41
+ alias eql? ==
42
+
43
+ def hash
44
+ [@foreground, @background, @ansi_colors].hash
45
+ end
46
+ end
47
+
48
+ # Default terminal theme (based on typical dark terminal)
49
+ DEFAULT_TERMINAL_THEME = TerminalTheme.new(
50
+ foreground: ColorTriplet.new(230, 230, 230),
51
+ background: ColorTriplet.new(12, 12, 12),
52
+ ansi_colors: [
53
+ ColorTriplet.new(12, 12, 12), # 0: Black
54
+ ColorTriplet.new(205, 49, 49), # 1: Red
55
+ ColorTriplet.new(13, 188, 121), # 2: Green
56
+ ColorTriplet.new(229, 229, 16), # 3: Yellow
57
+ ColorTriplet.new(36, 114, 200), # 4: Blue
58
+ ColorTriplet.new(188, 63, 188), # 5: Magenta
59
+ ColorTriplet.new(17, 168, 205), # 6: Cyan
60
+ ColorTriplet.new(229, 229, 229), # 7: White
61
+ ColorTriplet.new(102, 102, 102), # 8: Bright Black
62
+ ColorTriplet.new(241, 76, 76), # 9: Bright Red
63
+ ColorTriplet.new(35, 209, 139), # 10: Bright Green
64
+ ColorTriplet.new(245, 245, 67), # 11: Bright Yellow
65
+ ColorTriplet.new(59, 142, 234), # 12: Bright Blue
66
+ ColorTriplet.new(214, 112, 214), # 13: Bright Magenta
67
+ ColorTriplet.new(41, 184, 219), # 14: Bright Cyan
68
+ ColorTriplet.new(255, 255, 255) # 15: Bright White
69
+ ]
70
+ )
71
+
72
+ # Monokai-inspired theme
73
+ MONOKAI_THEME = TerminalTheme.new(
74
+ foreground: ColorTriplet.new(248, 248, 242),
75
+ background: ColorTriplet.new(39, 40, 34),
76
+ ansi_colors: [
77
+ ColorTriplet.new(39, 40, 34), # 0: Black
78
+ ColorTriplet.new(249, 38, 114), # 1: Red
79
+ ColorTriplet.new(166, 226, 46), # 2: Green
80
+ ColorTriplet.new(244, 191, 117), # 3: Yellow
81
+ ColorTriplet.new(102, 217, 239), # 4: Blue
82
+ ColorTriplet.new(174, 129, 255), # 5: Magenta
83
+ ColorTriplet.new(161, 239, 228), # 6: Cyan
84
+ ColorTriplet.new(248, 248, 242), # 7: White
85
+ ColorTriplet.new(117, 113, 94), # 8: Bright Black
86
+ ColorTriplet.new(249, 38, 114), # 9: Bright Red
87
+ ColorTriplet.new(166, 226, 46), # 10: Bright Green
88
+ ColorTriplet.new(244, 191, 117), # 11: Bright Yellow
89
+ ColorTriplet.new(102, 217, 239), # 12: Bright Blue
90
+ ColorTriplet.new(174, 129, 255), # 13: Bright Magenta
91
+ ColorTriplet.new(161, 239, 228), # 14: Bright Cyan
92
+ ColorTriplet.new(248, 248, 242) # 15: Bright White
93
+ ]
94
+ )
95
+
96
+ # Dimmed Monokai for SVG/HTML export
97
+ SVG_EXPORT_THEME = TerminalTheme.new(
98
+ foreground: ColorTriplet.new(248, 248, 242),
99
+ background: ColorTriplet.new(50, 48, 47),
100
+ ansi_colors: [
101
+ ColorTriplet.new(50, 48, 47), # 0: Black
102
+ ColorTriplet.new(255, 98, 134), # 1: Red
103
+ ColorTriplet.new(164, 238, 92), # 2: Green
104
+ ColorTriplet.new(255, 216, 102), # 3: Yellow
105
+ ColorTriplet.new(98, 209, 255), # 4: Blue
106
+ ColorTriplet.new(189, 147, 249), # 5: Magenta
107
+ ColorTriplet.new(128, 255, 234), # 6: Cyan
108
+ ColorTriplet.new(248, 248, 242), # 7: White
109
+ ColorTriplet.new(98, 94, 76), # 8: Bright Black
110
+ ColorTriplet.new(255, 98, 134), # 9: Bright Red
111
+ ColorTriplet.new(164, 238, 92), # 10: Bright Green
112
+ ColorTriplet.new(255, 216, 102), # 11: Bright Yellow
113
+ ColorTriplet.new(98, 209, 255), # 12: Bright Blue
114
+ ColorTriplet.new(189, 147, 249), # 13: Bright Magenta
115
+ ColorTriplet.new(128, 255, 234), # 14: Bright Cyan
116
+ ColorTriplet.new(248, 248, 242) # 15: Bright White
117
+ ]
118
+ )
119
+
120
+ # Windows Terminal default theme
121
+ WINDOWS_TERMINAL_THEME = TerminalTheme.new(
122
+ foreground: ColorTriplet.new(204, 204, 204),
123
+ background: ColorTriplet.new(12, 12, 12),
124
+ ansi_colors: Palettes::WINDOWS_PALETTE.dup
125
+ )
126
+ end