sai 0.1.0 → 0.3.0

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.
data/sig/sai/support.rbs CHANGED
@@ -4,27 +4,38 @@ module Sai
4
4
  # Determine the color capabilities of the terminal
5
5
  #
6
6
  # @author {https://aaronmallen.me Aaron Allen}
7
- # @since unreleased
7
+ # @since 0.1.0
8
8
  #
9
9
  # @api public
10
- class Support
11
- # Initialize a new instance of Support
10
+ module Support
11
+ # Check if the terminal supports 256 colors (8-bit)
12
12
  #
13
13
  # @author {https://aaronmallen.me Aaron Allen}
14
- # @since unreleased
14
+ # @since 0.1.0
15
15
  #
16
- # @api private
16
+ # @api public
17
17
  #
18
- # @param color_mode [Integer] the color mode
18
+ # @example Check if the terminal supports 256 colors
19
+ # Sai.advanced? # => true
19
20
  #
20
- # @return [Support] the new instance of support
21
- # @rbs (Integer color_mode) -> void
22
- def initialize: (Integer color_mode) -> void
21
+ # @return [Boolean] `true` if the terminal supports 256 colors (8-bit), otherwise `false`
22
+ # @rbs () -> bool
23
+ def self.advanced?: () -> bool
24
+
25
+ alias self.color256? self.advanced?
26
+
27
+ alias self.colour256? self.advanced?
28
+
29
+ alias self.eight_bit? self.advanced?
30
+
31
+ alias self.two_hundred_fifty_six_color? self.advanced?
32
+
33
+ alias self.two_hundred_fifty_six_colour? self.advanced?
23
34
 
24
35
  # Check if the terminal supports ANSI colors (4-bit)
25
36
  #
26
37
  # @author {https://aaronmallen.me Aaron Allen}
27
- # @since unreleased
38
+ # @since 0.1.0
28
39
  #
29
40
  # @api public
30
41
  #
@@ -33,16 +44,22 @@ module Sai
33
44
  #
34
45
  # @return [Boolean] `true` if the terminal supports ANSI colors (4-bit), otherwise `false`
35
46
  # @rbs () -> bool
36
- def ansi?: () -> bool
47
+ def self.ansi?: () -> bool
48
+
49
+ alias self.color16? self.ansi?
37
50
 
38
- alias bit4? ansi?
51
+ alias self.colour16? self.ansi?
39
52
 
40
- alias four_bit? ansi?
53
+ alias self.four_bit? self.ansi?
54
+
55
+ alias self.sixteen_color? self.ansi?
56
+
57
+ alias self.sixteen_colour? self.ansi?
41
58
 
42
59
  # Check if the terminal supports basic colors (3-bit)
43
60
  #
44
61
  # @author {https://aaronmallen.me Aaron Allen}
45
- # @since unreleased
62
+ # @since 0.1.0
46
63
  #
47
64
  # @api public
48
65
  #
@@ -51,32 +68,22 @@ module Sai
51
68
  #
52
69
  # @return [Boolean] `true` if the terminal supports basic colors (3-bit), otherwise `false`
53
70
  # @rbs () -> bool
54
- def basic?: () -> bool
71
+ def self.basic?: () -> bool
55
72
 
56
- alias bit3? basic?
73
+ alias self.color8? self.basic?
57
74
 
58
- alias three_bit? basic?
75
+ alias self.colour8? self.basic?
59
76
 
60
- # Check if the terminal supports 256 colors (8-bit)
61
- #
62
- # @author {https://aaronmallen.me Aaron Allen}
63
- # @since unreleased
64
- #
65
- # @api public
66
- #
67
- # @example Check if the terminal supports 256 colors
68
- # Sai.bit_8? # => true
69
- #
70
- # @return [Boolean] `true` if the terminal supports 256 colors (8-bit), otherwise `false`
71
- # @rbs () -> bool
72
- def bit8?: () -> bool
77
+ alias self.eight_color? self.basic?
78
+
79
+ alias self.eight_colour? self.basic?
73
80
 
