jcf-ansi_color 0.4.1 → 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION.yml +1 -1
- data/lib/ansi_color.rb +2 -21
- data/lib/ansi_color/std_out.rb +25 -0
- data/spec/ansi_color/std_out_spec.rb +86 -0
- data/spec/ansi_color_spec.rb +0 -85
- metadata +4 -1
data/VERSION.yml
CHANGED
data/lib/ansi_color.rb
CHANGED
@@ -2,6 +2,7 @@ $:.push File.dirname(__FILE__)
|
|
2
2
|
require "ansi_color/helpers"
|
3
3
|
require "ansi_color/effects"
|
4
4
|
require "ansi_color/rainbow"
|
5
|
+
require "ansi_color/std_out"
|
5
6
|
|
6
7
|
module AnsiColor
|
7
8
|
class InvalidColorName < StandardError; end
|
@@ -50,28 +51,8 @@ module AnsiColor
|
|
50
51
|
EFFECTS.each do |name, code|
|
51
52
|
define_method(name) { code }
|
52
53
|
end
|
53
|
-
end
|
54
54
|
|
55
|
-
|
56
|
-
if args.last.is_a?(Hash)
|
57
|
-
options = args.pop
|
58
|
-
open_tag = Helpers::build_open_tag(options)
|
59
|
-
string = args.map { |arg| arg.to_s }.join
|
60
|
-
super(open_tag + string + Helpers::reset)
|
61
|
-
else
|
62
|
-
super(*args)
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
def self.puts(*args)
|
67
|
-
if args.last.is_a?(Hash)
|
68
|
-
options = args.pop
|
69
|
-
open_tag = Helpers::build_open_tag(options)
|
70
|
-
string = args.map { |arg| arg.to_s }.join("\n")
|
71
|
-
super(open_tag + string + Helpers::reset)
|
72
|
-
else
|
73
|
-
super(*args)
|
74
|
-
end
|
55
|
+
include StdOut
|
75
56
|
end
|
76
57
|
end
|
77
58
|
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module AnsiColor
|
2
|
+
module StdOut
|
3
|
+
def print(*args)
|
4
|
+
if args.last.is_a?(Hash)
|
5
|
+
options = args.pop
|
6
|
+
open_tag = Helpers::build_open_tag(options)
|
7
|
+
string = args.map { |arg| arg.to_s }.join
|
8
|
+
super(open_tag + string + Helpers::reset)
|
9
|
+
else
|
10
|
+
super(*args)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def puts(*args)
|
15
|
+
if args.last.is_a?(Hash)
|
16
|
+
options = args.pop
|
17
|
+
open_tag = Helpers::build_open_tag(options)
|
18
|
+
string = args.map { |arg| arg.to_s }.join("\n")
|
19
|
+
super(open_tag + string + Helpers::reset)
|
20
|
+
else
|
21
|
+
super(*args)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,86 @@
|
|
1
|
+
module AnsiColor
|
2
|
+
describe "print" do
|
3
|
+
it "print the original string with no options" do
|
4
|
+
capture_stdout do |stdout|
|
5
|
+
AnsiColor.print('james')
|
6
|
+
stdout.string.should == 'james'
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
it "print non string objects with no options" do
|
11
|
+
capture_stdout do |stdout|
|
12
|
+
AnsiColor.print(234)
|
13
|
+
stdout.string.should == '234'
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
it "red and bold on non string object" do
|
18
|
+
capture_stdout do |stdout|
|
19
|
+
AnsiColor.print(42, :color => :red, :effects => :bold)
|
20
|
+
stdout.string.should == "#{E}31;1m42#{E}0m"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
it "print many args with no options" do
|
25
|
+
capture_stdout do |stdout|
|
26
|
+
AnsiColor.print(1, ' string ', 2)
|
27
|
+
stdout.string.should == "1 string 2"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
it "print many args in red and bold" do
|
32
|
+
capture_stdout do |stdout|
|
33
|
+
AnsiColor.print(1, ' string ', 2, :color => :red, :effects => :bold)
|
34
|
+
stdout.string.should == "#{E}31;1m1 string 2#{E}0m"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
it "red and bold" do
|
39
|
+
capture_stdout do |stdout|
|
40
|
+
AnsiColor.print('james', :color => :red, :effects => :bold)
|
41
|
+
stdout.string.should == "#{E}31;1mjames#{E}0m"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
it "blue on white blinking" do
|
46
|
+
capture_stdout do |stdout|
|
47
|
+
AnsiColor.print('james', :color => :blue,
|
48
|
+
:background => :white,
|
49
|
+
:effects => :blink)
|
50
|
+
stdout.string.should == "#{E}34;47;5mjames#{E}0m"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
describe "puts" do
|
56
|
+
it "print the original string with no options" do
|
57
|
+
capture_stdout do |stdout|
|
58
|
+
AnsiColor.puts('james')
|
59
|
+
stdout.string.should == "james\n"
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
it "print some number with no options" do
|
64
|
+
capture_stdout do |stdout|
|
65
|
+
AnsiColor.puts(243)
|
66
|
+
stdout.string.should == "243\n"
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
it "red and bold" do
|
71
|
+
capture_stdout do |stdout|
|
72
|
+
AnsiColor.puts('james', :color => :red, :effects => :bold)
|
73
|
+
stdout.string.should == "#{E}31;1mjames#{E}0m\n"
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
it "blue on white blinking" do
|
78
|
+
capture_stdout do |stdout|
|
79
|
+
AnsiColor.puts('james', :color => :blue,
|
80
|
+
:background => :white,
|
81
|
+
:effects => :blink)
|
82
|
+
stdout.string.should == "#{E}34;47;5mjames#{E}0m\n"
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
data/spec/ansi_color_spec.rb
CHANGED
@@ -19,90 +19,5 @@ describe AnsiColor do
|
|
19
19
|
AnsiColor.send("#{name}").should == code
|
20
20
|
end
|
21
21
|
end
|
22
|
-
|
23
|
-
describe "print" do
|
24
|
-
it "print the original string with no options" do
|
25
|
-
capture_stdout do |stdout|
|
26
|
-
AnsiColor.print('james')
|
27
|
-
stdout.string.should == 'james'
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
it "print non string objects with no options" do
|
32
|
-
capture_stdout do |stdout|
|
33
|
-
AnsiColor.print(234)
|
34
|
-
stdout.string.should == '234'
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
it "red and bold on non string object" do
|
39
|
-
capture_stdout do |stdout|
|
40
|
-
AnsiColor.print(42, :color => :red, :effects => :bold)
|
41
|
-
stdout.string.should == "#{E}31;1m42#{E}0m"
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
it "print many args with no options" do
|
46
|
-
capture_stdout do |stdout|
|
47
|
-
AnsiColor.print(1, ' string ', 2)
|
48
|
-
stdout.string.should == "1 string 2"
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
it "print many args in red and bold" do
|
53
|
-
capture_stdout do |stdout|
|
54
|
-
AnsiColor.print(1, ' string ', 2, :color => :red, :effects => :bold)
|
55
|
-
stdout.string.should == "#{E}31;1m1 string 2#{E}0m"
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
it "red and bold" do
|
60
|
-
capture_stdout do |stdout|
|
61
|
-
AnsiColor.print('james', :color => :red, :effects => :bold)
|
62
|
-
stdout.string.should == "#{E}31;1mjames#{E}0m"
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
it "blue on white blinking" do
|
67
|
-
capture_stdout do |stdout|
|
68
|
-
AnsiColor.print('james', :color => :blue,
|
69
|
-
:background => :white,
|
70
|
-
:effects => :blink)
|
71
|
-
stdout.string.should == "#{E}34;47;5mjames#{E}0m"
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
describe "puts" do
|
77
|
-
it "print the original string with no options" do
|
78
|
-
capture_stdout do |stdout|
|
79
|
-
AnsiColor.puts('james')
|
80
|
-
stdout.string.should == "james\n"
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
it "print some number with no options" do
|
85
|
-
capture_stdout do |stdout|
|
86
|
-
AnsiColor.puts(243)
|
87
|
-
stdout.string.should == "243\n"
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
it "red and bold" do
|
92
|
-
capture_stdout do |stdout|
|
93
|
-
AnsiColor.puts('james', :color => :red, :effects => :bold)
|
94
|
-
stdout.string.should == "#{E}31;1mjames#{E}0m\n"
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
it "blue on white blinking" do
|
99
|
-
capture_stdout do |stdout|
|
100
|
-
AnsiColor.puts('james', :color => :blue,
|
101
|
-
:background => :white,
|
102
|
-
:effects => :blink)
|
103
|
-
stdout.string.should == "#{E}34;47;5mjames#{E}0m\n"
|
104
|
-
end
|
105
|
-
end
|
106
|
-
end
|
107
22
|
end
|
108
23
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jcf-ansi_color
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Conroy-Finn
|
@@ -31,10 +31,12 @@ files:
|
|
31
31
|
- lib/ansi_color/effects.rb
|
32
32
|
- lib/ansi_color/helpers.rb
|
33
33
|
- lib/ansi_color/rainbow.rb
|
34
|
+
- lib/ansi_color/std_out.rb
|
34
35
|
- lib/ansi_color/string.rb
|
35
36
|
- spec/ansi_color/effects_spec.rb
|
36
37
|
- spec/ansi_color/helpers_spec.rb
|
37
38
|
- spec/ansi_color/rainbow_spec.rb
|
39
|
+
- spec/ansi_color/std_out_spec.rb
|
38
40
|
- spec/ansi_color/string_spec.rb
|
39
41
|
- spec/ansi_color_spec.rb
|
40
42
|
- spec/spec.opts
|
@@ -69,6 +71,7 @@ test_files:
|
|
69
71
|
- spec/ansi_color/effects_spec.rb
|
70
72
|
- spec/ansi_color/helpers_spec.rb
|
71
73
|
- spec/ansi_color/rainbow_spec.rb
|
74
|
+
- spec/ansi_color/std_out_spec.rb
|
72
75
|
- spec/ansi_color/string_spec.rb
|
73
76
|
- spec/ansi_color_spec.rb
|
74
77
|
- spec/spec_helper.rb
|