shiny 0.3.1 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +8 -2
- data/lib/shiny/ansi.rb +8 -13
- data/lib/shiny/helpers.rb +7 -1
- data/lib/shiny/html.rb +46 -48
- data/spec/shiny_spec.rb +9 -0
- metadata +3 -3
data/README.rdoc
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
=
|
1
|
+
= Shiny
|
2
2
|
|
3
3
|
Shiny extends the ruby core string class with two methods, ansi and html. These two are proxy methods to provide a bunch of color and text formating methods.
|
4
4
|
Over ansi there are the commen known ansi escape sequences available, bold, blink, underline and the whole colorful format things. The method html serves the same but in the html way, it makes the
|
@@ -10,6 +10,10 @@ standart w3c color names available and also a few other formats like overline, u
|
|
10
10
|
|
11
11
|
== Usage
|
12
12
|
|
13
|
+
First require it:
|
14
|
+
|
15
|
+
require 'shiny'
|
16
|
+
|
13
17
|
Some ansi color examples:
|
14
18
|
|
15
19
|
puts "magenta".ansi.magenta
|
@@ -41,7 +45,9 @@ Some other html effect examples:
|
|
41
45
|
"overline".html.overline
|
42
46
|
"line-through".html.line_through
|
43
47
|
|
44
|
-
Some terminal helper examples:
|
48
|
+
Some terminal helper examples:
|
49
|
+
|
50
|
+
include Shiny::Helpers
|
45
51
|
|
46
52
|
say("green day?", :color => :green)
|
47
53
|
say("fail!", :type => :error)
|
data/lib/shiny/ansi.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module Shiny
|
2
|
-
# The ansi class
|
3
|
-
# methods. To get an overview of all the
|
4
|
-
# at the CODES hash
|
2
|
+
# The ansi class serves a large list of color and a few format
|
3
|
+
# methods. To get an overview of all the generated methods, just look
|
4
|
+
# at the CODES hash.
|
5
5
|
#
|
6
6
|
# Some color examples:
|
7
7
|
#
|
@@ -53,7 +53,6 @@ module Shiny
|
|
53
53
|
:on_bright_magenta => "\e[105m",
|
54
54
|
:on_bright_cyan => "\e[106m",
|
55
55
|
:on_bright_white => "\e[107m",
|
56
|
-
:reset => "\e[0m",
|
57
56
|
:bold => "\e[1m",
|
58
57
|
:underline => "\e[4m",
|
59
58
|
:negative => "\e[7m",
|
@@ -69,16 +68,12 @@ module Shiny
|
|
69
68
|
# Generate color instance methods
|
70
69
|
# See CODES for a list of the created methods
|
71
70
|
CODES.each do |code, value|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
@string = "#{value}" + @string + "#{reset}"
|
77
|
-
self
|
78
|
-
end
|
79
|
-
DEF
|
71
|
+
define_method code do
|
72
|
+
@string = "#{value}#{@string}\e[0m"
|
73
|
+
self
|
74
|
+
end
|
80
75
|
end
|
81
|
-
|
76
|
+
|
82
77
|
# Remove all ansi escape sequences from the string
|
83
78
|
#
|
84
79
|
# @return [String] from ansi escape sequences cleaned
|
data/lib/shiny/helpers.rb
CHANGED
@@ -51,7 +51,13 @@ module Shiny
|
|
51
51
|
# @param [String] sign ('#') The character around the message
|
52
52
|
def wrap(message, sign="#")
|
53
53
|
sign = sign[0] if sign.length > 1
|
54
|
-
|
54
|
+
|
55
|
+
to_ignore = 0
|
56
|
+
message.gsub(/\e\[[0-9]+m/) do |m|
|
57
|
+
to_ignore += m.length
|
58
|
+
end
|
59
|
+
|
60
|
+
around = sign * ((message.length - to_ignore) + 4) + "\n"
|
55
61
|
|
56
62
|
output = ""
|
57
63
|
output << around
|
data/lib/shiny/html.rb
CHANGED
@@ -2,46 +2,46 @@ module Shiny
|
|
2
2
|
class HTML < Basic
|
3
3
|
# List of the 17 w3c supported color names
|
4
4
|
# @see http://www.w3.org/TR/CSS21/syndata.html#value-def-color
|
5
|
-
|
6
|
-
:black => '
|
7
|
-
:silver => '
|
8
|
-
:gray => '
|
9
|
-
:white => '
|
10
|
-
:maroon => '
|
11
|
-
:red => '
|
12
|
-
:purple => '
|
13
|
-
:fuchsia => '
|
14
|
-
:green => '
|
15
|
-
:lime => '
|
16
|
-
:olive => '
|
17
|
-
:yellow => '
|
18
|
-
:navy => '
|
19
|
-
:blue => '
|
20
|
-
:teal => '
|
21
|
-
:aqua => '
|
22
|
-
:orange => '
|
23
|
-
:on_black => '
|
24
|
-
:on_silver => '
|
25
|
-
:on_gray => '
|
26
|
-
:on_white => '
|
27
|
-
:on_maroon => '
|
28
|
-
:on_red => '
|
29
|
-
:on_purple => '
|
30
|
-
:on_fuchsia => '
|
31
|
-
:on_green => '
|
32
|
-
:on_lime => '
|
33
|
-
:on_olive => '
|
34
|
-
:on_yellow => '
|
35
|
-
:on_navy => '
|
36
|
-
:on_blue => '
|
37
|
-
:on_teal => '
|
38
|
-
:on_aqua => '
|
39
|
-
:on_orange => '
|
40
|
-
:bold => '
|
41
|
-
:underline => '
|
42
|
-
:overline => '
|
43
|
-
:line_through => '
|
44
|
-
:blink => '
|
5
|
+
STYLES = {
|
6
|
+
:black => 'color: black',
|
7
|
+
:silver => 'color: silver',
|
8
|
+
:gray => 'color: gray',
|
9
|
+
:white => 'color: white',
|
10
|
+
:maroon => 'color: maroon',
|
11
|
+
:red => 'color: red',
|
12
|
+
:purple => 'color: purple',
|
13
|
+
:fuchsia => 'color: fuchsia',
|
14
|
+
:green => 'color: green',
|
15
|
+
:lime => 'color: lime',
|
16
|
+
:olive => 'color: olive',
|
17
|
+
:yellow => 'color: yellow',
|
18
|
+
:navy => 'color: navy',
|
19
|
+
:blue => 'color: blue',
|
20
|
+
:teal => 'color: teal',
|
21
|
+
:aqua => 'color: aqua',
|
22
|
+
:orange => 'color: orange',
|
23
|
+
:on_black => 'background-color: black',
|
24
|
+
:on_silver => 'background-color: silver',
|
25
|
+
:on_gray => 'background-color: gray',
|
26
|
+
:on_white => 'background-color: white',
|
27
|
+
:on_maroon => 'background-color: maroon',
|
28
|
+
:on_red => 'background-color: red',
|
29
|
+
:on_purple => 'background-color: purple',
|
30
|
+
:on_fuchsia => 'background-color: fuchsia',
|
31
|
+
:on_green => 'background-color: green',
|
32
|
+
:on_lime => 'background-color: lime',
|
33
|
+
:on_olive => 'background-color: olive',
|
34
|
+
:on_yellow => 'background-color: yellow',
|
35
|
+
:on_navy => 'background-color: navy',
|
36
|
+
:on_blue => 'background-color: blue',
|
37
|
+
:on_teal => 'background-color: teal',
|
38
|
+
:on_aqua => 'background-color: aqua',
|
39
|
+
:on_orange => 'background-color: orange',
|
40
|
+
:bold => 'font-weight: bold',
|
41
|
+
:underline => 'text-decoration: underline',
|
42
|
+
:overline => 'text-decoration: overline',
|
43
|
+
:line_through => 'text-decoration: line-through',
|
44
|
+
:blink => 'text-decoration: blink'
|
45
45
|
}
|
46
46
|
|
47
47
|
# HTML span begin tag
|
@@ -51,14 +51,12 @@ module Shiny
|
|
51
51
|
SPAN_END = "</span>"
|
52
52
|
|
53
53
|
# Generate html format instance methods
|
54
|
-
# See
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
end
|
61
|
-
DEF
|
54
|
+
# See STYLES for a list of created methods
|
55
|
+
STYLES.each do |name, value|
|
56
|
+
define_method name do
|
57
|
+
@string = "<span style=\"#{value};\">#{@string}</span>"
|
58
|
+
self
|
59
|
+
end
|
62
60
|
end
|
63
61
|
|
64
62
|
# Remove all html span format tags
|
data/spec/shiny_spec.rb
CHANGED
@@ -57,6 +57,15 @@ describe Shiny do
|
|
57
57
|
$stdout.should_receive(:print).with(output)
|
58
58
|
wrap("Hello I'm wrapped", "*")
|
59
59
|
end
|
60
|
+
|
61
|
+
it "should not count escape sequences as characters" do
|
62
|
+
output = "###########\n"
|
63
|
+
output += "# \e[31mI'm red\e[0m #\n"
|
64
|
+
output += "###########\n"
|
65
|
+
|
66
|
+
$stdout.should_receive(:print).with(output)
|
67
|
+
wrap("\e[31mI'm red\e[0m")
|
68
|
+
end
|
60
69
|
end
|
61
70
|
|
62
71
|
describe "#log" do
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 3
|
8
|
-
-
|
9
|
-
version: 0.3.
|
8
|
+
- 2
|
9
|
+
version: 0.3.2
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Samuel Tonini
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-
|
17
|
+
date: 2010-12-29 00:00:00 +01:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|