riel 1.1.12 → 1.1.13

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. data/README.md +41 -0
  2. data/lib/riel/array.rb +0 -2
  3. data/lib/riel/command.rb +0 -3
  4. data/lib/riel/date.rb +0 -4
  5. data/lib/riel/file.rb +0 -1
  6. data/lib/riel/pathname.rb +0 -2
  7. data/lib/riel/setdiff.rb +5 -3
  8. data/lib/riel/string.rb +4 -20
  9. data/lib/riel/text/ansi/ansi_color.rb +31 -0
  10. data/lib/riel/text/ansi/ansi_colors.rb +16 -0
  11. data/lib/riel/text/ansi/ansi_highlight.rb +111 -0
  12. data/lib/riel/text/ansi/ansi_list.rb +17 -0
  13. data/lib/riel/text/ansi/ansi_palette.rb +48 -0
  14. data/lib/riel/text/ansi/attributes.rb +21 -0
  15. data/lib/riel/text/ansi/backgrounds.rb +13 -0
  16. data/lib/riel/text/ansi/color.rb +62 -0
  17. data/lib/riel/text/ansi/foregrounds.rb +12 -0
  18. data/lib/riel/text/ansi/grey.rb +30 -0
  19. data/lib/riel/text/ansi/grey_palette.rb +36 -0
  20. data/lib/riel/text/ansi/palette.rb +18 -0
  21. data/lib/riel/text/ansi/rgb_color.rb +28 -0
  22. data/lib/riel/text/ansi/rgb_palette.rb +49 -0
  23. data/lib/riel/text/highlight.rb +130 -0
  24. data/lib/riel/text/highlightable.rb +85 -0
  25. data/lib/riel/text/html_highlight.rb +98 -0
  26. data/lib/riel/text/non_highlight.rb +17 -0
  27. data/lib/riel/text/string.rb +10 -0
  28. data/lib/riel/text.rb +1 -412
  29. data/lib/riel.rb +1 -1
  30. data/test/riel/command_test.rb +11 -10
  31. data/test/riel/date_test.rb +23 -6
  32. data/test/riel/file_test.rb +15 -4
  33. data/test/riel/io_test.rb +2 -2
  34. data/test/riel/setdiff_test.rb +31 -10
  35. data/test/riel/string_test.rb +0 -5
  36. data/test/riel/text/ansi/ansi_highlight_test.rb +125 -0
  37. data/test/riel/text/ansi/ansi_palette_test.rb +65 -0
  38. data/test/riel/text/ansi/grey_palette_test.rb +39 -0
  39. data/test/riel/text/ansi/rgb_palette_test.rb +122 -0
  40. data/test/riel/text/highlightable_test.rb +27 -0
  41. data/test/riel/text/string_test.rb +48 -0
  42. data/test/riel/text_test.rb +1 -1
  43. metadata +37 -6
  44. 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