74
- alias eight_bit? bit8?
81
+ alias self.three_bit? self.basic?
75
82
 
76
83
  # Check if the terminal supports color output
77
84
  #
78
85
  # @author {https://aaronmallen.me Aaron Allen}
79
- # @since unreleased
86
+ # @since 0.1.0
80
87
  #
81
88
  # @api public
82
89
  #
@@ -85,12 +92,12 @@ module Sai
85
92
  #
86
93
  # @return [Boolean] `true` if the terminal supports color output, otherwise `false`
87
94
  # @rbs () -> bool
88
- def color?: () -> bool
95
+ def self.color?: () -> bool
89
96
 
90
97
  # Check if the terminal supports true color (24-bit)
91
98
  #
92
99
  # @author {https://aaronmallen.me Aaron Allen}
93
- # @since unreleased
100
+ # @since 0.1.0
94
101
  #
95
102
  # @api public
96
103
  #
@@ -99,10 +106,16 @@ module Sai
99
106
  #
100
107
  # @return [Boolean] `true` if the terminal supports true color (24-bit), otherwise `false`
101
108
  # @rbs () -> bool
102
- def true_color?: () -> bool
109
+ def self.true_color?: () -> bool
110
+
111
+ alias self.color16m? self.true_color?
112
+
113
+ alias self.colour16m? self.true_color?
114
+
115
+ alias self.sixteen_million_color? self.true_color?
103
116
 
104
- alias bit24? true_color?
117
+ alias self.sixteen_million_colour? self.true_color?
105
118
 
106
- alias twenty_four_bit? true_color?
119
+ alias self.twenty_for_bit? self.true_color?
107
120
  end
108
121
  end
@@ -5,14 +5,14 @@ module Sai
5
5
  # Detect the color capabilities of the terminal
6
6
  #
7
7
  # @author {https://aaronmallen.me Aaron Allen}
8
- # @since unreleased
8
+ # @since 0.1.0
9
9
  #
10
10
  # @api private
11
11
  module Capabilities
12
12
  # Detect the color capabilities of the current terminal
13
13
  #
14
14
  # @author {https://aaronmallen.me Aaron Allen}
15
- # @since unreleased
15
+ # @since 0.1.0
16
16
  #
17
17
  # @api private
18
18
  #
@@ -20,43 +20,43 @@ module Sai
20
20
  # @rbs () -> Integer
21
21
  def self.detect_color_support: () -> Integer
22
22
 
23
- # Check for ANSI color support
23
+ # Check for 256 color (8-bit) support
24
24
  #
25
25
  # @author {https://aaronmallen.me Aaron Allen}
26
- # @since unreleased
26
+ # @since 0.1.0
27
27
  #
28
28
  # @api private
29
29
  #
30
- # @return [Boolean] `true` if the terminal supports basic ANSI colors, otherwise `false`
30
+ # @return [Boolean] `true` if the terminal supports 256 colors, otherwise `false`
31
31
  # @rbs () -> bool
32
- private def self.ansi?: () -> bool
32
+ private def self.advanced?: () -> bool
33
33
 
34
- # Check for basic color support
34
+ # Check for ANSI color support
35
35
  #
36
36
  # @author {https://aaronmallen.me Aaron Allen}
37
- # @since unreleased
37
+ # @since 0.1.0
38
38
  #
39
39
  # @api private
40
40
  #
41
- # @return [Boolean] `true` if the terminal supports basic colors, otherwise `false`
41
+ # @return [Boolean] `true` if the terminal supports basic ANSI colors, otherwise `false`
42
42
  # @rbs () -> bool
43
- private def self.basic?: () -> bool
43
+ private def self.ansi?: () -> bool
44
44
 
45
- # Check for 256 color (8-bit) support
45
+ # Check for basic color support
46
46
  #
47
47
  # @author {https://aaronmallen.me Aaron Allen}
48
- # @since unreleased
48
+ # @since 0.1.0
49
49
  #
50
50
  # @api private
51
51
  #
