tiny_color 1.0.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/tiny_color.rb +48 -30
  3. metadata +4 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ab6f7f97772572db9f9150f29e255d3115b8c63f07235779950d608981978065
4
- data.tar.gz: 0bc3fa123e8062f1a08561ec028fb3372c82794a22171b1d1a2bbbc3b81d6250
3
+ metadata.gz: d3fab6755d6cbd85d80d5b68ed03896947aef7c7c546b7f4178fa78f6ba44aee
4
+ data.tar.gz: ccb2c63c201a14635de641808c9ab34001a743468ec655a8efc29598572c3243
5
5
  SHA512:
6
- metadata.gz: e41b28487f9a48a768375d16200e8d5a8ed65f5565b9073ff526cf2e3ca9338969b2b9cc6043a386f77ca58239432e4f5f4efdeb78089a1c8f22e7aa562347e5
7
- data.tar.gz: a28dfad2340703e9eda86b7639a8e77f05ec819b8ae3776f03acef20042cbd18d3bd3132bdb3510748b994ba18ddbcd49c2b488c7e3545a096fadec0705ba412
6
+ metadata.gz: cb4dc9ea78870716b1c21c8fafcf8c00addf14073e09833b94b7b7d5987912d26d8cba6c58eb93b59a80e4373fe4cda67b242c0f1ca7e43dee65023e65e26015
7
+ data.tar.gz: 9c36772323fe25ce70410486c6a93da391ba74c34fea346695de366258d208f9284bc847d0376b7dcaaf7cc02d518f631f119c9c772999a45caf666259ed0f8c
data/lib/tiny_color.rb CHANGED
@@ -1,55 +1,73 @@
1
- # this code extends the String class, adding ANSI color codes for modifying the
2
- # text.
1
+ # this class extends the String class to add color formatting methods using
2
+ # ANSI escape codes.
3
3
  #
4
- # usage:
5
- # puts 'Hi'.green + ' there!'
6
- #
7
- # "Hi there!" # where 'Hi' will appear in green,
8
- # # and the rest in your # default
9
- # # terminal color
4
+ # try these examples:
5
+ # require 'tiny_color'
10
6
  #
11
- # you can also add background colors:
12
- # puts 'Hi'.black.on_yellow + ' there!'
7
+ # "Hello World!".red # "Hello World!" in red
8
+ # "Hello World!".on_green # "Hello World!" with green background
9
+ # "Hello World!".bold # "Hello World!" in bold
10
+ # "Hello World!".underline # "Hello World!" with underline
11
+ # "Hello World!".red.underline # "Hello World!" with red color and underline
13
12
  #
14
- # "Hi there!" # where 'Hi' will appear in black
15
- # # with a yellow background, and the
16
- # # rest in your default terminal
17
- # # color
13
+ # for support notes, see: https://en.wikipedia.org/wiki/ANSI_escape_code
18
14
  class String
19
- COLORS = {
15
+ COLORS = {
20
16
  black: 30,
21
- light_black: 90,
22
-
17
+ gray: 90, # convenient alias for light_black
18
+ grey: 90, # convenient alias for light_black
23
19
  red: 31,
24
- light_red: 91,
25
-
26
20
  green: 32,
27
- light_green: 92,
28
-
29
21
  yellow: 33,
30
- light_yellow: 93,
31
-
32
22
  blue: 34,
33
- light_blue: 94,
34
-
35
23
  purple: 35,
36
- light_purple: 95,
37
-
38
24
  cyan: 36,
39
- light_cyan: 96,
40
-
41
25
  white: 37,
26
+ light_black: 90,
27
+ light_red: 91,
28
+ light_green: 92,
29
+ light_yellow: 93,
30
+ light_blue: 94,
31
+ light_purple: 95,
32
+ light_cyan: 96,
42
33
  light_white: 97
43
34
  }
44
35
 
36
+ # see: https://en.wikipedia.org/wiki/ANSI_escape_code
37
+ # not all of these modes may be supported by your terminal
38
+ #
39
+ # some terminal emulators require that you enable certain features, such as
40
+ # blinking text
41
+ MODES = {
42
+ normal: 0,
43
+ bold: 1,
44
+ dim: 2,
45
+ italic: 3,
46
+ underline: 4,
47
+ blink: 5,
48
+ blink_slow: 5,
49
+ blink_fast: 6,
50
+ invert: 7,
51
+ hide: 8,
52
+ strike: 9,
53
+ double_underline: 20,
54
+ reveal: 28,
55
+ overlined: 53
56
+ }
57
+
45
58
  COLORS.each do |color, value|
46
59
  define_method color do
47
60
  "\033[#{value}m#{self}\033[0m"
48
61
  end
49
-
50
62
  define_method "on_#{color}" do
51
63
  "\033[#{value + 10}m#{self}\033[0m"
52
64
  end
53
65
  end
66
+
67
+ MODES.each do |mode, value|
68
+ define_method mode do
69
+ "\033[#{value}m#{self}\033[0m"
70
+ end
71
+ end
54
72
  end
55
73
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tiny_color
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeff Lunt
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-01-24 00:00:00.000000000 Z
11
+ date: 2023-01-25 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: a tiny library for String colorization
14
14
  email: jefflunt@gmail.com
@@ -39,6 +39,6 @@ requirements: []
39
39
  rubygems_version: 3.4.1
40
40
  signing_key:
41
41
  specification_version: 4
42
- summary: this is a minimalist library for colorinzing Strings, via extending the String
43
- class
42
+ summary: this is a minimalist library for adding color to Strings by extending the
43
+ String class
44
44
  test_files: []