formatador 0.0.1 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/formatador.gemspec +2 -2
- data/lib/formatador.rb +56 -42
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.3
|
data/formatador.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{formatador}
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.3"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Wesley Beary"]
|
12
|
-
s.date = %q{2009-
|
12
|
+
s.date = %q{2009-12-03}
|
13
13
|
s.description = %q{STDOUT text formatting}
|
14
14
|
s.email = %q{wbeary@engineyard.com}
|
15
15
|
s.extra_rdoc_files = [
|
data/lib/formatador.rb
CHANGED
@@ -1,58 +1,72 @@
|
|
1
1
|
class Formatador
|
2
2
|
|
3
3
|
STYLES = {
|
4
|
-
:
|
5
|
-
:
|
6
|
-
:
|
7
|
-
:
|
8
|
-
:
|
9
|
-
:
|
10
|
-
:
|
11
|
-
:
|
12
|
-
:
|
13
|
-
:
|
14
|
-
:
|
15
|
-
:
|
16
|
-
:
|
17
|
-
:
|
18
|
-
:
|
19
|
-
:
|
20
|
-
:
|
21
|
-
:
|
22
|
-
:
|
23
|
-
:
|
24
|
-
:
|
25
|
-
:
|
26
|
-
:
|
27
|
-
:
|
28
|
-
:
|
29
|
-
:
|
4
|
+
:"\/" => "0",
|
5
|
+
:reset => "0",
|
6
|
+
:bold => "1",
|
7
|
+
:underline => "4",
|
8
|
+
:blink_slow => "5",
|
9
|
+
:blink_fast => "6",
|
10
|
+
:negative => "7", # invert color/color
|
11
|
+
:normal => "22",
|
12
|
+
:underline_none => "24",
|
13
|
+
:blink_off => "25",
|
14
|
+
:positive => "27", # revert color/color
|
15
|
+
:black => "30",
|
16
|
+
:red => "31",
|
17
|
+
:green => "32",
|
18
|
+
:yellow => "33",
|
19
|
+
:blue => "34",
|
20
|
+
:magenta => "35",
|
21
|
+
:purple => "35",
|
22
|
+
:cyan => "36",
|
23
|
+
:white => "37",
|
24
|
+
:_black_ => "40",
|
25
|
+
:_red_ => "41",
|
26
|
+
:_green_ => "42",
|
27
|
+
:_yellow_ => "43",
|
28
|
+
:_blue_ => "44",
|
29
|
+
:_magenta_ => "45",
|
30
|
+
:_purple_ => "45",
|
31
|
+
:_cyan_ => "46",
|
32
|
+
:_white_ => "47",
|
33
|
+
:light_black => "90",
|
34
|
+
:light_red => "91",
|
35
|
+
:light_green => "92",
|
36
|
+
:light_yellow => "93",
|
37
|
+
:light_blue => "94",
|
38
|
+
:light_magenta => "95",
|
39
|
+
:light_purple => "95",
|
40
|
+
:light_cyan => "96",
|
41
|
+
:_light_black_ => "100",
|
42
|
+
:_light_red_ => "101",
|
43
|
+
:_light_green_ => "102",
|
44
|
+
:_light_yellow_ => "103",
|
45
|
+
:_light_blue_ => "104",
|
46
|
+
:_light_magenta_ => "105",
|
47
|
+
:_light_purple_ => "105",
|
48
|
+
:_light_cyan_ => "106",
|
30
49
|
}
|
31
50
|
|
51
|
+
FORMAT_REGEX = /\[(#{ STYLES.keys.join('|') })\]/ix
|
52
|
+
INDENT_REGEX = /\[indent\]/ix
|
53
|
+
|
32
54
|
def initialize
|
33
55
|
@indent = 1
|
34
56
|
end
|
35
57
|
|
36
|
-
def display(string
|
37
|
-
print(format("#{
|
58
|
+
def display(string)
|
59
|
+
print(format("[indent]#{string}"))
|
38
60
|
end
|
39
61
|
|
40
|
-
def display_line(string
|
41
|
-
display(string
|
62
|
+
def display_line(string)
|
63
|
+
display(string)
|
42
64
|
print("\n")
|
43
65
|
end
|
44
66
|
|
45
|
-
def format(string
|
46
|
-
if STDOUT.tty?
|
47
|
-
|
48
|
-
for style in styles
|
49
|
-
formated << STYLES[style]
|
50
|
-
end
|
51
|
-
formated << string
|
52
|
-
if reset
|
53
|
-
formated << STYLES[:reset]
|
54
|
-
end
|
55
|
-
formated
|
67
|
+
def format(string)
|
68
|
+
if STDOUT.tty?
|
69
|
+
string.gsub(FORMAT_REGEX) { "\e[#{STYLES[$1.to_sym]}m" }.gsub(INDENT_REGEX) { indentation }
|
56
70
|
else
|
57
71
|
string
|
58
72
|
end
|
@@ -68,4 +82,4 @@ class Formatador
|
|
68
82
|
' ' * @indent
|
69
83
|
end
|
70
84
|
|
71
|
-
end
|
85
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: formatador
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Wesley Beary
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-12-03 00:00:00 -08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|