tiny_color 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/tiny_color.rb +47 -32
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d3fab6755d6cbd85d80d5b68ed03896947aef7c7c546b7f4178fa78f6ba44aee
|
4
|
+
data.tar.gz: ccb2c63c201a14635de641808c9ab34001a743468ec655a8efc29598572c3243
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cb4dc9ea78870716b1c21c8fafcf8c00addf14073e09833b94b7b7d5987912d26d8cba6c58eb93b59a80e4373fe4cda67b242c0f1ca7e43dee65023e65e26015
|
7
|
+
data.tar.gz: 9c36772323fe25ce70410486c6a93da391ba74c34fea346695de366258d208f9284bc847d0376b7dcaaf7cc02d518f631f119c9c772999a45caf666259ed0f8c
|
data/lib/tiny_color.rb
CHANGED
@@ -1,58 +1,73 @@
|
|
1
|
-
# this
|
2
|
-
#
|
1
|
+
# this class extends the String class to add color formatting methods using
|
2
|
+
# ANSI escape codes.
|
3
3
|
#
|
4
|
-
#
|
5
|
-
#
|
4
|
+
# try these examples:
|
5
|
+
# require 'tiny_color'
|
6
6
|
#
|
7
|
-
# "
|
8
|
-
#
|
9
|
-
#
|
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
|
10
12
|
#
|
11
|
-
#
|
12
|
-
# puts 'Hi'.black.on_yellow + ' there!'
|
13
|
-
#
|
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
15
|
COLORS = {
|
20
16
|
black: 30,
|
21
|
-
|
22
|
-
|
23
|
-
grey: 90,
|
24
|
-
gray: 90,
|
25
|
-
|
17
|
+
gray: 90, # convenient alias for light_black
|
18
|
+
grey: 90, # convenient alias for light_black
|
26
19
|
red: 31,
|
27
|
-
light_red: 91,
|
28
|
-
|
29
20
|
green: 32,
|
30
|
-
light_green: 92,
|
31
|
-
|
32
21
|
yellow: 33,
|
33
|
-
light_yellow: 93,
|
34
|
-
|
35
22
|
blue: 34,
|
36
|
-
light_blue: 94,
|
37
|
-
|
38
23
|
purple: 35,
|
39
|
-
light_purple: 95,
|
40
|
-
|
41
24
|
cyan: 36,
|
42
|
-
light_cyan: 96,
|
43
|
-
|
44
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,
|
45
33
|
light_white: 97
|
46
34
|
}
|
47
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
|
+
|
48
58
|
COLORS.each do |color, value|
|
49
59
|
define_method color do
|
50
60
|
"\033[#{value}m#{self}\033[0m"
|
51
61
|
end
|
52
|
-
|
53
62
|
define_method "on_#{color}" do
|
54
63
|
"\033[#{value + 10}m#{self}\033[0m"
|
55
64
|
end
|
56
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
|
57
72
|
end
|
58
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.
|
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-
|
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
|
43
|
-
class
|
42
|
+
summary: this is a minimalist library for adding color to Strings by extending the
|
43
|
+
String class
|
44
44
|
test_files: []
|