riel 1.1.12 → 1.1.13
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +41 -0
- data/lib/riel/array.rb +0 -2
- data/lib/riel/command.rb +0 -3
- data/lib/riel/date.rb +0 -4
- data/lib/riel/file.rb +0 -1
- data/lib/riel/pathname.rb +0 -2
- data/lib/riel/setdiff.rb +5 -3
- data/lib/riel/string.rb +4 -20
- data/lib/riel/text/ansi/ansi_color.rb +31 -0
- data/lib/riel/text/ansi/ansi_colors.rb +16 -0
- data/lib/riel/text/ansi/ansi_highlight.rb +111 -0
- data/lib/riel/text/ansi/ansi_list.rb +17 -0
- data/lib/riel/text/ansi/ansi_palette.rb +48 -0
- data/lib/riel/text/ansi/attributes.rb +21 -0
- data/lib/riel/text/ansi/backgrounds.rb +13 -0
- data/lib/riel/text/ansi/color.rb +62 -0
- data/lib/riel/text/ansi/foregrounds.rb +12 -0
- data/lib/riel/text/ansi/grey.rb +30 -0
- data/lib/riel/text/ansi/grey_palette.rb +36 -0
- data/lib/riel/text/ansi/palette.rb +18 -0
- data/lib/riel/text/ansi/rgb_color.rb +28 -0
- data/lib/riel/text/ansi/rgb_palette.rb +49 -0
- data/lib/riel/text/highlight.rb +130 -0
- data/lib/riel/text/highlightable.rb +85 -0
- data/lib/riel/text/html_highlight.rb +98 -0
- data/lib/riel/text/non_highlight.rb +17 -0
- data/lib/riel/text/string.rb +10 -0
- data/lib/riel/text.rb +1 -412
- data/lib/riel.rb +1 -1
- data/test/riel/command_test.rb +11 -10
- data/test/riel/date_test.rb +23 -6
- data/test/riel/file_test.rb +15 -4
- data/test/riel/io_test.rb +2 -2
- data/test/riel/setdiff_test.rb +31 -10
- data/test/riel/string_test.rb +0 -5
- data/test/riel/text/ansi/ansi_highlight_test.rb +125 -0
- data/test/riel/text/ansi/ansi_palette_test.rb +65 -0
- data/test/riel/text/ansi/grey_palette_test.rb +39 -0
- data/test/riel/text/ansi/rgb_palette_test.rb +122 -0
- data/test/riel/text/highlightable_test.rb +27 -0
- data/test/riel/text/string_test.rb +48 -0
- data/test/riel/text_test.rb +1 -1
- metadata +37 -6
- data/README +0 -0
@@ -0,0 +1,125 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# -*- ruby -*-
|
3
|
+
|
4
|
+
require 'test/unit'
|
5
|
+
require 'riel/text/ansi/ansi_highlight'
|
6
|
+
require 'riel/text/string'
|
7
|
+
|
8
|
+
class AnsiHighlightTestCase < Test::Unit::TestCase
|
9
|
+
def run_ansi_test str, input, *chars
|
10
|
+
escape_sequence = chars.collect { |ch| "\e[#{ch}m" }.join("")
|
11
|
+
assert_equal "#{escape_sequence}#{str}\e[0m", input
|
12
|
+
end
|
13
|
+
|
14
|
+
def setup
|
15
|
+
Text::Highlightable.add_to String
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_ansi_highlight
|
19
|
+
str = "precision"
|
20
|
+
|
21
|
+
run_ansi_test str, str.none, 0
|
22
|
+
run_ansi_test str, str.bold, 1
|
23
|
+
run_ansi_test str, str.underline, 4
|
24
|
+
run_ansi_test str, str.underscore, 4
|
25
|
+
run_ansi_test str, str.blink, 5 # every geocities site circa 1998
|
26
|
+
run_ansi_test str, str.negative, 7
|
27
|
+
run_ansi_test str, str.concealed, 8
|
28
|
+
|
29
|
+
run_ansi_test str, str.black, 30
|
30
|
+
run_ansi_test str, str.red, 31
|
31
|
+
run_ansi_test str, str.green, 32
|
32
|
+
run_ansi_test str, str.yellow, 33
|
33
|
+
run_ansi_test str, str.blue, 34
|
34
|
+
run_ansi_test str, str.magenta, 35
|
35
|
+
run_ansi_test str, str.cyan, 36
|
36
|
+
run_ansi_test str, str.white, 37
|
37
|
+
|
38
|
+
run_ansi_test str, str.on_black, 40
|
39
|
+
run_ansi_test str, str.on_red, 41
|
40
|
+
run_ansi_test str, str.on_green, 42
|
41
|
+
run_ansi_test str, str.on_yellow, 43
|
42
|
+
run_ansi_test str, str.on_blue, 44
|
43
|
+
run_ansi_test str, str.on_magenta, 45
|
44
|
+
run_ansi_test str, str.on_cyan, 46
|
45
|
+
run_ansi_test str, str.on_white, 47
|
46
|
+
|
47
|
+
run_ansi_test str, str.none_on_white, 0, 47
|
48
|
+
run_ansi_test str, str.none_on_black, 0, 40
|
49
|
+
run_ansi_test str, str.none_on_blue, 0, 44
|
50
|
+
run_ansi_test str, str.red_on_white, 31, 47
|
51
|
+
run_ansi_test str, str.bold_red_on_white, 1, 31, 47
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_highlighter
|
55
|
+
hl = Text::ANSIHighlighter.instance
|
56
|
+
assert_equal "\e[1m", hl.code('bold')
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_gsub
|
60
|
+
hl = Text::ANSIHighlighter.instance
|
61
|
+
assert_equal "...\e[34mthis\e[0m... is blue", hl.gsub("...this... is blue", %r{this}, "blue")
|
62
|
+
assert_equal "...\e[34m\e[42mthis\e[0m... is blue", hl.gsub("...this... is blue", %r{this}, "blue on green")
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_rgb
|
66
|
+
str = "123".rgb(1, 2, 3)
|
67
|
+
assert_equal "\x1b[38;5;67m123\e[0m", str
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_on_rgb
|
71
|
+
str = "123".on_rgb(1, 2, 3)
|
72
|
+
assert_equal "\x1b[48;5;67m123\e[0m", str
|
73
|
+
end
|
74
|
+
|
75
|
+
def test_grey
|
76
|
+
str = "123".grey(14)
|
77
|
+
assert_equal "\x1b[38;5;246m123\e[0m", str
|
78
|
+
end
|
79
|
+
|
80
|
+
def test_on_grey
|
81
|
+
str = "123".on_grey(4)
|
82
|
+
assert_equal "\x1b[48;5;236m123\e[0m", str
|
83
|
+
end
|
84
|
+
|
85
|
+
def test_gray
|
86
|
+
str = "123".gray(14)
|
87
|
+
assert_equal "\x1b[38;5;246m123\e[0m", str
|
88
|
+
end
|
89
|
+
|
90
|
+
def test_on_gray
|
91
|
+
str = "123".on_gray(4)
|
92
|
+
assert_equal "\x1b[48;5;236m123\e[0m", str
|
93
|
+
end
|
94
|
+
|
95
|
+
def test_multiple
|
96
|
+
str = "ABC".bold.blue.on_green
|
97
|
+
assert_equal "\e[42m\e[34m\e[1mABC\e[0m\e[0m\e[0m", str
|
98
|
+
end
|
99
|
+
|
100
|
+
def test_multiple_add_to
|
101
|
+
Text::Highlightable.add_to Integer
|
102
|
+
str = "ABC".blue
|
103
|
+
int = 123.red
|
104
|
+
# puts str + int.to_s
|
105
|
+
assert_equal "\e[34mABC\e[0m\e[31m123\e[0m", str + int
|
106
|
+
end
|
107
|
+
|
108
|
+
def test_rgb_fg_alias
|
109
|
+
hl = Text::ANSIHighlighter.instance
|
110
|
+
hl.add_alias :teal, 1, 4, 4
|
111
|
+
|
112
|
+
str = "ABC".teal
|
113
|
+
# puts str
|
114
|
+
assert_equal "\x1b[38;5;80mABC\e[0m", str
|
115
|
+
end
|
116
|
+
|
117
|
+
def test_rgb_bg_alias
|
118
|
+
hl = Text::ANSIHighlighter.instance
|
119
|
+
hl.add_alias :on_maroon, 1, 0, 2
|
120
|
+
|
121
|
+
str = "ABC".on_maroon
|
122
|
+
# puts str
|
123
|
+
assert_equal "\x1b[48;5;54mABC\e[0m", str
|
124
|
+
end
|
125
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# -*- ruby -*-
|
3
|
+
|
4
|
+
require 'riel/text/ansi/ansi_palette'
|
5
|
+
require 'riel/text/ansi/palette_tc'
|
6
|
+
|
7
|
+
module Text
|
8
|
+
class AnsiPaletteTest < PaletteTest
|
9
|
+
def cls
|
10
|
+
AnsiPalette
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_ansi_foregrounds
|
14
|
+
expected = [
|
15
|
+
"ansi foregrounds\n",
|
16
|
+
"[38;5;0m0/.[0m [38;5;1m1/.[0m [38;5;2m2/.[0m [38;5;3m3/.[0m [38;5;4m4/.[0m [38;5;5m5/.[0m [38;5;6m6/.[0m [38;5;7m7/.[0m \n",
|
17
|
+
"\n",
|
18
|
+
]
|
19
|
+
|
20
|
+
assert_print expected, :print_foregrounds
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_ansi_backgrounds
|
24
|
+
expected = [
|
25
|
+
"ansi backgrounds\n",
|
26
|
+
"[48;5;0m./0[0m [48;5;1m./1[0m [48;5;2m./2[0m [48;5;3m./3[0m [48;5;4m./4[0m [48;5;5m./5[0m [48;5;6m./6[0m [48;5;7m./7[0m \n",
|
27
|
+
"\n",
|
28
|
+
]
|
29
|
+
|
30
|
+
assert_print expected, :print_backgrounds
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_ansi_combinations
|
34
|
+
expected = [
|
35
|
+
"ansi combinations\n",
|
36
|
+
"bg: 000\n",
|
37
|
+
"[48;5;0m[38;5;0m0/.[0m [48;5;0m[38;5;1m1/.[0m [48;5;0m[38;5;2m2/.[0m [48;5;0m[38;5;3m3/.[0m [48;5;0m[38;5;4m4/.[0m [48;5;0m[38;5;5m5/.[0m [48;5;0m[38;5;6m6/.[0m [48;5;0m[38;5;7m7/.[0m \n",
|
38
|
+
"\n",
|
39
|
+
"bg: 001\n",
|
40
|
+
"[48;5;1m[38;5;0m0/.[0m [48;5;1m[38;5;1m1/.[0m [48;5;1m[38;5;2m2/.[0m [48;5;1m[38;5;3m3/.[0m [48;5;1m[38;5;4m4/.[0m [48;5;1m[38;5;5m5/.[0m [48;5;1m[38;5;6m6/.[0m [48;5;1m[38;5;7m7/.[0m \n",
|
41
|
+
"\n",
|
42
|
+
"bg: 002\n",
|
43
|
+
"[48;5;2m[38;5;0m0/.[0m [48;5;2m[38;5;1m1/.[0m [48;5;2m[38;5;2m2/.[0m [48;5;2m[38;5;3m3/.[0m [48;5;2m[38;5;4m4/.[0m [48;5;2m[38;5;5m5/.[0m [48;5;2m[38;5;6m6/.[0m [48;5;2m[38;5;7m7/.[0m \n",
|
44
|
+
"\n",
|
45
|
+
"bg: 003\n",
|
46
|
+
"[48;5;3m[38;5;0m0/.[0m [48;5;3m[38;5;1m1/.[0m [48;5;3m[38;5;2m2/.[0m [48;5;3m[38;5;3m3/.[0m [48;5;3m[38;5;4m4/.[0m [48;5;3m[38;5;5m5/.[0m [48;5;3m[38;5;6m6/.[0m [48;5;3m[38;5;7m7/.[0m \n",
|
47
|
+
"\n",
|
48
|
+
"bg: 004\n",
|
49
|
+
"[48;5;4m[38;5;0m0/.[0m [48;5;4m[38;5;1m1/.[0m [48;5;4m[38;5;2m2/.[0m [48;5;4m[38;5;3m3/.[0m [48;5;4m[38;5;4m4/.[0m [48;5;4m[38;5;5m5/.[0m [48;5;4m[38;5;6m6/.[0m [48;5;4m[38;5;7m7/.[0m \n",
|
50
|
+
"\n",
|
51
|
+
"bg: 005\n",
|
52
|
+
"[48;5;5m[38;5;0m0/.[0m [48;5;5m[38;5;1m1/.[0m [48;5;5m[38;5;2m2/.[0m [48;5;5m[38;5;3m3/.[0m [48;5;5m[38;5;4m4/.[0m [48;5;5m[38;5;5m5/.[0m [48;5;5m[38;5;6m6/.[0m [48;5;5m[38;5;7m7/.[0m \n",
|
53
|
+
"\n",
|
54
|
+
"bg: 006\n",
|
55
|
+
"[48;5;6m[38;5;0m0/.[0m [48;5;6m[38;5;1m1/.[0m [48;5;6m[38;5;2m2/.[0m [48;5;6m[38;5;3m3/.[0m [48;5;6m[38;5;4m4/.[0m [48;5;6m[38;5;5m5/.[0m [48;5;6m[38;5;6m6/.[0m [48;5;6m[38;5;7m7/.[0m \n",
|
56
|
+
"\n",
|
57
|
+
"bg: 007\n",
|
58
|
+
"[48;5;7m[38;5;0m0/.[0m [48;5;7m[38;5;1m1/.[0m [48;5;7m[38;5;2m2/.[0m [48;5;7m[38;5;3m3/.[0m [48;5;7m[38;5;4m4/.[0m [48;5;7m[38;5;5m5/.[0m [48;5;7m[38;5;6m6/.[0m [48;5;7m[38;5;7m7/.[0m \n",
|
59
|
+
"\n",
|
60
|
+
]
|
61
|
+
|
62
|
+
assert_print expected, :print_combinations
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# -*- ruby -*-
|
3
|
+
|
4
|
+
require 'riel/text/ansi/grey_palette'
|
5
|
+
require 'riel/text/ansi/palette_tc'
|
6
|
+
|
7
|
+
module Text
|
8
|
+
class GreyPaletteTest < PaletteTest
|
9
|
+
def cls
|
10
|
+
GreyPalette
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_foregrounds
|
14
|
+
expected = [
|
15
|
+
"grey foreground colors\n",
|
16
|
+
"[38;5;232m232[0m [38;5;233m233[0m [38;5;234m234[0m [38;5;235m235[0m [38;5;236m236[0m [38;5;237m237[0m \n",
|
17
|
+
"[38;5;238m238[0m [38;5;239m239[0m [38;5;240m240[0m [38;5;241m241[0m [38;5;242m242[0m [38;5;243m243[0m \n",
|
18
|
+
"[38;5;244m244[0m [38;5;245m245[0m [38;5;246m246[0m [38;5;247m247[0m [38;5;248m248[0m [38;5;249m249[0m \n",
|
19
|
+
"[38;5;250m250[0m [38;5;251m251[0m [38;5;252m252[0m [38;5;253m253[0m [38;5;254m254[0m [38;5;255m255[0m \n",
|
20
|
+
"\n",
|
21
|
+
]
|
22
|
+
|
23
|
+
assert_print expected, :print_foregrounds
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_backgrounds
|
27
|
+
expected = [
|
28
|
+
"grey background colors\n",
|
29
|
+
"[48;5;232m232[0m [48;5;233m233[0m [48;5;234m234[0m [48;5;235m235[0m [48;5;236m236[0m [48;5;237m237[0m \n",
|
30
|
+
"[48;5;238m238[0m [48;5;239m239[0m [48;5;240m240[0m [48;5;241m241[0m [48;5;242m242[0m [48;5;243m243[0m \n",
|
31
|
+
"[48;5;244m244[0m [48;5;245m245[0m [48;5;246m246[0m [48;5;247m247[0m [48;5;248m248[0m [48;5;249m249[0m \n",
|
32
|
+
"[48;5;250m250[0m [48;5;251m251[0m [48;5;252m252[0m [48;5;253m253[0m [48;5;254m254[0m [48;5;255m255[0m \n",
|
33
|
+
"\n",
|
34
|
+
]
|
35
|
+
|
36
|
+
assert_print expected, :print_backgrounds
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,122 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# -*- ruby -*-
|
3
|
+
|
4
|
+
require 'riel/text/ansi/rgb_palette'
|
5
|
+
require 'riel/text/ansi/palette_tc'
|
6
|
+
|
7
|
+
module Text
|
8
|
+
class RGBPaletteTest < PaletteTest
|
9
|
+
def cls
|
10
|
+
RGBPalette
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_foregrounds
|
14
|
+
expected = [
|
15
|
+
"rgb foreground colors\n",
|
16
|
+
"[38;5;16m000[0m [38;5;17m001[0m [38;5;18m002[0m [38;5;19m003[0m [38;5;20m004[0m [38;5;21m005[0m \n",
|
17
|
+
"[38;5;22m010[0m [38;5;23m011[0m [38;5;24m012[0m [38;5;25m013[0m [38;5;26m014[0m [38;5;27m015[0m \n",
|
18
|
+
"[38;5;28m020[0m [38;5;29m021[0m [38;5;30m022[0m [38;5;31m023[0m [38;5;32m024[0m [38;5;33m025[0m \n",
|
19
|
+
"[38;5;34m030[0m [38;5;35m031[0m [38;5;36m032[0m [38;5;37m033[0m [38;5;38m034[0m [38;5;39m035[0m \n",
|
20
|
+
"[38;5;40m040[0m [38;5;41m041[0m [38;5;42m042[0m [38;5;43m043[0m [38;5;44m044[0m [38;5;45m045[0m \n",
|
21
|
+
"[38;5;46m050[0m [38;5;47m051[0m [38;5;48m052[0m [38;5;49m053[0m [38;5;50m054[0m [38;5;51m055[0m \n",
|
22
|
+
"\n",
|
23
|
+
"[38;5;52m100[0m [38;5;53m101[0m [38;5;54m102[0m [38;5;55m103[0m [38;5;56m104[0m [38;5;57m105[0m \n",
|
24
|
+
"[38;5;58m110[0m [38;5;59m111[0m [38;5;60m112[0m [38;5;61m113[0m [38;5;62m114[0m [38;5;63m115[0m \n",
|
25
|
+
"[38;5;64m120[0m [38;5;65m121[0m [38;5;66m122[0m [38;5;67m123[0m [38;5;68m124[0m [38;5;69m125[0m \n",
|
26
|
+
"[38;5;70m130[0m [38;5;71m131[0m [38;5;72m132[0m [38;5;73m133[0m [38;5;74m134[0m [38;5;75m135[0m \n",
|
27
|
+
"[38;5;76m140[0m [38;5;77m141[0m [38;5;78m142[0m [38;5;79m143[0m [38;5;80m144[0m [38;5;81m145[0m \n",
|
28
|
+
"[38;5;82m150[0m [38;5;83m151[0m [38;5;84m152[0m [38;5;85m153[0m [38;5;86m154[0m [38;5;87m155[0m \n",
|
29
|
+
"\n",
|
30
|
+
"[38;5;88m200[0m [38;5;89m201[0m [38;5;90m202[0m [38;5;91m203[0m [38;5;92m204[0m [38;5;93m205[0m \n",
|
31
|
+
"[38;5;94m210[0m [38;5;95m211[0m [38;5;96m212[0m [38;5;97m213[0m [38;5;98m214[0m [38;5;99m215[0m \n",
|
32
|
+
"[38;5;100m220[0m [38;5;101m221[0m [38;5;102m222[0m [38;5;103m223[0m [38;5;104m224[0m [38;5;105m225[0m \n",
|
33
|
+
"[38;5;106m230[0m [38;5;107m231[0m [38;5;108m232[0m [38;5;109m233[0m [38;5;110m234[0m [38;5;111m235[0m \n",
|
34
|
+
"[38;5;112m240[0m [38;5;113m241[0m [38;5;114m242[0m [38;5;115m243[0m [38;5;116m244[0m [38;5;117m245[0m \n",
|
35
|
+
"[38;5;118m250[0m [38;5;119m251[0m [38;5;120m252[0m [38;5;121m253[0m [38;5;122m254[0m [38;5;123m255[0m \n",
|
36
|
+
"\n",
|
37
|
+
"[38;5;124m300[0m [38;5;125m301[0m [38;5;126m302[0m [38;5;127m303[0m [38;5;128m304[0m [38;5;129m305[0m \n",
|
38
|
+
"[38;5;130m310[0m [38;5;131m311[0m [38;5;132m312[0m [38;5;133m313[0m [38;5;134m314[0m [38;5;135m315[0m \n",
|
39
|
+
"[38;5;136m320[0m [38;5;137m321[0m [38;5;138m322[0m [38;5;139m323[0m [38;5;140m324[0m [38;5;141m325[0m \n",
|
40
|
+
"[38;5;142m330[0m [38;5;143m331[0m [38;5;144m332[0m [38;5;145m333[0m [38;5;146m334[0m [38;5;147m335[0m \n",
|
41
|
+
"[38;5;148m340[0m [38;5;149m341[0m [38;5;150m342[0m [38;5;151m343[0m [38;5;152m344[0m [38;5;153m345[0m \n",
|
42
|
+
"[38;5;154m350[0m [38;5;155m351[0m [38;5;156m352[0m [38;5;157m353[0m [38;5;158m354[0m [38;5;159m355[0m \n",
|
43
|
+
"\n",
|
44
|
+
"[38;5;160m400[0m [38;5;161m401[0m [38;5;162m402[0m [38;5;163m403[0m [38;5;164m404[0m [38;5;165m405[0m \n",
|
45
|
+
"[38;5;166m410[0m [38;5;167m411[0m [38;5;168m412[0m [38;5;169m413[0m [38;5;170m414[0m [38;5;171m415[0m \n",
|
46
|
+
"[38;5;172m420[0m [38;5;173m421[0m [38;5;174m422[0m [38;5;175m423[0m [38;5;176m424[0m [38;5;177m425[0m \n",
|
47
|
+
"[38;5;178m430[0m [38;5;179m431[0m [38;5;180m432[0m [38;5;181m433[0m [38;5;182m434[0m [38;5;183m435[0m \n",
|
48
|
+
"[38;5;184m440[0m [38;5;185m441[0m [38;5;186m442[0m [38;5;187m443[0m [38;5;188m444[0m [38;5;189m445[0m \n",
|
49
|
+
"[38;5;190m450[0m [38;5;191m451[0m [38;5;192m452[0m [38;5;193m453[0m [38;5;194m454[0m [38;5;195m455[0m \n",
|
50
|
+
"\n",
|
51
|
+
"[38;5;196m500[0m [38;5;197m501[0m [38;5;198m502[0m [38;5;199m503[0m [38;5;200m504[0m [38;5;201m505[0m \n",
|
52
|
+
"[38;5;202m510[0m [38;5;203m511[0m [38;5;204m512[0m [38;5;205m513[0m [38;5;206m514[0m [38;5;207m515[0m \n",
|
53
|
+
"[38;5;208m520[0m [38;5;209m521[0m [38;5;210m522[0m [38;5;211m523[0m [38;5;212m524[0m [38;5;213m525[0m \n",
|
54
|
+
"[38;5;214m530[0m [38;5;215m531[0m [38;5;216m532[0m [38;5;217m533[0m [38;5;218m534[0m [38;5;219m535[0m \n",
|
55
|
+
"[38;5;220m540[0m [38;5;221m541[0m [38;5;222m542[0m [38;5;223m543[0m [38;5;224m544[0m [38;5;225m545[0m \n",
|
56
|
+
"[38;5;226m550[0m [38;5;227m551[0m [38;5;228m552[0m [38;5;229m553[0m [38;5;230m554[0m [38;5;231m555[0m \n",
|
57
|
+
"\n",
|
58
|
+
]
|
59
|
+
|
60
|
+
assert_print expected, :print_foregrounds
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_backgrounds
|
64
|
+
expected = [
|
65
|
+
"rgb background colors\n",
|
66
|
+
"[48;5;16m000[0m [48;5;17m001[0m [48;5;18m002[0m [48;5;19m003[0m [48;5;20m004[0m [48;5;21m005[0m \n",
|
67
|
+
"[48;5;22m010[0m [48;5;23m011[0m [48;5;24m012[0m [48;5;25m013[0m [48;5;26m014[0m [48;5;27m015[0m \n",
|
68
|
+
"[48;5;28m020[0m [48;5;29m021[0m [48;5;30m022[0m [48;5;31m023[0m [48;5;32m024[0m [48;5;33m025[0m \n",
|
69
|
+
"[48;5;34m030[0m [48;5;35m031[0m [48;5;36m032[0m [48;5;37m033[0m [48;5;38m034[0m [48;5;39m035[0m \n",
|
70
|
+
"[48;5;40m040[0m [48;5;41m041[0m [48;5;42m042[0m [48;5;43m043[0m [48;5;44m044[0m [48;5;45m045[0m \n",
|
71
|
+
"[48;5;46m050[0m [48;5;47m051[0m [48;5;48m052[0m [48;5;49m053[0m [48;5;50m054[0m [48;5;51m055[0m \n",
|
72
|
+
"\n",
|
73
|
+
"[48;5;52m100[0m [48;5;53m101[0m [48;5;54m102[0m [48;5;55m103[0m [48;5;56m104[0m [48;5;57m105[0m \n",
|
74
|
+
"[48;5;58m110[0m [48;5;59m111[0m [48;5;60m112[0m [48;5;61m113[0m [48;5;62m114[0m [48;5;63m115[0m \n",
|
75
|
+
"[48;5;64m120[0m [48;5;65m121[0m [48;5;66m122[0m [48;5;67m123[0m [48;5;68m124[0m [48;5;69m125[0m \n",
|
76
|
+
"[48;5;70m130[0m [48;5;71m131[0m [48;5;72m132[0m [48;5;73m133[0m [48;5;74m134[0m [48;5;75m135[0m \n",
|
77
|
+
"[48;5;76m140[0m [48;5;77m141[0m [48;5;78m142[0m [48;5;79m143[0m [48;5;80m144[0m [48;5;81m145[0m \n",
|
78
|
+
"[48;5;82m150[0m [48;5;83m151[0m [48;5;84m152[0m [48;5;85m153[0m [48;5;86m154[0m [48;5;87m155[0m \n",
|
79
|
+
"\n",
|
80
|
+
"[48;5;88m200[0m [48;5;89m201[0m [48;5;90m202[0m [48;5;91m203[0m [48;5;92m204[0m [48;5;93m205[0m \n",
|
81
|
+
"[48;5;94m210[0m [48;5;95m211[0m [48;5;96m212[0m [48;5;97m213[0m [48;5;98m214[0m [48;5;99m215[0m \n",
|
82
|
+
"[48;5;100m220[0m [48;5;101m221[0m [48;5;102m222[0m [48;5;103m223[0m [48;5;104m224[0m [48;5;105m225[0m \n",
|
83
|
+
"[48;5;106m230[0m [48;5;107m231[0m [48;5;108m232[0m [48;5;109m233[0m [48;5;110m234[0m [48;5;111m235[0m \n",
|
84
|
+
"[48;5;112m240[0m [48;5;113m241[0m [48;5;114m242[0m [48;5;115m243[0m [48;5;116m244[0m [48;5;117m245[0m \n",
|
85
|
+
"[48;5;118m250[0m [48;5;119m251[0m [48;5;120m252[0m [48;5;121m253[0m [48;5;122m254[0m [48;5;123m255[0m \n",
|
86
|
+
"\n",
|
87
|
+
"[48;5;124m300[0m [48;5;125m301[0m [48;5;126m302[0m [48;5;127m303[0m [48;5;128m304[0m [48;5;129m305[0m \n",
|
88
|
+
"[48;5;130m310[0m [48;5;131m311[0m [48;5;132m312[0m [48;5;133m313[0m [48;5;134m314[0m [48;5;135m315[0m \n",
|
89
|
+
"[48;5;136m320[0m [48;5;137m321[0m [48;5;138m322[0m [48;5;139m323[0m [48;5;140m324[0m [48;5;141m325[0m \n",
|
90
|
+
"[48;5;142m330[0m [48;5;143m331[0m [48;5;144m332[0m [48;5;145m333[0m [48;5;146m334[0m [48;5;147m335[0m \n",
|
91
|
+
"[48;5;148m340[0m [48;5;149m341[0m [48;5;150m342[0m [48;5;151m343[0m [48;5;152m344[0m [48;5;153m345[0m \n",
|
92
|
+
"[48;5;154m350[0m [48;5;155m351[0m [48;5;156m352[0m [48;5;157m353[0m [48;5;158m354[0m [48;5;159m355[0m \n",
|
93
|
+
"\n",
|
94
|
+
"[48;5;160m400[0m [48;5;161m401[0m [48;5;162m402[0m [48;5;163m403[0m [48;5;164m404[0m [48;5;165m405[0m \n",
|
95
|
+
"[48;5;166m410[0m [48;5;167m411[0m [48;5;168m412[0m [48;5;169m413[0m [48;5;170m414[0m [48;5;171m415[0m \n",
|
96
|
+
"[48;5;172m420[0m [48;5;173m421[0m [48;5;174m422[0m [48;5;175m423[0m [48;5;176m424[0m [48;5;177m425[0m \n",
|
97
|
+
"[48;5;178m430[0m [48;5;179m431[0m [48;5;180m432[0m [48;5;181m433[0m [48;5;182m434[0m [48;5;183m435[0m \n",
|
98
|
+
"[48;5;184m440[0m [48;5;185m441[0m [48;5;186m442[0m [48;5;187m443[0m [48;5;188m444[0m [48;5;189m445[0m \n",
|
99
|
+
"[48;5;190m450[0m [48;5;191m451[0m [48;5;192m452[0m [48;5;193m453[0m [48;5;194m454[0m [48;5;195m455[0m \n",
|
100
|
+
"\n",
|
101
|
+
"[48;5;196m500[0m [48;5;197m501[0m [48;5;198m502[0m [48;5;199m503[0m [48;5;200m504[0m [48;5;201m505[0m \n",
|
102
|
+
"[48;5;202m510[0m [48;5;203m511[0m [48;5;204m512[0m [48;5;205m513[0m [48;5;206m514[0m [48;5;207m515[0m \n",
|
103
|
+
"[48;5;208m520[0m [48;5;209m521[0m [48;5;210m522[0m [48;5;211m523[0m [48;5;212m524[0m [48;5;213m525[0m \n",
|
104
|
+
"[48;5;214m530[0m [48;5;215m531[0m [48;5;216m532[0m [48;5;217m533[0m [48;5;218m534[0m [48;5;219m535[0m \n",
|
105
|
+
"[48;5;220m540[0m [48;5;221m541[0m [48;5;222m542[0m [48;5;223m543[0m [48;5;224m544[0m [48;5;225m545[0m \n",
|
106
|
+
"[48;5;226m550[0m [48;5;227m551[0m [48;5;228m552[0m [48;5;229m553[0m [48;5;230m554[0m [48;5;231m555[0m \n",
|
107
|
+
"\n",
|
108
|
+
]
|
109
|
+
|
110
|
+
assert_print expected, :print_backgrounds
|
111
|
+
end
|
112
|
+
|
113
|
+
def test_combinations
|
114
|
+
# not checking this, since it is over 9000 lines of output:
|
115
|
+
expected = [
|
116
|
+
# a lot
|
117
|
+
]
|
118
|
+
|
119
|
+
# assert_print expected, :print_combinations
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# -*- ruby -*-
|
3
|
+
|
4
|
+
require 'test/unit'
|
5
|
+
require 'riel/text/ansi/ansi_highlight'
|
6
|
+
require 'riel/text/string'
|
7
|
+
|
8
|
+
class HighlightableTestCase < Test::Unit::TestCase
|
9
|
+
def test_string_add_to
|
10
|
+
Text::Highlightable.add_to String
|
11
|
+
assert_equal "\e[34mfoo\e[0m", "foo".blue
|
12
|
+
end
|
13
|
+
|
14
|
+
class String
|
15
|
+
include Text::Highlightable
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_string_include
|
19
|
+
assert_equal "\e[34mfoo\e[0m", "foo".blue
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_string_respond_to
|
23
|
+
str = ""
|
24
|
+
assert str.respond_to? :blue
|
25
|
+
assert !str.respond_to?(:azure)
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# -*- ruby -*-
|
3
|
+
|
4
|
+
require 'test/unit'
|
5
|
+
require 'riel/text/ansi/ansi_highlight'
|
6
|
+
require 'riel/text/string'
|
7
|
+
|
8
|
+
class StringTestCase < Test::Unit::TestCase
|
9
|
+
def run_test str, input, *chars
|
10
|
+
escape_sequence = chars.collect { |ch| "\e[#{ch}m" }.join("")
|
11
|
+
assert_equal "#{escape_sequence}#{str}\e[0m", input
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_all_ansi
|
15
|
+
String.highlighter = "ANSI"
|
16
|
+
|
17
|
+
str = "precision"
|
18
|
+
|
19
|
+
run_test str, str.none, 0
|
20
|
+
run_test str, str.bold, 1
|
21
|
+
run_test str, str.underline, 4
|
22
|
+
run_test str, str.underscore, 4
|
23
|
+
run_test str, str.blink, 5 # every geocities site circa 1998
|
24
|
+
run_test str, str.negative, 7
|
25
|
+
run_test str, str.concealed, 8
|
26
|
+
run_test str, str.black, 30
|
27
|
+
run_test str, str.red, 31
|
28
|
+
run_test str, str.green, 32
|
29
|
+
run_test str, str.yellow, 33
|
30
|
+
run_test str, str.blue, 34
|
31
|
+
run_test str, str.magenta, 35
|
32
|
+
run_test str, str.cyan, 36
|
33
|
+
run_test str, str.white, 37
|
34
|
+
run_test str, str.on_black, 40
|
35
|
+
run_test str, str.on_red, 41
|
36
|
+
run_test str, str.on_green, 42
|
37
|
+
run_test str, str.on_yellow, 43
|
38
|
+
run_test str, str.on_blue, 44
|
39
|
+
run_test str, str.on_magenta, 45
|
40
|
+
run_test str, str.on_cyan, 46
|
41
|
+
run_test str, str.on_white, 47
|
42
|
+
run_test str, str.none_on_white, 0, 47
|
43
|
+
run_test str, str.none_on_black, 0, 40
|
44
|
+
run_test str, str.none_on_blue, 0, 44
|
45
|
+
run_test str, str.red_on_white, 31, 47
|
46
|
+
run_test str, str.bold_red_on_white, 1, 31, 47
|
47
|
+
end
|
48
|
+
end
|
data/test/riel/text_test.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: riel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 9
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 1.1.
|
9
|
+
- 13
|
10
|
+
version: 1.1.13
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Jeff Pace
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-
|
18
|
+
date: 2012-12-08 00:00:00 -05:00
|
19
19
|
default_executable:
|
20
20
|
dependencies: []
|
21
21
|
|
@@ -26,7 +26,7 @@ executables: []
|
|
26
26
|
extensions: []
|
27
27
|
|
28
28
|
extra_rdoc_files:
|
29
|
-
- README
|
29
|
+
- README.md
|
30
30
|
files:
|
31
31
|
- lib/riel/array.rb
|
32
32
|
- lib/riel/size_converter.rb
|
@@ -47,6 +47,25 @@ files:
|
|
47
47
|
- lib/riel/tempfile.rb
|
48
48
|
- lib/riel/string.rb
|
49
49
|
- lib/riel/command.rb
|
50
|
+
- lib/riel/text/non_highlight.rb
|
51
|
+
- lib/riel/text/html_highlight.rb
|
52
|
+
- lib/riel/text/string.rb
|
53
|
+
- lib/riel/text/highlightable.rb
|
54
|
+
- lib/riel/text/highlight.rb
|
55
|
+
- lib/riel/text/ansi/backgrounds.rb
|
56
|
+
- lib/riel/text/ansi/color.rb
|
57
|
+
- lib/riel/text/ansi/ansi_color.rb
|
58
|
+
- lib/riel/text/ansi/rgb_color.rb
|
59
|
+
- lib/riel/text/ansi/attributes.rb
|
60
|
+
- lib/riel/text/ansi/ansi_highlight.rb
|
61
|
+
- lib/riel/text/ansi/grey_palette.rb
|
62
|
+
- lib/riel/text/ansi/ansi_palette.rb
|
63
|
+
- lib/riel/text/ansi/rgb_palette.rb
|
64
|
+
- lib/riel/text/ansi/foregrounds.rb
|
65
|
+
- lib/riel/text/ansi/ansi_colors.rb
|
66
|
+
- lib/riel/text/ansi/palette.rb
|
67
|
+
- lib/riel/text/ansi/grey.rb
|
68
|
+
- lib/riel/text/ansi/ansi_list.rb
|
50
69
|
- lib/riel/pathname.rb
|
51
70
|
- lib/riel/file.rb
|
52
71
|
- lib/riel/integer.rb
|
@@ -78,6 +97,12 @@ files:
|
|
78
97
|
- test/riel/tempfile_test.rb
|
79
98
|
- test/riel/filetype_test.rb
|
80
99
|
- test/riel/log_test.rb
|
100
|
+
- test/riel/text/ansi/ansi_palette_test.rb
|
101
|
+
- test/riel/text/ansi/rgb_palette_test.rb
|
102
|
+
- test/riel/text/ansi/grey_palette_test.rb
|
103
|
+
- test/riel/text/ansi/ansi_highlight_test.rb
|
104
|
+
- test/riel/text/string_test.rb
|
105
|
+
- test/riel/text/highlightable_test.rb
|
81
106
|
- test/riel/integer_test.rb
|
82
107
|
- test/riel/rcfile_test.rb
|
83
108
|
- test/riel/log_stack_test.rb
|
@@ -86,7 +111,7 @@ files:
|
|
86
111
|
- test/riel/string_test.rb
|
87
112
|
- test/riel/command_test.rb
|
88
113
|
- test/riel/timer_test.rb
|
89
|
-
- README
|
114
|
+
- README.md
|
90
115
|
has_rdoc: true
|
91
116
|
homepage: http://www.incava.org/projects/riel
|
92
117
|
licenses: []
|
@@ -138,6 +163,12 @@ test_files:
|
|
138
163
|
- test/riel/tempfile_test.rb
|
139
164
|
- test/riel/filetype_test.rb
|
140
165
|
- test/riel/log_test.rb
|
166
|
+
- test/riel/text/ansi/ansi_palette_test.rb
|
167
|
+
- test/riel/text/ansi/rgb_palette_test.rb
|
168
|
+
- test/riel/text/ansi/grey_palette_test.rb
|
169
|
+
- test/riel/text/ansi/ansi_highlight_test.rb
|
170
|
+
- test/riel/text/string_test.rb
|
171
|
+
- test/riel/text/highlightable_test.rb
|
141
172
|
- test/riel/integer_test.rb
|
142
173
|
- test/riel/rcfile_test.rb
|
143
174
|
- test/riel/log_stack_test.rb
|
data/README
DELETED
File without changes
|