sai 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -18,7 +18,7 @@
18
18
  # decorations (apply, call, decorate, encode). These methods are directly delegated to a new {Decorator} instance
19
19
  #
20
20
  # @author {https://aaronmallen.me Aaron Allen}
21
- # @since unreleased
21
+ # @since 0.1.0
22
22
  #
23
23
  # @api public
24
24
  #
@@ -39,135 +39,156 @@
39
39
  #
40
40
  # Sai.support.true_color? # => true
41
41
  module Sai
42
- def black: () -> self
42
+ # The Sai {ModeSelector mode selector}
43
+ #
44
+ # @author {https://aaronmallen.me Aaron Allen}
45
+ # @since 0.2.0
46
+ #
47
+ # @api public
48
+ #
49
+ # @example
50
+ # Sai.mode.auto #=> 4
51
+ #
52
+ # @return [ModeSelector] the mode selector
53
+ # @rbs () -> singleton(ModeSelector)
54
+ def self.mode: () -> singleton(ModeSelector)
43
55
 
44
- def blink: () -> self
56
+ def black: () -> Decorator
45
57
 
46
- def blue: () -> self
58
+ def blink: () -> Decorator
47
59
 
48
- def bold: () -> self
60
+ def blue: () -> Decorator
49
61
 
50
- def bright_black: () -> self
62
+ def bold: () -> Decorator
51
63
 
52
- def bright_blue: () -> self
64
+ def bright_black: () -> Decorator
53
65
 
54
- def bright_cyan: () -> self
66
+ def bright_blue: () -> Decorator
55
67
 
56
- def bright_green: () -> self
68
+ def bright_cyan: () -> Decorator
57
69
 
58
- def bright_magenta: () -> self
70
+ def bright_green: () -> Decorator
59
71
 
60
- def bright_red: () -> self
72
+ def bright_magenta: () -> Decorator
61
73
 
62
- def bright_white: () -> self
74
+ def bright_red: () -> Decorator
63
75
 
64
- def bright_yellow: () -> self
76
+ def bright_white: () -> Decorator
65
77
 
66
- def conceal: () -> self
78
+ def bright_yellow: () -> Decorator
67
79
 
68
- def cyan: () -> self
80
+ def conceal: () -> Decorator
69
81
 
70
- def dim: () -> self
82
+ def cyan: () -> Decorator
71
83
 
72
- def green: () -> self
84
+ def dim: () -> Decorator
73
85
 
74
- def italic: () -> self
86
+ def green: () -> Decorator
75
87
 
76
- def magenta: () -> self
88
+ def italic: () -> Decorator
77
89
 
78
- def no_blink: () -> self
90
+ def magenta: () -> Decorator
79
91
 
80
- def no_conceal: () -> self
92
+ def no_blink: () -> Decorator
81
93
 
82
- def no_italic: () -> self
94
+ def no_conceal: () -> Decorator
83
95
 
84
- def no_reverse: () -> self
96
+ def no_italic: () -> Decorator
85
97
 
86
- def no_strike: () -> self
98
+ def no_reverse: () -> Decorator
87
99
 
88
- def no_underline: () -> self
100
+ def no_strike: () -> Decorator
89
101
 
90
- def normal_intensity: () -> self
102
+ def no_underline: () -> Decorator
91
103
 
92
- def on_black: () -> self
104
+ def normal_intensity: () -> Decorator
93
105
 
94
- def on_blue: () -> self
106
+ def on_black: () -> Decorator
95
107
 
96
- def on_bright_black: () -> self
108
+ def on_blue: () -> Decorator
97
109
 
98
- def on_bright_blue: () -> self
110
+ def on_bright_black: () -> Decorator
99
111
 
100
- def on_bright_cyan: () -> self
112
+ def on_bright_blue: () -> Decorator
101
113
 
102
- def on_bright_green: () -> self
114
+ def on_bright_cyan: () -> Decorator
103
115
 
104
- def on_bright_magenta: () -> self
116
+ def on_bright_green: () -> Decorator
105
117
 
106
- def on_bright_red: () -> self
118
+ def on_bright_magenta: () -> Decorator
107
119
 
108
- def on_bright_white: () -> self
120
+ def on_bright_red: () -> Decorator
109
121
 
110
- def on_bright_yellow: () -> self
122
+ def on_bright_white: () -> Decorator
111
123
 
112
- def on_cyan: () -> self
124
+ def on_bright_yellow: () -> Decorator
113
125
 
114
- def on_green: () -> self
126
+ def on_cyan: () -> Decorator
115
127
 
116
- def on_magenta: () -> self
128
+ def on_green: () -> Decorator
117
129
 
118
- def on_red: () -> self
130
+ def on_magenta: () -> Decorator
119
131
 
120
- def on_white: () -> self
132
+ def on_red: () -> Decorator
121
133
 
122
- def on_yellow: () -> self
134
+ def on_white: () -> Decorator
123
135
 
124
- def rapid_blink: () -> self
136
+ def on_yellow: () -> Decorator
125
137
 
126
- def red: () -> self
138
+ def rapid_blink: () -> Decorator
127
139
 
128
- def reverse: () -> self
140
+ def red: () -> Decorator
129
141
 
130
- def strike: () -> self
142
+ def reverse: () -> Decorator
131
143
 
132
- def underline: () -> self
144
+ def strike: () -> Decorator
133
145
 
134
- def white: () -> self
146
+ def underline: () -> Decorator
135
147
 