52
- # @return [Boolean] `true` if the terminal supports 256 colors, otherwise `false`
52
+ # @return [Boolean] `true` if the terminal supports basic colors, otherwise `false`
53
53
  # @rbs () -> bool
54
- private def self.bit8?: () -> bool
54
+ private def self.basic?: () -> bool
55
55
 
56
56
  # Check for NO_COLOR environment variable
57
57
  #
58
58
  # @author {https://aaronmallen.me Aaron Allen}
59
- # @since unreleased
59
+ # @since 0.1.0
60
60
  #
61
61
  # @api private
62
62
  #
@@ -69,7 +69,7 @@ module Sai
69
69
  # Check for true color (24-bit) support
70
70
  #
71
71
  # @author {https://aaronmallen.me Aaron Allen}
72
- # @since unreleased
72
+ # @since 0.1.0
73
73
  #
74
74
  # @api private
75
75
  #
@@ -5,14 +5,14 @@ module Sai
5
5
  # Represents different color support levels for terminal interfaces
6
6
  #
7
7
  # @author {https://aaronmallen.me Aaron Allen}
8
- # @since unreleased
8
+ # @since 0.1.0
9
9
  #
10
10
  # @api private
11
11
  module ColorMode
12
12
  # The terminal does not support color output
13
13
  #
14
14
  # @author {https://aaronmallen.me Aaron Allen}
15
- # @since unreleased
15
+ # @since 0.1.0
16
16
  #
17
17
  # @api private
18
18
  #
@@ -22,7 +22,7 @@ module Sai
22
22
  # The terminal supports 8 colors (3-bit)
23
23
  #
24
24
  # @author {https://aaronmallen.me Aaron Allen}
25
- # @since unreleased
25
+ # @since 0.1.0
26
26
  #
27
27
  # @api private
28
28
  #
@@ -32,7 +32,7 @@ module Sai
32
32
  # The terminal supports 16 colors (4-bit)
33
33
  #
34
34
  # @author {https://aaronmallen.me Aaron Allen}
35
- # @since unreleased
35
+ # @since 0.1.0
36
36
  #
37
37
  # @api private
38
38
  #
@@ -42,17 +42,17 @@ module Sai
42
42
  # The terminal supports 256 colors (8-bit)
43
43
  #
44
44
  # @author {https://aaronmallen.me Aaron Allen}
45
- # @since unreleased
45
+ # @since 0.1.0
46
46
  #
47
47
  # @api private
48
48
  #
49
49
  # @return [Integer] the color mode
50
- BIT8: Integer
50
+ ADVANCED: Integer
51
51
 
52
52
  # The terminal supports 16 million colors (24-bit)
53
53
  #
54
54
  # @author {https://aaronmallen.me Aaron Allen}
55
- # @since unreleased
55
+ # @since 0.1.0
56
56
  #
57
57
  # @api private
58
58
  #
data/sig/sai.rbs CHANGED
@@ -11,6 +11,7 @@
11
11
  # adaptive color to your terminal interfaces
12
12
  #
13
13
  # When included in a class or module, Sai provides the following instance methods:
14
+ # * {#color_mode} - Returns an interface to select Sai color modes
14
15
  # * {#decorator} - Returns a new instance of {Decorator} for method chaining
15
16
  # * {#terminal_color_support} - Returns the color support capabilities of the current terminal
16
17
  #
@@ -18,7 +19,7 @@
18
19
  # decorations (apply, call, decorate, encode). These methods are directly delegated to a new {Decorator} instance
19
20
  #
20
21
  # @author {https://aaronmallen.me Aaron Allen}
21
- # @since unreleased
22
+ # @since 0.1.0
22
23
  #
23
24
  # @api public
24
25
  #
@@ -39,135 +40,172 @@
39
40
  #
40
41
  # Sai.support.true_color? # => true
41
42
  module Sai
