coloring 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/CHANGELOG.rdoc ADDED
@@ -0,0 +1,7 @@
1
+ == 0.0.4 Date: 2012-08-22
2
+ * Added specs
3
+ * Added full README
4
+ * Added this CHANGELOG file
5
+
6
+ == 0.0.3 Date: 2012-08-22
7
+ * Start release
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in paintout.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 DoZator
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,64 @@
1
+ ## About
2
+
3
+ Extension for Ruby string class. Extension add methods for coloring text or background in Terminal. Also add some text effects.
4
+
5
+ ### Features
6
+
7
+ * String.color ( color: black, red, green, yelow, blue, magenta, cyan, white )
8
+ * String.on_color( background colors same )
9
+ * String.bright
10
+ * String.underline
11
+ * String.blink
12
+ * String.negative
13
+ * String.hide
14
+
15
+ ### Installation
16
+
17
+ Add this line to your application's Gemfile:
18
+
19
+ gem 'coloring'
20
+
21
+ And then execute:
22
+
23
+ $ bundle
24
+
25
+ Or install it yourself as:
26
+
27
+ $ gem install coloring
28
+
29
+ ### Usage
30
+
31
+ Add line:
32
+
33
+ require 'coloring'
34
+
35
+ For base colors:
36
+
37
+ puts "Hello, World!".green
38
+ puts "Hello, World!".coloring(32)
39
+ puts "Hello, World!".coloring(:green)
40
+ puts "Hello, World!".coloring("green")
41
+
42
+ For more params:
43
+
44
+ puts "Hello,World!".green.underline
45
+ puts "Hello, World".green.on_red.underline
46
+ puts "Hello, World!".coloring [:green, :on_red, :underline]
47
+ puts "Hello, World!".coloring ["green", "on_red", "underline"]
48
+ puts "Hello,World!".coloring [32, 41, 4]
49
+ puts "Hello,World!".coloring(32).on_red
50
+ puts "Hello,World!".coloring([:green, :underline]).on_red
51
+
52
+ ### Contributing
53
+
54
+ 1. Fork it
55
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
56
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
57
+ 4. Push to the branch (`git push origin my-new-feature`)
58
+ 5. Create new Pull Request
59
+
60
+ ### Author
61
+
62
+ DoZator, 2012
63
+
64
+ Sorry for my English )
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env rake
2
+
3
+ require "bundler/gem_tasks"
4
+
5
+ desc 'Run all tests'
6
+ task :spec_all do
7
+ system("rspec spec/ --color")
8
+ end
data/coloring.gemspec ADDED
@@ -0,0 +1,20 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/coloring/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["DoZator"]
6
+ gem.email = ["oabogatenko@gmail.com"]
7
+ gem.description = %q{Adds methods for coloring and styling text for class String}
8
+ gem.summary = %q{Terminal text painter}
9
+ gem.homepage = ""
10
+
11
+ gem.add_development_dependency "rspec"
12
+
13
+ gem.files = `git ls-files`.split($\)
14
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
15
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
16
+ gem.name = "coloring"
17
+ gem.require_paths = ["lib"]
18
+ gem.version = Coloring::VERSION
19
+ end
20
+
data/lib/coloring.rb ADDED
@@ -0,0 +1,68 @@
1
+ require "coloring/version"
2
+
3
+ module Coloring
4
+
5
+ # Select Graphic Rendition parameters
6
+
7
+ SGRPARAMS = {
8
+ :bright => 1,
9
+ :underline => 4,
10
+ :blink => 5,
11
+ :negative => 7,
12
+ :hide => 8,
13
+ :black => 30,
14
+ :red => 31,
15
+ :green => 32,
16
+ :yellow => 33,
17
+ :blue => 34,
18
+ :magenta => 35,
19
+ :cyan => 36,
20
+ :white => 37,
21
+ :on_black => 40,
22
+ :on_red => 41,
23
+ :on_green => 42,
24
+ :on_yellow => 43,
25
+ :on_blue => 44,
26
+ :on_magenta => 45,
27
+ :on_cyan => 46,
28
+ :on_white => 47
29
+ }
30
+
31
+ # Define base methods
32
+
33
+ SGRPARAMS.each do |effect, value|
34
+ define_method( effect ) { self.coloring( value ) }
35
+ end
36
+
37
+ # Set effect value from SGR Hash
38
+
39
+ def set_param ( param )
40
+
41
+ if param.instance_of?(Fixnum)
42
+ param
43
+ elsif param.instance_of?(String)
44
+ param = SGRPARAMS[param.to_sym]
45
+ else
46
+ param = SGRPARAMS[param]
47
+ end
48
+ param
49
+ end
50
+
51
+ # Output method
52
+
53
+ def coloring ( params )
54
+
55
+ if params.instance_of?(Array)
56
+ all_params = params.map! { |elem| elem = self.set_param(elem).to_s }.join ";"
57
+ else
58
+ all_params = self.set_param( params )
59
+ end
60
+
61
+ "\033[#{all_params}m" + self + "\033[0m"
62
+
63
+ end
64
+
65
+ end
66
+
67
+ String.send(:include, Coloring)
68
+
@@ -0,0 +1,3 @@
1
+ module Coloring
2
+ VERSION = "0.0.4"
3
+ end
@@ -0,0 +1,38 @@
1
+ require File.dirname(__FILE__) + "/../lib/coloring.rb"
2
+
3
+ describe Coloring do
4
+
5
+ before :all do
6
+ @sample = "Hello, World!"
7
+ end
8
+
9
+ describe "base colors methods" do
10
+
11
+ it "should return value" do
12
+ @sample.green.should_not be_nil
13
+ end
14
+
15
+ it "should return right class" do
16
+ @sample.red.class.should == String
17
+ end
18
+
19
+ end
20
+
21
+ describe "method with params" do
22
+
23
+ it "should return value" do
24
+ @sample.coloring(:green).should_not be_nil
25
+ end
26
+
27
+ it "should return right class" do
28
+ @sample.red.class.should == String
29
+ end
30
+
31
+ it "should raise error if wrong parameter for method" do
32
+ expect { @sample.coloring(:red, :on_blue) }.to raise_error
33
+ end
34
+
35
+ end
36
+
37
+ end
38
+
metadata ADDED
@@ -0,0 +1,72 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: coloring
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.4
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - DoZator
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-08-22 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ description: Adds methods for coloring and styling text for class String
31
+ email:
32
+ - oabogatenko@gmail.com
33
+ executables: []
34
+ extensions: []
35
+ extra_rdoc_files: []
36
+ files:
37
+ - .gitignore
38
+ - CHANGELOG.rdoc
39
+ - Gemfile
40
+ - LICENSE
41
+ - README.md
42
+ - Rakefile
43
+ - coloring.gemspec
44
+ - lib/coloring.rb
45
+ - lib/coloring/version.rb
46
+ - spec/coloring_spec.rb
47
+ homepage: ''
48
+ licenses: []
49
+ post_install_message:
50
+ rdoc_options: []
51
+ require_paths:
52
+ - lib
53
+ required_ruby_version: !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ! '>='
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
59
+ required_rubygems_version: !ruby/object:Gem::Requirement
60
+ none: false
61
+ requirements:
62
+ - - ! '>='
63
+ - !ruby/object:Gem::Version
64
+ version: '0'
65
+ requirements: []
66
+ rubyforge_project:
67
+ rubygems_version: 1.8.24
68
+ signing_key:
69
+ specification_version: 3
70
+ summary: Terminal text painter
71
+ test_files:
72
+ - spec/coloring_spec.rb