shiny 0.1.1 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.rdoc CHANGED
@@ -1,26 +1,45 @@
1
1
  = shiny
2
2
 
3
- Shiny gives you some common ansi escape sequences, which are available over a defined proxy method called 'shell', in the core ruby String class.
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
+ 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
5
+ standart w3c color names available and also a few other formats like overline, underline, blink etc.
4
6
 
5
- Some colors examples:
7
+ == Installation
6
8
 
7
- puts "magenta".shell.magenta
8
- puts "bold blue".shell.bold.blue
9
- puts "yellow on cyan".shell.yellow.on_cyan
10
- puts "bright blue on green".shell.bright_blue.on_green
11
- puts "red on bright blue".shell.red.on_bright_blue
9
+ $ gem install shiny
12
10
 
13
- Some other effect examples:
11
+ == Usage
14
12
 
15
- puts "bold".shell.bold
16
- puts "oh! i'm blinking".shell.blink
17
- puts "nice and underlined".shell.underline
18
- puts "other side, please".shell.negative
13
+ Some ansi color examples:
19
14
 
20
- Helpers to list available colors and effect methods (execute under terminal to see it in action)
15
+ puts "magenta".ansi.magenta
16
+ puts "bold blue".ansi.bold.blue
17
+ puts "yellow on cyan".ansi.yellow.on_cyan
18
+ puts "bright blue on green".ansi.bright_blue.on_green
19
+ puts "red on bright blue".ansi.red.on_bright_blue
21
20
 
22
- Shiny.show_colors
23
- Shiny.show_effects
21
+ Some other ansi effect examples:
22
+
23
+ puts "bold".ansi.bold
24
+ puts "oh! i'm blinking".ansi.blink
25
+ puts "nice and underlined".ansi.underline
26
+ puts "other side, please".ansi.negative
27
+
28
+ Some html color examples: (the html formats should be used in the browser ;)
29
+
30
+ "orange".html.orange
31
+ "bold red".html.bold.red
32
+ "yellow on olive".html.yellow.on_olive
33
+ "blue on teal".html.blue.on_teal
34
+ "fuchsia".html.fuchsia
35
+
36
+ Some other html effect examples:
37
+
38
+ "bold".html.bold
39
+ "oh! i'm blinking".html.blink
40
+ "nice and underlined".html.underline
41
+ "overline".html.overline
42
+ "line-through".html.line_through
24
43
 
25
44
  == Note on Patches/Pull Requests
26
45
 
data/lib/shiny.rb CHANGED
@@ -1,76 +1,4 @@
1
- require 'shiny/ansi'
1
+ require 'shiny/core_ext/string'
2
2
 