42
- def black: () -> self
43
+ # The Sai {ModeSelector mode selector}
44
+ #
45
+ # @author {https://aaronmallen.me Aaron Allen}
46
+ # @since 0.2.0
47
+ #
48
+ # @api public
49
+ #
50
+ # @example
51
+ # Sai.mode.auto #=> 4
52
+ #
53
+ # @return [ModeSelector] the mode selector
54
+ # @rbs () -> singleton(ModeSelector)
55
+ def self.mode: () -> singleton(ModeSelector)
43
56
 
44
- def blink: () -> self
57
+ def black: () -> Decorator
45
58
 
46
- def blue: () -> self
59
+ def blink: () -> Decorator
47
60
 
48
- def bold: () -> self
61
+ def blue: () -> Decorator
49
62
 
50
- def bright_black: () -> self
63
+ def bold: () -> Decorator
51
64
 
52
- def bright_blue: () -> self
65
+ def bright_black: () -> Decorator
53
66
 
54
- def bright_cyan: () -> self
67
+ def bright_blue: () -> Decorator
55
68
 
56
- def bright_green: () -> self
69
+ def bright_cyan: () -> Decorator
57
70
 
58
- def bright_magenta: () -> self
71
+ def bright_green: () -> Decorator
59
72
 
60
- def bright_red: () -> self
73
+ def bright_magenta: () -> Decorator
61
74
 
62
- def bright_white: () -> self
75
+ def bright_red: () -> Decorator
63
76
 
64
- def bright_yellow: () -> self
77
+ def bright_white: () -> Decorator
65
78
 
66
- def conceal: () -> self
79
+ def bright_yellow: () -> Decorator
67
80
 
68
- def cyan: () -> self
81
+ def conceal: () -> Decorator
69
82
 
70
- def dim: () -> self
83
+ def cyan: () -> Decorator
71
84
 
72
- def green: () -> self
85
+ def dim: () -> Decorator
73
86
 
74
- def italic: () -> self
87
+ def green: () -> Decorator
75
88
 
76
- def magenta: () -> self
89
+ def italic: () -> Decorator
77
90
 
78
- def no_blink: () -> self
91
+ def magenta: () -> Decorator
79
92
 
80
- def no_conceal: () -> self
93
+ def no_blink: () -> Decorator
81
94
 
82
- def no_italic: () -> self
95
+ def no_conceal: () -> Decorator
83
96
 
84
- def no_reverse: () -> self
97
+ def no_italic: () -> Decorator
85
98
 
86
- def no_strike: () -> self
99
+ def no_reverse: () -> Decorator
87
100
 
88
- def no_underline: () -> self
101
+ def no_strike: () -> Decorator
89
102
 
90
- def normal_intensity: () -> self
103
+ def no_underline: () -> Decorator
91
104
 
92
- def on_black: () -> self
105
+ def normal_intensity: () -> Decorator
93
106
 
94
- def on_blue: () -> self
107
+ def on_black: () -> Decorator
95
108
 
96
- def on_bright_black: () -> self
109
+ def on_blue: () -> Decorator
97
110
 
98
- def on_bright_blue: () -> self
111
+ def on_bright_black: () -> Decorator
99
112
 
100
- def on_bright_cyan: () -> self
113
+ def on_bright_blue: () -> Decorator
101
114
 
102
- def on_bright_green: () -> self
115
+ def on_bright_cyan: () -> Decorator
103
116
 
104
- def on_bright_magenta: () -> self
117
+ def on_bright_green: () -> Decorator
105
118
 
106
- def on_bright_red: () -> self
119
+ def on_bright_magenta: () -> Decorator
107
120
 
108
- def on_bright_white: () -> self
121
+ def on_bright_red: () -> Decorator
109
122
 
110
- def on_bright_yellow: () -> self
123
+ def on_bright_white: () -> Decorator
111
124
 
112
- def on_cyan: () -> self
125
+ def on_bright_yellow: () -> Decorator
113
126
 
114
- def on_green: () -> self
127
+ def on_cyan: () -> Decorator
115
128
 
116
- def on_magenta: () -> self
129
+ def on_green: () -> Decorator
117
130
 
118
- def on_red: () -> self
131
+ def on_magenta: () -> Decorator
119
132
 
