cli-colorize 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/cli-colorize.rb +34 -2
- metadata +5 -13
data/lib/cli-colorize.rb
CHANGED
@@ -99,6 +99,31 @@ module CLIColorize
|
|
99
99
|
STDOUT.print CLIColorize.colorize(text, color)
|
100
100
|
end
|
101
101
|
|
102
|
+
# Call STDOUT.puts with the colorized text if STDOUT is a tty device.
|
103
|
+
# (If STDOUT has been redirected to a file, it will be a block device,
|
104
|
+
# not a tty device, and we wouldn't want the ANSI codes inserted.
|
105
|
+
def CLIColorize.puts_colorized_if_tty(text, color=nil)
|
106
|
+
STDOUT.puts(STDOUT.isatty ? CLIColorize.colorize(text, color) : text)
|
107
|
+
end
|
108
|
+
|
109
|
+
# instance method delegating to class method, see CLIColorize.puts_if_tty
|
110
|
+
def puts_colorized_if_tty(text, color=nil)
|
111
|
+
CLIColorize.puts_colorized_if_tty(text, color)
|
112
|
+
end
|
113
|
+
|
114
|
+
# Call STDOUT.print with the colorized text if STDOUT is a tty device.
|
115
|
+
# (If STDOUT has been redirected to a file, it will be a block device,
|
116
|
+
# not a tty device, and we wouldn't want the ANSI codes inserted.
|
117
|
+
def CLIColorize.print_colorized_if_tty(text, color=nil)
|
118
|
+
STDOUT.puts(STDOUT.isatty ? CLIColorize.colorize(text, color) : text)
|
119
|
+
end
|
120
|
+
|
121
|
+
# instance method delegating to class method, see CLIColorize.print_if_tty
|
122
|
+
def print_colorized_if_tty(text, color=nil)
|
123
|
+
CLIColorize.print_colorized_if_tty(text, color)
|
124
|
+
end
|
125
|
+
|
126
|
+
|
102
127
|
# Use safe_colorize in conjunction with CLIColorize.off and CLIColorize.on to conditionally
|
103
128
|
# determine whether or not output will be given the control characters for colorization.
|
104
129
|
# This is designed to work with a command-line switch to the script that uses this module.
|
@@ -116,11 +141,13 @@ module CLIColorize
|
|
116
141
|
def safe_colorize_active
|
117
142
|
CLIColorize.on
|
118
143
|
end
|
144
|
+
alias safe_colorize_activate safe_colorize_active
|
119
145
|
|
120
146
|
# Makes the safe_colorize method return text without colorization control codes.
|
121
147
|
def safe_colorize_deactive
|
122
148
|
CLIColorize.off
|
123
149
|
end
|
150
|
+
alias safe_colorize_deactivate safe_colorize_deactive
|
124
151
|
|
125
152
|
# Call STDOUT.puts with the colorized text.
|
126
153
|
def CLIColorize.safe_puts(text, color=nil)
|
@@ -151,9 +178,14 @@ module CLIColorize
|
|
151
178
|
CLIColorize.default_color=(color)
|
152
179
|
end
|
153
180
|
|
181
|
+
def CLIColorize.on?
|
182
|
+
! @@off
|
183
|
+
end
|
184
|
+
|
154
185
|
private
|
155
186
|
# Call CLIColorize.off to turn off colorizing (for instance to make the output safe
|
156
187
|
# for evaluation or for output sometimes not headed to the terminal).
|
157
|
-
def CLIColorize.off; @@off = true;
|
158
|
-
def CLIColorize.on; @@off = false;
|
188
|
+
def CLIColorize.off; @@off = true; nil; end
|
189
|
+
def CLIColorize.on; @@off = false; nil; end
|
190
|
+
|
159
191
|
end
|
metadata
CHANGED
@@ -1,12 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cli-colorize
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
prerelease:
|
5
|
-
|
6
|
-
- 1
|
7
|
-
- 0
|
8
|
-
- 0
|
9
|
-
version: 1.0.0
|
4
|
+
prerelease:
|
5
|
+
version: 1.1.0
|
10
6
|
platform: ruby
|
11
7
|
authors:
|
12
8
|
- Chris St. John
|
@@ -14,7 +10,7 @@ autorequire:
|
|
14
10
|
bindir: bin
|
15
11
|
cert_chain: []
|
16
12
|
|
17
|
-
date: 2011-
|
13
|
+
date: 2011-05-31 00:00:00 -04:00
|
18
14
|
default_executable:
|
19
15
|
dependencies: []
|
20
16
|
|
@@ -42,23 +38,19 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
42
38
|
requirements:
|
43
39
|
- - ">="
|
44
40
|
- !ruby/object:Gem::Version
|
45
|
-
segments:
|
46
|
-
- 0
|
47
41
|
version: "0"
|
48
42
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
49
43
|
none: false
|
50
44
|
requirements:
|
51
45
|
- - ">="
|
52
46
|
- !ruby/object:Gem::Version
|
53
|
-
segments:
|
54
|
-
- 0
|
55
47
|
version: "0"
|
56
48
|
requirements: []
|
57
49
|
|
58
50
|
rubyforge_project:
|
59
|
-
rubygems_version: 1.
|
51
|
+
rubygems_version: 1.5.2
|
60
52
|
signing_key:
|
61
53
|
specification_version: 3
|
62
|
-
summary: command-line interface colorization library
|
54
|
+
summary: A command-line interface colorization library.
|
63
55
|
test_files: []
|
64
56
|
|