3
- class Shiny
4
-
5
- # Shiny gives you some common ansi escape sequences, which
6
- # are available over a defined proxy method called 'shell', in
7
- # the core ruby String class.
8
- #
9
- # Some colors examples:
10
- #
11
- # puts "magenta".shell.magenta
12
- # puts "bold blue".shell.bold.blue
13
- # puts "yellow on cyan".shell.yellow.on_cyan
14
- # puts "bright blue on green".shell.bright_blue.on_green
15
- # puts "red on bright blue".shell.red.on_bright_blue
16
- #
17
- # Some other effect examples:
18
- #
19
- # puts "bold".shell.bold
20
- # puts "oh! i'm blinking".shell.blink
21
- # puts "nice and underlined".shell.underline
22
- # puts "other side, please".shell.negative
23
- def initialize(string)
24
- @string = string
25
- end
26
-
27
- ANSI::ESCAPE_SEQUENCES.each do |code, value|
28
- next if code == 'reset'
29
- reset = ANSI::ESCAPE_SEQUENCES['reset']
30
- class_eval <<-DEF
31
- def #{code}
32
- @string = "#{value}" + @string + "#{reset}"
33
- Shiny.new(@string)
34
- end
35
- DEF
36
- end
37
-
38
- def to_s
39
- @string
40
- end
41
-
42
- def blank
43
- @string.gsub(/\e\[[0-9]+m/,'')
44
- end
45
-
46
- # some helpers to see how shiny the ansi sequences are
47
- class << self
48
- def colors
49
- ANSI::COLORS
50
- end
51
-
52
- def effects
53
- ANSI::EFFECTS
54
- end
55
-
56
- def show_colors
57
- ANSI::COLORS.each do |color|
58
- [color, "bright_#{color}", "on_#{color}", "on_bright_#{color}"].each do |code|
59
- $stdout.puts ANSI::ESCAPE_SEQUENCES[code] + code + ANSI::ESCAPE_SEQUENCES['reset']
60
- end
61
- end
62
- $stdout.flush
63
- end
64
-
65
- def show_effects
66
- ANSI::EFFECTS.each do |code|
67
- $stdout.puts ANSI::ESCAPE_SEQUENCES[code] + code + ANSI::ESCAPE_SEQUENCES['reset']
68
- end
69
- $stdout.flush
70
- end
71
- end
72
- end
73
-
74
- class String
75
- def shell; Shiny.new(self); end
3
+ module Shiny
76
4
  end
data/lib/shiny/ansi.rb CHANGED
@@ -1,5 +1,26 @@
1
- module ANSI
2
- ESCAPE_SEQUENCES = {
1
+ module Shiny
2
+ # Shiny::ANSI gives you some common ansi escape sequences, which
3
+ # are available over a defined proxy method called 'shell', in
4
+ # the core ruby String class.
5
+ #
6
+ # Some colors examples:
7
+ #
8
+ # puts "magenta".shell.magenta
9
+ # puts "bold blue".shell.bold.blue
10
+ # puts "yellow on cyan".shell.yellow.on_cyan
11
+ # puts "bright blue on green".shell.bright_blue.on_green
12
+ # puts "red on bright blue".shell.red.on_bright_blue
13
+ #
14
+ # Some other effect examples:
15
+ #
16
+ # puts "bold".shell.bold
17
+ # puts "oh! i'm blinking".shell.blink
18
+ # puts "nice and underlined".shell.underline
19
+ # puts "other side, please".shell.negative
20
+ class ANSI < Basic
21
+
22
+ # ansi escape sequences list
23
+ CODES = {
3
24
  'black' => "\e[30m",
4
25
  'red' => "\e[31m",
5
26
  'green' => "\e[32m",
@@ -37,8 +58,29 @@ module ANSI
37
58
  'underline' => "\e[4m",
38
59
  'negative' => "\e[7m",
39
60
  'blink' => "\e[5m"
40
- }
61
+ }
62
+
63
+ # list of available ansi colors
64
+ COLORS = ['black', 'red', 'green', 'yellow', 'blue', 'magenta', 'cyan', 'white']
65
+
66
+ # list of available ansi effects
67
+ EFFECTS = ['bold', 'underline', 'negative', 'blink']
68
+
69
+ # generate instance methods
70
+ CODES.each do |code, value|
71
+ next if code == 'reset'
72
+ reset = CODES['reset']
73
+ class_eval <<-DEF
74
+ def #{code}
75
+ @string = "#{value}" + @string + "#{reset}"
76
+ self
77
+ end
78
+ DEF
79
+ end
41
80
 
42
- COLORS = ['black', 'red', 'green', 'yellow', 'blue', 'magenta', 'cyan', 'white']
43
- EFFECTS = ['bold', 'underline', 'negative', 'blink']
81
+ # remove all ansi escape sequences
82
+ def blank
83
+ @string.gsub(/\e\[[0-9]+m/,'')
84
+ end
85
+ end
44
86
  end
@@ -0,0 +1,11 @@
1
+ module Shiny
2
+ class Basic
3
+ def initialize(string)
4
+ @string = string
5
+ end
6
+
7
+ def to_s
8
+ @string
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,20 @@
1
+ require 'shiny/basic'
2
+ require 'shiny/ansi'
3
+ require 'shiny/html'
4
+
5
+ # instead to extend the ruby core string class with all the ansi
6
+ # escape and html methods, there are two proxy methods called ansi and
7
+ # html, to serve all the functionality.
8
+ class String
9
+ def ansi
10
+ Shiny::ANSI.new(self)
11
+ end
12
+
13
+ alias shell ansi
14
+
15
+ def html
16
+ Shiny::HTML.new(self)
17
+ end
18
+
19
+ alias browser html
20
+ end
data/lib/shiny/html.rb ADDED
@@ -0,0 +1,65 @@
1
+ module Shiny
2
+ class HTML < Basic
3
+ # the 17 w3c supported color names
4
+ # http://www.w3.org/TR/CSS21/syndata.html#value-def-color
5
+ FORMATS = {
6
+ 'black' => "<span style='color: black;'>",
7
+ 'silver' => "<span style='color: silver;'>",
8
+ 'gray' => "<span style='color: gray;'>",
9
+ 'white' => "<span style='color: white;'>",
10
+ 'maroon' => "<span style='color: maroon;'>",
11
+ 'red' => "<span style='color: red;'>",
12
+ 'purple' => "<span style='color: purple;'>",
13
+ 'fuchsia' => "<span style='color: fuchsia;'>",
14
+ 'green' => "<span style='color: green;'>",
15
+ 'lime' => "<span style='color: lime;'>",
16
+ 'olive' => "<span style='color: olive;'>",
17
+ 'yellow' => "<span style='color: yellow;'>",
18
+ 'navy' => "<span style='color: navy;'>",
19
+ 'blue' => "<span style='color: blue;'>",
20
+ 'teal' => "<span style='color: teal;'>",
21
+ 'aqua' => "<span style='color: aqua;'>",
22
+ 'orange' => "<span style='color: orange;'>",
23
+ 'on_black' => "<span style='background-color: black;'>",
24
+ 'on_silver' => "<span style='background-color: silver;'>",
25
+ 'on_gray' => "<span style='background-color: gray;'>",
26
+ 'on_white' => "<span style='background-color: white;'>",
27
+ 'on_maroon' => "<span style='background-color: maroon;'>",
28
+ 'on_red' => "<span style='background-color: red;'>",
29
+ 'on_purple' => "<span style='background-color: purple;'>",
30
+ 'on_fuchsia' => "<span style='background-color: fuchsia;'>",
31
+ 'on_green' => "<span style='background-color: green;'>",
32
+ 'on_lime' => "<span style='background-color: lime;'>",
33
+ 'on_olive' => "<span style='background-color: olive;'>",
34
+ 'on_yellow' => "<span style='background-color: yellow;'>",
35
+ 'on_navy' => "<span style='background-color: navy;'>",
36
+ 'on_blue' => "<span style='background-color: blue;'>",
37
+ 'on_teal' => "<span style='background-color: teal;'>",
38
+ 'on_aqua' => "<span style='background-color: aqua;'>",
39
+ 'on_orange' => "<span style='background-color: orange;'>",
40
+ 'bold' => "<span style='font-weight: bold;'>",
41
+ 'underline' => "<span style='text-decoration: underline;'>",
42
+ 'overline' => "<span style='text-decoration: overline;'>",
43
+ 'line_through' => "<span style='text-decoration: line-through;'>",
44
+ 'blink' => "<span style='text-decoration: blink;'>"
45
+ }
46
+
47
+ SPAN_BEGIN = "<span>"
48
+ SPAN_END = "</span>"
49
+
50
+ # generate html format instance methods
51
+ FORMATS.each do |name, value|
52
+ class_eval <<-DEF
53
+ def #{name}
54
+ @string = "#{value}" + @string + "#{SPAN_END}"
55
+ self
56
+ end
57
+ DEF
58
+ end
59
+
60
+ # remove all html span format tags
61
+ def blank
62
+ @string.gsub(/(<span [^>]+>|<\/span>)/, '')
63
+ end
64
+ end
65
+ end
data/spec/shiny_spec.rb CHANGED
@@ -3,54 +3,86 @@ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
3
3
  describe Shiny do
4
4
 
5
5
  # overwrite for testing
6
- class Shiny
6
+ class Shiny::Basic
7
7
  def ==(string)
8
8
  to_s == string
9
9
  end
10
10
  end
11
11
 
12
- it 'should return a green string' do
13
- "green".shell.green.should == "\e[32mgreen\e[0m"
14
- end
12
+ describe "#ansi" do
13
+ it 'should return a green string' do
14
+ "green".shell.green.should == "\e[32mgreen\e[0m"
15
+ end
15
16
 
16
- it 'should return an on yellow string' do
17
- "on yellow".shell.on_yellow.should == "\e[43mon yellow\e[0m"
18
- end
17
+ it 'should return an on yellow string' do
18
+ "on yellow".shell.on_yellow.should == "\e[43mon yellow\e[0m"
19
+ end
19
20
 
20
- it 'should return an on bright magenta string' do
21
- "on bright magenta".shell.on_bright_magenta == "\e[105mon bright magenta\e[0m"
22
- end
21
+ it 'should return an on bright magenta string' do
22
+ "on bright magenta".shell.on_bright_magenta.should == "\e[105mon bright magenta\e[0m"
23
+ end
23
24
 
24
- it 'should return a red on white string' do
25
- "red on white".shell.red.on_white == "\e[47m\e[31mred on white\e[0m\e[0m"
26
- end
25
+ it 'should return a red on white string' do
26
+ "red on white".shell.red.on_white.should == "\e[47m\e[31mred on white\e[0m\e[0m"
27
+ end
27
28
 
28
- it 'should return a bright blue string' do
29
- "bright blue".shell.bright_blue.should == "\e[94mbright blue\e[0m"
30
- end
29
+ it 'should return a bright blue string' do
30
+ "bright blue".shell.bright_blue.should == "\e[94mbright blue\e[0m"
31
+ end
31
32
 
32
- it 'should return a black on bright green string' do
33
- "black on bright green".shell.black.on_bright_green.should == "\e[102m\e[30mblack on bright green\e[0m\e[0m"
34
- end
33
+ it 'should return a black on bright green string' do
34
+ "black on bright green".shell.black.on_bright_green.should == "\e[102m\e[30mblack on bright green\e[0m\e[0m"
35
+ end
35
36
 
36
- it 'should return an underlined string' do
37
- "underline".shell.underline == "\e[4munderline\e[0m"
38
- end
37
+ it 'should return an underlined string' do
38
+ "underline".shell.underline.should == "\e[4munderline\e[0m"
39
+ end
39
40
 
40
- it 'should return a bold string' do
41
- "bold".shell.bold == "\e[1mbold\e[0m"
42
- end
41
+ it 'should return a bold string' do
42
+ "bold".shell.bold.should == "\e[1mbold\e[0m"
43
+ end
43
44
 
44
- it 'should return a negative string' do
45
- "negative".shell.negative == "\e[7mnegative\e[0m"
46
- end
45
+ it 'should return a negative string' do
46
+ "negative".shell.negative.should == "\e[7mnegative\e[0m"
47
+ end
48
+
49
+ it 'should return a blinking string' do
50
+ "blinking".shell.blink.should == "\e[5mblinking\e[0m"
51
+ end
52
+
53
+ it 'should clear all ansi escape sequences from string' do
54
+ "\e[47m\e[31mred on white\e[0m\e[0m".shell.blank.should == "red on white"
55
+ end
47
56
 
48
- it 'should return a blinking string' do
49
- "blinking".shell.blink == "\e[5mblinking\e[0m"
57
+ it 'should run also with the alias method' do
58
+ "try the alias method".shell.red.should == "\e[31mtry the alias method\e[0m"
59
+ end
50
60
  end
51
61
 
52
- it 'should clear all ansi escape sequences from string' do
53
- "\e[47m\e[31mred on white\e[0m\e[0m".shell.blank == "red on white"
62
+ describe "#html" do
63
+ it 'should return a bold string' do
64
+ "bold".html.bold.should == "<span style='font-weight: bold;'>bold</span>"
65
+ end
66
+
67
+ it 'should return a underlined string' do
68
+ "underline".html.underline.should == "<span style='text-decoration: underline;'>underline</span>"
69
+ end
70
+
71
+ it 'should return a overlined string' do
72
+ "overline".html.overline.should == "<span style='text-decoration: overline;'>overline</span>"
73
+ end
74
+
75
+ it 'should return a line-through string' do
76
+ "line-through".html.line_through.should == "<span style='text-decoration: line-through;'>line-through</span>"
77
+ end
78
+
79
+ it 'should return a blinking string' do
80
+ "blink".html.blink.should == "<span style='text-decoration: blink;'>blink</span>"
81
+ end
82
+
83
+ it 'should clear all html formats from string' do
84
+ "<span style='font-weight: bold;'>i'm blank now!</span>".html.blank.should == "i'm blank now!"
85
+ end
54
86
  end
55
87
 
56
88
  end
data/spec/spec_helper.rb CHANGED
@@ -1,9 +1,3 @@
1
- $LOAD_PATH.unshift(File.dirname(__FILE__))
2
1
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
- require 'shiny'
4
- require 'spec'
5
- require 'spec/autorun'
6
2
 
7
- Spec::Runner.configure do |config|
8
-
9
- end
3
+ require 'shiny'
metadata CHANGED
@@ -1,13 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shiny
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
5
4
  prerelease: false
6
5
  segments:
7
6
  - 0
8
- - 1
9
- - 1
10
- version: 0.1.1
7
+ - 2
8
+ - 0
9
+ version: 0.2.0
11
10
  platform: ruby
12
11
  authors:
13
12
  - Samuel Tonini
@@ -15,11 +14,11 @@ autorequire:
15
14
  bindir: bin
16
15
  cert_chain: []
17
16
 
18
- date: 2010-09-21 00:00:00 +02:00
17
+ date: 2010-10-25 00:00:00 +02:00
19
18
  default_executable:
20
19
  dependencies: []
21
20
 
22
- description: " Shiny gives you some common ansi escape sequences, which\n are available over a defined proxy method called 'shell', in\n the core ruby String class.\n\n Some colors examples:\n\n puts \"magenta\".shell.magenta\n puts \"bold blue\".shell.bold.blue\n puts \"yellow on cyan\".shell.yellow.on_cyan\n puts \"bright blue on green\".shell.bright_blue.on_green\n puts \"red on bright blue\".shell.red.on_bright_blue\n\n Some other effect examples:\n\n puts \"bold\".shell.bold\n puts \"oh! i'm blinking\".shell.blink\n puts \"nice and underlined\".shell.underline\n puts \"other side, please\".shell.negative\n"
21
+ description: Some common nice and shiny ansi escapse sequences and html format tags for the daily grind in the shell and browser.
23
22
  email: tonini.samuel@gmail.com
24
23
  executables: []
25
24
 
@@ -29,9 +28,11 @@ extra_rdoc_files: []
29
28
 
30
29
  files:
31
30
  - lib/shiny/ansi.rb
31
+ - lib/shiny/basic.rb
32
+ - lib/shiny/core_ext/string.rb
33
+ - lib/shiny/html.rb
32
34
  - lib/shiny.rb
33
35
  - spec/shiny_spec.rb
34
- - spec/spec.opts
35
36
  - spec/spec_helper.rb
36
37
  - LICENSE
37
38
  - Rakefile
@@ -50,7 +51,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
50
51
  requirements:
51
52
  - - ">="
52
53
  - !ruby/object:Gem::Version
53
- hash: 3
54
54
  segments:
55
55
  - 0
56
56
  version: "0"
@@ -59,7 +59,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
59
59
  requirements:
60
60
  - - ">="
61
61
  - !ruby/object:Gem::Version
62
- hash: 19
63
62
  segments:
64
63
  - 1
65
64
  - 3
@@ -71,6 +70,6 @@ rubyforge_project: shiny
71
70
  rubygems_version: 1.3.7
72
71
  signing_key:
73
72
  specification_version: 3
74
- summary: some common nice and shiny ansi escapse sequences for the daily grind in the shell
73
+ summary: Shiny ansi and html format methods.
75
74
  test_files: []
76
75
 
data/spec/spec.opts DELETED
@@ -1 +0,0 @@
1
- --color