120
- def on_white: () -> self
133
+ def on_red: () -> Decorator
121
134
 
122
- def on_yellow: () -> self
135
+ def on_white: () -> Decorator
123
136
 
124
- def rapid_blink: () -> self
137
+ def on_yellow: () -> Decorator
125
138
 
126
- def red: () -> self
139
+ def rapid_blink: () -> Decorator
127
140
 
128
- def reverse: () -> self
141
+ def red: () -> Decorator
129
142
 
130
- def strike: () -> self
143
+ def reverse: () -> Decorator
131
144
 
132
- def underline: () -> self
145
+ def strike: () -> Decorator
133
146
 
134
- def white: () -> self
147
+ def underline: () -> Decorator
135
148
 
136
- def yellow: () -> self
149
+ def white: () -> Decorator
150
+
151
+ def yellow: () -> Decorator
152
+
153
+ # Sequence a string with ANSI escape codes
154
+ #
155
+ # @author {https://aaronmallen.me Aaron Allen}
156
+ # @since 0.3.0
157
+ #
158
+ # @api public
159
+ #
160
+ # @example Sequence a string with ANSI escape codes
161
+ # Sai.sequence("\e[38;2;205;0;0mHello, World!\e[0m") #=> #<Sai::ANSI::SequencedString:0x123>
162
+ #
163
+ # @param text [String] the text to sequence
164
+ #
165
+ # @return [ANSI::SequencedString] the sequenced string
166
+ # @rbs (String text) -> ANSI::SequencedString
167
+ def self.sequence: (String text) -> ANSI::SequencedString
137
168
 
138
169
  # The supported color modes for the terminal
139
170
  #
140
171
  # @author {https://aaronmallen.me Aaron Allen}
141
- # @since unreleased
172
+ # @since 0.1.0
142
173
  #
143
174
  # @api public
144
175
  #
145
176
  # @example Check the color support of the terminal
146
177
  # Sai.support.ansi? # => true
147
178
  # Sai.support.basic? # => true
148
- # Sai.support.bit8? # => true
179
+ # Sai.support.advanced? # => true
149
180
  # Sai.support.no_color? # => false
150
181
  # Sai.support.true_color? # => true
151
182
  #
152
183
  # @return [Support] the color support
153
- # @rbs () -> Support
154
- def self.support: () -> Support
184
+ # @rbs () -> singleton(Support)
185
+ def self.support: () -> singleton(Support)
155
186
 
156
- # Detect the color capabilities of the terminal
187
+ # A helper method that provides Sai color modes
157
188
  #
158
189
  # @author {https://aaronmallen.me Aaron Allen}
159
- # @since unreleased
190
+ # @since 0.2.0
160
191
  #
161
- # @api private
192
+ # @api public
162
193
  #
163
- # @return [Integer] the color mode
164
- # @rbs () -> Integer
165
- private def self.color_mode: () -> Integer
194
+ # @example
195
+ # class MyClass
196
+ # include Sai
197
+ # end
198
+ #
199
+ # MyClass.new.color_mode.ansi #=> 2
200
+ #
201
+ # @return [ModeSelector] the mode selector
202
+ # @rbs () -> singleton(ModeSelector)
203
+ def color_mode: () -> singleton(ModeSelector)
166
204
 
167
205
  # A helper method to initialize an instance of {Decorator}
168
206
  #
169
207
  # @author {https://aaronmallen.me Aaron Allen}
170
- # @since unreleased
208
+ # @since 0.1.0
171
209
  #
172
210
  # @api public
173
211
  #
@@ -179,14 +217,19 @@ module Sai
179
217
  # MyClass.new.decorator.blue.on_red.bold.decorate('Hello, world!')
180
218
  # #=> "\e[38;5;21m\e[48;5;160m\e[1mHello, world!\e[0m"
181
219
  #
220
+ # MyClass.new.decorator(mode: Sai.mode.no_color)
221
+ # #=> "Hello, world!"
222
+ #
223
+ # @param mode [Integer] the color mode to use
224
+ #
182
225
  # @return [Decorator] the Decorator instance
