tiny_color 1.1.0 → 1.2.1
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: e7113147e252bc8c34aa370879fc840a64fa354123e6b51b2f180cb0c2ad3321
|
4
|
+
data.tar.gz: c131e6532f8eab35eeaacd8a1492375ac9a0b80f545f4357e6f92e7ec47f3895
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 51747d394a4468f2c4f688dc27409c5c4b736380e30aa0899ba333de1871ed687d710032dfa96c74b8b6621283d9e52fe18b996fbe7b776b4b3a22891725f739
|
7
|
+
data.tar.gz: 14ab76eb46ee1a6a4a1dca1234cc98ca1e0a825616b487f23fe8b7ab304084c6f94313ee9d3223457b45915986e93fcd61bf4a58d194876e8868ba78b443c9b1
|
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.1
|
4
|
+
version: 1.2.1
|
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: []
|