136
- def yellow: () -> self
148
+ def white: () -> Decorator
149
+
150
+ def yellow: () -> Decorator
137
151
 
138
152
  # The supported color modes for the terminal
139
153
  #
140
154
  # @author {https://aaronmallen.me Aaron Allen}
141
- # @since unreleased
155
+ # @since 0.1.0
142
156
  #
143
157
  # @api public
144
158
  #
145
159
  # @example Check the color support of the terminal
146
160
  # Sai.support.ansi? # => true
147
161
  # Sai.support.basic? # => true
148
- # Sai.support.bit8? # => true
162
+ # Sai.support.advanced? # => true
149
163
  # Sai.support.no_color? # => false
150
164
  # Sai.support.true_color? # => true
151
165
  #
152
166
  # @return [Support] the color support
153
- # @rbs () -> Support
154
- def self.support: () -> Support
167
+ # @rbs () -> singleton(Support)
168
+ def self.support: () -> singleton(Support)
155
169
 
156
- # Detect the color capabilities of the terminal
170
+ # A helper method that provides Sai color modes
157
171
  #
158
172
  # @author {https://aaronmallen.me Aaron Allen}
159
- # @since unreleased
173
+ # @since 0.2.0
160
174
  #
161
- # @api private
175
+ # @api public
162
176
  #
163
- # @return [Integer] the color mode
164
- # @rbs () -> Integer
165
- private def self.color_mode: () -> Integer
177
+ # @example
178
+ # class MyClass
179
+ # include Sai
180
+ # end
181
+ #
182
+ # MyClass.new.color_mode.ansi #=> 2
183
+ #
184
+ # @return [ModeSelector] the mode selector
185
+ # @rbs () -> singleton(ModeSelector)
186
+ def color_mode: () -> singleton(ModeSelector)
166
187
 
167
188
  # A helper method to initialize an instance of {Decorator}
168
189
  #
169
190
  # @author {https://aaronmallen.me Aaron Allen}
170
- # @since unreleased
191
+ # @since 0.1.0
171
192
  #
172
193
  # @api public
173
194
  #
@@ -179,14 +200,19 @@ module Sai
179
200
  # MyClass.new.decorator.blue.on_red.bold.decorate('Hello, world!')
180
201
  # #=> "\e[38;5;21m\e[48;5;160m\e[1mHello, world!\e[0m"
181
202
  #
203
+ # MyClass.new.decorator(mode: Sai.mode.no_color)
204
+ # #=> "Hello, world!"
205
+ #
206
+ # @param mode [Integer] the color mode to use
207
+ #
182
208
  # @return [Decorator] the Decorator instance
183
- # @rbs () -> Decorator
184
- def decorator: () -> Decorator
209
+ # @rbs (?mode: Integer) -> Decorator
210
+ def decorator: (?mode: Integer) -> Decorator
185
211
 
186
212
  # The supported color modes for the terminal
187
213
  #
188
214
  # @author {https://aaronmallen.me Aaron Allen}
189
- # @since unreleased
215
+ # @since 0.1.0
190
216
  #
191
217
  # @api public
192
218
  #
@@ -197,11 +223,11 @@ module Sai
197
223
  #
198
224
  # MyClass.new.terminal_color_support.ansi? # => true
199
225
  # MyClass.new.terminal_color_support.basic? # => true
200
- # MyClass.new.terminal_color_support.bit8? # => true
226
+ # MyClass.new.terminal_color_support.advanced? # => true
201
227
  # MyClass.new.terminal_color_support.no_color? # => false
202
228
  # MyClass.new.terminal_color_support.true_color? # => true
203
229
  #
204
230
  # @return [Support] the color support
205
- # @rbs () -> Support
206
- def terminal_color_support: () -> Support
231
+ # @rbs () -> singleton(Support)
232
+ def terminal_color_support: () -> singleton(Support)
207
233
  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.2.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.
@@ -27,6 +27,7 @@ files:
27
27
  - lib/sai/conversion/color_sequence.rb
28
28
  - lib/sai/conversion/rgb.rb
29
29
  - lib/sai/decorator.rb
30
+ - lib/sai/mode_selector.rb
30
31
  - lib/sai/support.rb
31
32
  - lib/sai/terminal/capabilities.rb
32
33
  - lib/sai/terminal/color_mode.rb
@@ -35,6 +36,7 @@ files:
35
36
  - sig/sai/conversion/color_sequence.rbs
36
37
  - sig/sai/conversion/rgb.rbs
37
38
  - sig/sai/decorator.rbs
39
+ - sig/sai/mode_selector.rbs
38
40
  - sig/sai/support.rbs
39
41
  - sig/sai/terminal/capabilities.rbs
40
42
  - sig/sai/terminal/color_mode.rbs
@@ -43,10 +45,10 @@ licenses:
43
45
  - MIT
44
46
  metadata:
45
47
  bug_tracker_uri: https://github.com/aaronmallen/sai/issues
46
- changelog_uri: https://github.com/aaronmallen/sai/releases/tag/0.1.0
48
+ changelog_uri: https://github.com/aaronmallen/sai/releases/tag/0.2.0
47
49
  homepage_uri: https://github.com/aaronmallen/sai
48
50
  rubygems_mfa_required: 'true'
49
- source_code_uri: https://github.com/aaronmallen/sai/tree/0.1.0
51
+ source_code_uri: https://github.com/aaronmallen/sai/tree/0.2.0
50
52
  rdoc_options: []
51
53
  require_paths:
52
54
  - lib