183
- # @rbs () -> Decorator
184
- def decorator: () -> Decorator
226
+ # @rbs (?mode: Integer) -> Decorator
227
+ def decorator: (?mode: Integer) -> Decorator
185
228
 
186
229
  # The supported color modes for the terminal
187
230
  #
188
231
  # @author {https://aaronmallen.me Aaron Allen}
189
- # @since unreleased
232
+ # @since 0.1.0
190
233
  #
191
234
  # @api public
192
235
  #
@@ -197,11 +240,11 @@ module Sai
197
240
  #
198
241
  # MyClass.new.terminal_color_support.ansi? # => true
199
242
  # MyClass.new.terminal_color_support.basic? # => true
200
- # MyClass.new.terminal_color_support.bit8? # => true
243
+ # MyClass.new.terminal_color_support.advanced? # => true
201
244
  # MyClass.new.terminal_color_support.no_color? # => false
202
245
  # MyClass.new.terminal_color_support.true_color? # => true
203
246
  #
204
247
  # @return [Support] the color support
205
- # @rbs () -> Support
206
- def terminal_color_support: () -> Support
248
+ # @rbs () -> singleton(Support)
249
+ def terminal_color_support: () -> singleton(Support)
207
250
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sai
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aaron Allen
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-01-19 00:00:00.000000000 Z
10
+ date: 2025-01-20 00:00:00.000000000 Z
11
11
  dependencies: []
12
12
  description: |-
13
13
  Sai (彩) - meaning 'coloring' or 'paint' in Japanese - is a powerful and intuitive system for managing color output in command-line applications. Drawing inspiration from traditional Japanese artistic techniques, Sai brings vibrancy and harmony to terminal interfaces through its sophisticated color management.
@@ -22,19 +22,27 @@ files:
22
22
  - CHANGELOG.md
23
23
  - LICENSE
24
24
  - README.md
25
+ - docs/USAGE.md
25
26
  - lib/sai.rb
26
27
  - lib/sai/ansi.rb
28
+ - lib/sai/ansi/sequence_processor.rb
29
+ - lib/sai/ansi/sequenced_string.rb
27
30
  - lib/sai/conversion/color_sequence.rb
28
31
  - lib/sai/conversion/rgb.rb
29
32
  - lib/sai/decorator.rb
33
+ - lib/sai/mode_selector.rb
30
34
  - lib/sai/support.rb
31
35
  - lib/sai/terminal/capabilities.rb
32
36
  - lib/sai/terminal/color_mode.rb
37
+ - sig/manifest.yaml
33
38
  - sig/sai.rbs
34
39
  - sig/sai/ansi.rbs
40
+ - sig/sai/ansi/sequence_processor.rbs
41
+ - sig/sai/ansi/sequenced_string.rbs
35
42
  - sig/sai/conversion/color_sequence.rbs
36
43
  - sig/sai/conversion/rgb.rbs
37
44
  - sig/sai/decorator.rbs
45
+ - sig/sai/mode_selector.rbs
38
46
  - sig/sai/support.rbs
39
47
  - sig/sai/terminal/capabilities.rbs
40
48
  - sig/sai/terminal/color_mode.rbs
@@ -43,10 +51,10 @@ licenses:
43
51
  - MIT
44
52
  metadata:
45
53
  bug_tracker_uri: https://github.com/aaronmallen/sai/issues
46
- changelog_uri: https://github.com/aaronmallen/sai/releases/tag/0.1.0
54
+ changelog_uri: https://github.com/aaronmallen/sai/releases/tag/0.3.0
47
55
  homepage_uri: https://github.com/aaronmallen/sai
48
56
  rubygems_mfa_required: 'true'
49
- source_code_uri: https://github.com/aaronmallen/sai/tree/0.1.0
57
+ source_code_uri: https://github.com/aaronmallen/sai/tree/0.3.0
50
58
  rdoc_options: []
51
59
  require_paths:
52
60
  - lib