Hokkaido 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/Hokkaido/version.rb +1 -1
- data/lib/term/ansicolor.rb +89 -114
- metadata +1 -1
data/lib/Hokkaido/version.rb
CHANGED
data/lib/term/ansicolor.rb
CHANGED
@@ -1,127 +1,102 @@
|
|
1
|
-
|
2
|
-
app.files << File.expand_path(File.join(File.dirname(__FILE__),'ansicolor.rb'))
|
3
|
-
end
|
4
|
-
module Hokkaido
|
5
|
-
module Term
|
6
|
-
# The ANSIColor module can be used for namespacing and mixed into your own
|
7
|
-
# classes.
|
8
|
-
module ANSIColor
|
9
|
-
# :stopdoc:
|
10
|
-
ATTRIBUTES = [
|
11
|
-
[ :clear , 0 ],
|
12
|
-
[ :reset , 0 ], # synonym for :clear
|
13
|
-
[ :bold , 1 ],
|
14
|
-
[ :dark , 2 ],
|
15
|
-
[ :italic , 3 ], # not widely implemented
|
16
|
-
[ :underline , 4 ],
|
17
|
-
[ :underscore , 4 ], # synonym for :underline
|
18
|
-
[ :blink , 5 ],
|
19
|
-
[ :rapid_blink , 6 ], # not widely implemented
|
20
|
-
[ :negative , 7 ], # no reverse because of String#reverse
|
21
|
-
[ :concealed , 8 ],
|
22
|
-
[ :strikethrough, 9 ], # not widely implemented
|
23
|
-
[ :black , 30 ],
|
24
|
-
[ :red , 31 ],
|
25
|
-
[ :green , 32 ],
|
26
|
-
[ :yellow , 33 ],
|
27
|
-
[ :blue , 34 ],
|
28
|
-
[ :magenta , 35 ],
|
29
|
-
[ :cyan , 36 ],
|
30
|
-
[ :white , 37 ],
|
31
|
-
[ :on_black , 40 ],
|
32
|
-
[ :on_red , 41 ],
|
33
|
-
[ :on_green , 42 ],
|
34
|
-
[ :on_yellow , 43 ],
|
35
|
-
[ :on_blue , 44 ],
|
36
|
-
[ :on_magenta , 45 ],
|
37
|
-
[ :on_cyan , 46 ],
|
38
|
-
[ :on_white , 47 ],
|
39
|
-
]
|
40
|
-
|
41
|
-
ATTRIBUTE_NAMES = ATTRIBUTES.transpose.first
|
42
|
-
# :startdoc:
|
43
|
-
|
44
|
-
# Returns true, if the coloring function of this module
|
45
|
-
# is switched on, false otherwise.
|
46
|
-
def self.coloring?
|
47
|
-
@coloring
|
48
|
-
end
|
49
|
-
|
50
|
-
# Turns the coloring on or off globally, so you can easily do
|
51
|
-
# this for example:
|
52
|
-
# Cucumber::Term::ANSIColor::coloring = STDOUT.isatty
|
53
|
-
def self.coloring=(val)
|
54
|
-
@coloring = val
|
55
|
-
end
|
56
|
-
self.coloring = true
|
1
|
+
#require 'term/ansicolor/version'
|
57
2
|
|
58
|
-
|
59
|
-
#
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
3
|
+
module Term
|
4
|
+
# The ANSIColor module can be used for namespacing and mixed into your own
|
5
|
+
# classes.
|
6
|
+
module ANSIColor
|
7
|
+
# :stopdoc:
|
8
|
+
ATTRIBUTES = [
|
9
|
+
[ :clear , 0 ],
|
10
|
+
[ :reset , 0 ], # synonym for :clear
|
11
|
+
[ :bold , 1 ],
|
12
|
+
[ :dark , 2 ],
|
13
|
+
[ :italic , 3 ], # not widely implemented
|
14
|
+
[ :underline , 4 ],
|
15
|
+
[ :underscore , 4 ], # synonym for :underline
|
16
|
+
[ :blink , 5 ],
|
17
|
+
[ :rapid_blink , 6 ], # not widely implemented
|
18
|
+
[ :negative , 7 ], # no reverse because of String#reverse
|
19
|
+
[ :concealed , 8 ],
|
20
|
+
[ :strikethrough, 9 ], # not widely implemented
|
21
|
+
[ :black , 30 ],
|
22
|
+
[ :red , 31 ],
|
23
|
+
[ :green , 32 ],
|
24
|
+
[ :yellow , 33 ],
|
25
|
+
[ :blue , 34 ],
|
26
|
+
[ :magenta , 35 ],
|
27
|
+
[ :cyan , 36 ],
|
28
|
+
[ :white , 37 ],
|
29
|
+
[ :on_black , 40 ],
|
30
|
+
[ :on_red , 41 ],
|
31
|
+
[ :on_green , 42 ],
|
32
|
+
[ :on_yellow , 43 ],
|
33
|
+
[ :on_blue , 44 ],
|
34
|
+
[ :on_magenta , 45 ],
|
35
|
+
[ :on_cyan , 46 ],
|
36
|
+
[ :on_white , 47 ],
|
37
|
+
]
|
77
38
|
|
78
|
-
|
79
|
-
|
80
|
-
COLORED_REGEXP = /\e\[(?:[34][0-7]|[0-9])?m/
|
39
|
+
ATTRIBUTE_NAMES = ATTRIBUTES.transpose.first
|
40
|
+
# :startdoc:
|
81
41
|
|
42
|
+
# Returns true, if the coloring function of this module
|
43
|
+
# is switched on, false otherwise.
|
44
|
+
def self.coloring?
|
45
|
+
@coloring
|
46
|
+
end
|
82
47
|
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
48
|
+
# Turns the coloring on or off globally, so you can easily do
|
49
|
+
# this for example:
|
50
|
+
# Term::ANSIColor::coloring = STDOUT.isatty
|
51
|
+
def self.coloring=(val)
|
52
|
+
@coloring = val
|
53
|
+
end
|
54
|
+
self.coloring = true
|
89
55
|
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
56
|
+
ATTRIBUTES.each do |c, v|
|
57
|
+
eval %Q{
|
58
|
+
def #{c}(string = nil)
|
59
|
+
result = ''
|
60
|
+
result << "\e[#{v}m" if Term::ANSIColor.coloring?
|
61
|
+
if block_given?
|
62
|
+
result << yield
|
63
|
+
elsif string
|
64
|
+
result << string
|
65
|
+
elsif respond_to?(:to_str)
|
66
|
+
result << to_str
|
67
|
+
else
|
68
|
+
return result #only switch on
|
69
|
+
end
|
70
|
+
result << "\e[0m" if Term::ANSIColor.coloring?
|
71
|
+
result
|
72
|
+
end
|
73
|
+
}
|
74
|
+
end
|
103
75
|
|
104
|
-
|
76
|
+
# Regular expression that is used to scan for ANSI-sequences while
|
77
|
+
# uncoloring strings.
|
78
|
+
COLORED_REGEXP = /\e\[(?:[34][0-7]|[0-9])?m/
|
105
79
|
|
106
|
-
|
107
|
-
|
108
|
-
|
80
|
+
# Returns an uncolored version of the string, that is all
|
81
|
+
# ANSI-sequences are stripped from the string.
|
82
|
+
def uncolored(string = nil) # :yields:
|
83
|
+
if block_given?
|
84
|
+
yield.gsub(COLORED_REGEXP, '')
|
85
|
+
elsif string
|
86
|
+
string.gsub(COLORED_REGEXP, '')
|
87
|
+
elsif respond_to?(:to_str)
|
88
|
+
to_str.gsub(COLORED_REGEXP, '')
|
89
|
+
else
|
90
|
+
''
|
109
91
|
end
|
110
|
-
|
92
|
+
end
|
111
93
|
|
112
|
-
|
94
|
+
module_function
|
113
95
|
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
version[0] >= 1 && version[1] > 8
|
118
|
-
end
|
96
|
+
# Returns an array of all Term::ANSIColor attributes as symbols.
|
97
|
+
def attributes
|
98
|
+
ATTRIBUTE_NAMES
|
119
99
|
end
|
120
|
-
|
121
|
-
end
|
122
|
-
|
123
|
-
class String
|
124
|
-
def colorize(sym)
|
125
|
-
Hokkaido::Term::ANSIColor.send(sym, self)
|
100
|
+
extend self
|
126
101
|
end
|
127
102
|
end
|