+ "0/. 1/. 2/. 3/. 4/. 5/. 6/. 7/. \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
+ "./0 ./1 ./2 ./3 ./4 ./5 ./6 ./7 \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
+ "0/. 1/. 2/. 3/. 4/. 5/. 6/. 7/. \n",
38
+ "\n",
39
+ "bg: 001\n",
40
+ "0/. 1/. 2/. 3/. 4/. 5/. 6/. 7/. \n",
41
+ "\n",
42
+ "bg: 002\n",
43
+ "0/. 1/. 2/. 3/. 4/. 5/. 6/. 7/. \n",
44
+ "\n",
45
+ "bg: 003\n",
46
+ "0/. 1/. 2/. 3/. 4/. 5/. 6/. 7/. \n",
47
+ "\n",
48
+ "bg: 004\n",
49
+ "0/. 1/. 2/. 3/. 4/. 5/. 6/. 7/. \n",
50
+ "\n",
51
+ "bg: 005\n",
52
+ "0/. 1/. 2/. 3/. 4/. 5/. 6/. 7/. \n",
53
+ "\n",
54
+ "bg: 006\n",
55
+ "0/. 1/. 2/. 3/. 4/. 5/. 6/. 7/. \n",
56
+ "\n",
57
+ "bg: 007\n",
58
+ "0/. 1/. 2/. 3/. 4/. 5/. 6/. 7/. \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
+ "232 233 234 235 236 237 \n",
17
+ "238 239 240 241 242 243 \n",
18
+ "244 245 246 247 248 249 \n",
19
+ "250 251 252 253 254 255 \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
+ "232 233 234 235 236 237 \n",
30
+ "238 239 240 241 242 243 \n",
31
+ "244 245 246 247 248 249 \n",
32
+ "250 251 252 253 254 255 \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
+ "000 001 002 003 004 005 \n",
17
+ "010 011 012 013 014 015 \n",
18
+ "020 021 022 023 024 025 \n",
19
+ "030 031 032 033 034 035 \n",
20
+ "040 041 042 043 044 045 \n",
21
+ "050 051 052 053 054 055 \n",
22
+ "\n",
23
+ "100 101 102 103 104 105 \n",
24
+ "110 111 112 113 114 115 \n",
25
+ "120 121 122 123 124 125 \n",
26
+ "130 131 132 133 134 135 \n",
27
+ "140 141 142 143 144 145 \n",
28
+ "150 151 152 153 154 155 \n",
29
+ "\n",
30
+ "200 201 202 203 204 205 \n",
31
+ "210 211 212 213 214 215 \n",
32
+ "220 221 222 223 224 225 \n",
33
+ "230 231 232 233 234 235 \n",
34
+ "240 241 242 243 244 245 \n",
35
+ "250 251 252 253 254 255 \n",
36
+ "\n",
37
+ "300 301 302 303 304 305 \n",
38
+ "310 311 312 313 314 315 \n",
39
+ "320 321 322 323 324 325 \n",
40
+ "330 331 332 333 334 335 \n",
41
+ "340 341 342 343 344 345 \n",
42
+ "350 351 352 353 354 355 \n",
43
+ "\n",
44
+ "400 401 402 403 404 405 \n",
45
+ "410 411 412 413 414 415 \n",
46
+ "420 421 422 423 424 425 \n",
47
+ "430 431 432 433 434 435 \n",
48
+ "440 441 442 443 444 445 \n",
49
+ "450 451 452 453 454 455 \n",
50
+ "\n",
51
+ "500 501 502 503 504 505 \n",
52
+ "510 511 512 513 514 515 \n",
53
+ "520 521 522 523 524 525 \n",
54
+ "530 531 532 533 534 535 \n",
55
+ "540 541 542 543 544 545 \n",
56
+ "550 551 552 553 554 555 \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
+ "000 001 002 003 004 005 \n",
67
+ "010 011 012 013 014 015 \n",
68
+ "020 021 022 023 024 025 \n",
69
+ "030 031 032 033 034 035 \n",
70
+ "040 041 042 043 044 045 \n",
71
+ "050 051 052 053 054 055 \n",
72
+ "\n",
73
+ "100 101 102 103 104 105 \n",
74
+ "110 111 112 113 114 115 \n",
75
+ "120 121 122 123 124 125 \n",
76
+ "130 131 132 133 134 135 \n",
77
+ "140 141 142 143 144 145 \n",
78
+ "150 151 152 153 154 155 \n",
79
+ "\n",
80
+ "200 201 202 203 204 205 \n",
81
+ "210 211 212 213 214 215 \n",
82
+ "220 221 222 223 224 225 \n",
83
+ "230 231 232 233 234 235 \n",
84
+ "240 241 242 243 244 245 \n",
85
+ "250 251 252 253 254 255 \n",
86
+ "\n",
87
+ "300 301 302 303 304 305 \n",
88
+ "310 311 312 313 314 315 \n",
89
+ "320 321 322 323 324 325 \n",
90
+ "330 331 332 333 334 335 \n",
91
+ "340 341 342 343 344 345 \n",
92
+ "350 351 352 353 354 355 \n",
93
+ "\n",
94
+ "400 401 402 403 404 405 \n",
95
+ "410 411 412 413 414 415 \n",
96
+ "420 421 422 423 424 425 \n",
97
+ "430 431 432 433 434 435 \n",
98
+ "440 441 442 443 444 445 \n",
99
+ "450 451 452 453 454 455 \n",
100
+ "\n",
101
+ "500 501 502 503 504 505 \n",
102
+ "510 511 512 513 514 515 \n",
103
+ "520 521 522 523 524 525 \n",
104
+ "530 531 532 533 534 535 \n",
105
+ "540 541 542 543 544 545 \n",
106
+ "550 551 552 553 554 555 \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
@@ -92,7 +92,7 @@ class TextTestCase < Test::Unit::TestCase
92
92
 
93
93
  str = "precision"
94
94
 
95
- # this tests that string.reverse does not mean ANSI reverse
95
+ # string.reverse does not mean ANSI reverse:
96
96
  assert_equal "noisicerp", str.reverse
97
97
  end
98
98
  end
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: 11
4
+ hash: 9
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 1
9
- - 12
10
- version: 1.1.12
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-11-23 00:00:00 -05:00
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