shiny 0.1.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/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Samuel Tonini
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,37 @@
1
+ = shiny
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.
4
+
5
+ Some colors examples:
6
+
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
12
+
13
+ Some other effect examples:
14
+
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
19
+
20
+ Helpers to list available colors and effect methods (execute under terminal to see it in action)
21
+
22
+ Shiny.show_colors
23
+ Shiny.show_effects
24
+
25
+ == Note on Patches/Pull Requests
26
+
27
+ * Fork the project.
28
+ * Make your feature addition or bug fix.
29
+ * Add tests for it. This is important so I don't break it in a
30
+ future version unintentionally.
31
+ * Commit, do not mess with rakefile, version, or history.
32
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
33
+ * Send me a pull request. Bonus points for topic branches.
34
+
35
+ == Copyright
36
+
37
+ Copyright (c) 2010 Samuel Tonini. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,13 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'spec/rake/spectask'
4
+
5
+ spec_files = Rake::FileList["spec/**/*_spec.rb"]
6
+
7
+ desc "Run specs"
8
+ Spec::Rake::SpecTask.new do |t|
9
+ t.spec_files = spec_files
10
+ t.spec_opts = ["-c"]
11
+ end
12
+
13
+ task :default => :spec
data/lib/shiny.rb ADDED
@@ -0,0 +1,76 @@
1
+ require 'lib/shiny/ansi'
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
76
+ end
data/lib/shiny/ansi.rb ADDED
@@ -0,0 +1,44 @@
1
+ module ANSI
2
+ ESCAPE_SEQUENCES = {
3
+ 'black' => "\e[30m",
4
+ 'red' => "\e[31m",
5
+ 'green' => "\e[32m",
6
+ 'yellow' => "\e[33m",
7
+ 'blue' => "\e[34m",
8
+ 'magenta' => "\e[35m",
9
+ 'cyan' => "\e[36m",
10
+ 'white' => "\e[37m",
11
+ 'bright_black' => "\e[90m",
12
+ 'bright_red' => "\e[91m",
13
+ 'bright_green' => "\e[92m",
14
+ 'bright_yellow' => "\e[93m",
15
+ 'bright_blue' => "\e[94m",
16
+ 'bright_magenta' => "\e[95m",
17
+ 'bright_cyan' => "\e[96m",
18
+ 'bright_white' => "\e[97m",
19
+ 'on_black' => "\e[40m",
20
+ 'on_red' => "\e[41m",
21
+ 'on_green' => "\e[42m",
22
+ 'on_yellow' => "\e[43m",
23
+ 'on_blue' => "\e[44m",
24
+ 'on_magenta' => "\e[45m",
25
+ 'on_cyan' => "\e[46m",
26
+ 'on_white' => "\e[47m",
27
+ 'on_bright_black' => "\e[100m",
28
+ 'on_bright_red' => "\e[101m",
29
+ 'on_bright_green' => "\e[102m",
30
+ 'on_bright_yellow' => "\e[103m",
31
+ 'on_bright_blue' => "\e[104m",
32
+ 'on_bright_magenta' => "\e[105m",
33
+ 'on_bright_cyan' => "\e[106m",
34
+ 'on_bright_white' => "\e[107m",
35
+ 'reset' => "\e[0m",
36
+ 'bold' => "\e[1m",
37
+ 'underline' => "\e[4m",
38
+ 'negative' => "\e[7m",
39
+ 'blink' => "\e[5m"
40
+ }
41
+
42
+ COLORS = ['black', 'red', 'green', 'yellow', 'blue', 'magenta', 'cyan', 'white']
43
+ EFFECTS = ['bold', 'underline', 'negative', 'blink']
44
+ end
@@ -0,0 +1,56 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe Shiny do
4
+
5
+ # overwrite for testing
6
+ class Shiny
7
+ def ==(string)
8
+ to_s == string
9
+ end
10
+ end
11
+
12
+ it 'should return a green string' do
13
+ "green".shell.green.should == "\e[32mgreen\e[0m"
14
+ end
15
+
16
+ it 'should return an on yellow string' do
17
+ "on yellow".shell.on_yellow.should == "\e[43mon yellow\e[0m"
18
+ end
19
+
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
23
+
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
27
+
28
+ it 'should return a bright blue string' do
29
+ "bright blue".shell.bright_blue.should == "\e[94mbright blue\e[0m"
30
+ end
31
+
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
35
+
36
+ it 'should return an underlined string' do
37
+ "underline".shell.underline == "\e[4munderline\e[0m"
38
+ end
39
+
40
+ it 'should return a bold string' do
41
+ "bold".shell.bold == "\e[1mbold\e[0m"
42
+ end
43
+
44
+ it 'should return a negative string' do
45
+ "negative".shell.negative == "\e[7mnegative\e[0m"
46
+ end
47
+
48
+ it 'should return a blinking string' do
49
+ "blinking".shell.blink == "\e[5mblinking\e[0m"
50
+ end
51
+
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"
54
+ end
55
+
56
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1 @@
1
+ --color
@@ -0,0 +1,9 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'shiny'
4
+ require 'spec'
5
+ require 'spec/autorun'
6
+
7
+ Spec::Runner.configure do |config|
8
+
9
+ end
metadata ADDED
@@ -0,0 +1,76 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: shiny
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - Samuel Tonini
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-09-21 00:00:00 +02:00
19
+ default_executable:
20
+ dependencies: []
21
+
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"
23
+ email: tonini.samuel@gmail.com
24
+ executables: []
25
+
26
+ extensions: []
27
+
28
+ extra_rdoc_files: []
29
+
30
+ files:
31
+ - lib/shiny/ansi.rb
32
+ - lib/shiny.rb
33
+ - spec/shiny_spec.rb
34
+ - spec/spec.opts
35
+ - spec/spec_helper.rb
36
+ - LICENSE
37
+ - Rakefile
38
+ - README.rdoc
39
+ has_rdoc: true
40
+ homepage: http://github.com/zastav/shiny
41
+ licenses: []
42
+
43
+ post_install_message:
44
+ rdoc_options: []
45
+
46
+ require_paths:
47
+ - lib
48
+ required_ruby_version: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ hash: 3
54
+ segments:
55
+ - 0
56
+ version: "0"
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ hash: 19
63
+ segments:
64
+ - 1
65
+ - 3
66
+ - 4
67
+ version: 1.3.4
68
+ requirements: []
69
+
70
+ rubyforge_project: shiny
71
+ rubygems_version: 1.3.7
72
+ signing_key:
73
+ specification_version: 3
74
+ summary: some common nice and shiny ansi escapse sequences for the daily grind in the shell
75
+ test_files: []
76
+