fun_with_string_colors 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ NDgyMGU1MzMyNWY3MzIwNWY4NGFjZTk3NGRhNmI4Yjk2NjRjMThkNg==
5
+ data.tar.gz: !binary |-
6
+ Yjk0YzUzZDIyYWM5YjdlOTc5YzAzMTI5YzYxYTNjMGEzZWIwNjc3Mw==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ ZWZlNzgyZDJmOTMzNDZjMDEzZmFlMWIyYTk2M2FlNDY4NWI1OTMzYWE3Yzkw
10
+ ZmQ5ZjA3NzFlZTQyMjVkOWE5NTQ3MzFmNzg4ZDc2ZjBkM2QzMDlmZGZjYTI5
11
+ NjA5NDRiNGU0ODI5Y2Y4M2NlOGNmM2RmMjMwOWY0M2NkZTdhMmM=
12
+ data.tar.gz: !binary |-
13
+ NDhmYzdhMTU3MThkNzg3ODU4OWZhNWQxNzM1NTQ3NDRkNDI5YWE5MzlhMzNh
14
+ YmNkZmU2MjkwMDhkMGI1ZmMyNmZhMDkyNjUyMTliMGE2NjIzZWYwMTg4Njll
15
+ ZDhiMjJlZGRhZmZhMDZkMzc0ZWMwOGY1MmY4NzBmMzkzOWYyOGY=
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,15 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ group :development do
9
+ # gem "shoulda", "~> 3.5"
10
+ # gem "rdoc", "~> 3.12"
11
+ # gem "bundler", "~> 1.0"
12
+ # gem "jeweler", "~> 2.0.1"
13
+ # gem "simplecov", ">= 0.8"
14
+ gem "fun_with_testing", "~> 0.0"
15
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2014 Bryce Anderson
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,27 @@
1
+ = fun_with_string_colors
2
+
3
+ Paint your strings for prettier console output
4
+
5
+ require 'fun_with_color_strings'
6
+
7
+ FunWith::StringColors.activate
8
+ String.colorize( true )
9
+ puts "Hello World".paint(:pink)
10
+
11
+
12
+
13
+ == Contributing to fun_with_string_colors
14
+
15
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
16
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
17
+ * Fork the project.
18
+ * Start a feature/bugfix branch.
19
+ * Commit and push until you are happy with your contribution.
20
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
21
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
22
+
23
+ == Copyright
24
+
25
+ Copyright (c) 2014 Bryce Anderson. See LICENSE.txt for
26
+ further details.
27
+
data/Rakefile ADDED
@@ -0,0 +1,51 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://guides.rubygems.org/specification-reference/ for more options
17
+ gem.name = "fun_with_string_colors"
18
+ gem.homepage = "http://github.com/darthschmoo/fun_with_string_colors"
19
+ gem.license = "MIT"
20
+ gem.summary = "Paint your strings for prettier console output."
21
+ gem.description = "Paint your strings for prettier console output. Description should not equal summary."
22
+ gem.email = "keeputahweird@gmail.com"
23
+ gem.authors = ["Bryce Anderson"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rake/testtask'
29
+ Rake::TestTask.new(:test) do |test|
30
+ test.libs << 'lib' << 'test'
31
+ test.pattern = 'test/**/test_*.rb'
32
+ test.verbose = true
33
+ end
34
+
35
+ desc "Code coverage detail"
36
+ task :simplecov do
37
+ ENV['COVERAGE'] = "true"
38
+ Rake::Task['test'].execute
39
+ end
40
+
41
+ task :default => :test
42
+
43
+ require 'rdoc/task'
44
+ Rake::RDocTask.new do |rdoc|
45
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
46
+
47
+ rdoc.rdoc_dir = 'rdoc'
48
+ rdoc.title = "fun_with_string_colors #{version}"
49
+ rdoc.rdoc_files.include('README*')
50
+ rdoc.rdoc_files.include('lib/**/*.rb')
51
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.2
@@ -0,0 +1,20 @@
1
+ module FunWith
2
+ module StringColors
3
+ module StringPaintExtensions
4
+ # When set to false, no color codes are added. Good for
5
+ # adding colors only when output goes to interactive shell
6
+ def colorize( setting = nil )
7
+ @colorize_setting = setting unless setting.nil?
8
+ @colorize_setting
9
+ end
10
+
11
+ def colorize?
12
+ @colorize_setting
13
+ end
14
+
15
+ def colorize_if_tty_out( out = STDOUT )
16
+ self.colorize( out.tty? )
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,75 @@
1
+ module FunWith
2
+ module StringColors
3
+ module StringPaintInclusions
4
+ ############################## COLORS!!! ###############################
5
+ ANSI_COLORS = {
6
+ :bold => "1",
7
+ :dim => "2",
8
+ :underline => "4",
9
+ :blink => "5",
10
+ :reverse => "7",
11
+ :invisible => "8",
12
+ :clear => "8",
13
+ :black => "30",
14
+ :red => "31",
15
+ :green => "32",
16
+ :brown => "33",
17
+ :yellow => "33", # synonym :brown
18
+ :blue => "34",
19
+ :magenta => "35",
20
+ :pink => "35", # synonym :magenta
21
+ :cyan => "36",
22
+ :gray => "39",
23
+ :bg_black => "40",
24
+ :bg_red => "41",
25
+ :bg_green => "42",
26
+ :bg_brown => "43",
27
+ :bg_yellow => "43", # synonym :bg_brown
28
+ :bg_blue => "44",
29
+ :bg_magenta => "45",
30
+ :bg_pink => "45", # synonym :bg_magenta
31
+ :bg_cyan => "46",
32
+ :bg_gray => "47"
33
+ }
34
+
35
+ ANSI_COLOR_TERMINATORS = {
36
+ :reverse => "\e[27m",
37
+ 7 => "\e[27m",
38
+ :bold => "\e[22m",
39
+ 1 => "\e[22m"
40
+ }
41
+
42
+ def paint( *colors )
43
+ if paint?
44
+ rval = self.dup
45
+ terminations = []
46
+
47
+ for color in colors
48
+ case color
49
+ when :reset, :unpaint
50
+ regex = /\e\[\d+m/
51
+ rval = rval.gsub( regex, '' )
52
+ terminations = []
53
+ when Symbol
54
+ if ANSI_COLORS[color]
55
+ rval = "\e[#{ANSI_COLORS[color]}m#{rval}"
56
+ terminations << (ANSI_COLOR_TERMINATORS[color] || "\e[0m")
57
+ end
58
+ when /^\d+$/, Integer # you can give numbers/number strings directly
59
+ rval = "\e[#{ANSI_COLORS[color] || color}m#{rval}"
60
+ terminations << (ANSI_COLOR_TERMINATORS[color.to_i] || "\e[0m")
61
+ end
62
+ end
63
+
64
+ rval + terminations.uniq.join
65
+ else
66
+ self
67
+ end
68
+ end
69
+
70
+ def paint?
71
+ self.class.colorize?
72
+ end
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,8 @@
1
+ module FunWith
2
+ module StringColors
3
+ def self.activate
4
+ String.send( :include, StringPaintInclusions )
5
+ String.send( :extend, StringPaintExtensions )
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,3 @@
1
+ require_relative File.join( "fun_with", "string_colors" )
2
+ require_relative File.join( "fun_with", "string_colors", "string_paint_extensions" )
3
+ require_relative File.join( "fun_with", "string_colors", "string_paint_inclusions" )
data/test/helper.rb ADDED
@@ -0,0 +1,45 @@
1
+ require "fun_with_testing"
2
+ # require 'simplecov'
3
+ #
4
+ # module SimpleCov::Configuration
5
+ # def clean_filters
6
+ # @filters = []
7
+ # end
8
+ # end
9
+ #
10
+ # SimpleCov.configure do
11
+ # clean_filters
12
+ # load_adapter 'test_frameworks'
13
+ # end
14
+ #
15
+ # ENV["COVERAGE"] && SimpleCov.start do
16
+ # add_filter "/.rvm/"
17
+ # end
18
+ #
19
+ # require 'rubygems'
20
+ # require 'bundler'
21
+
22
+ # begin
23
+ # Bundler.setup(:default, :development)
24
+ # rescue Bundler::BundlerError => e
25
+ # $stderr.puts e.message
26
+ # $stderr.puts "Run `bundle install` to install missing gems"
27
+ # exit e.status_code
28
+ # end
29
+ #
30
+ # require 'minitest'
31
+ # require 'shoulda'
32
+
33
+ # $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
34
+ # $LOAD_PATH.unshift(File.dirname(__FILE__))
35
+
36
+ require_relative( File.join( "..", "lib", "fun_with_string_colors" ) )
37
+
38
+ FunWith::StringColors.activate
39
+ String.colorize( true )
40
+
41
+ # class Test::Unit::TestCase
42
+ # end
43
+ #
44
+ class FunWith::StringColors::TestCase < FunWith::Testing::TestCase
45
+ end
@@ -0,0 +1,41 @@
1
+ require 'helper'
2
+
3
+ class TestFunWithStringColors < FunWith::StringColors::TestCase
4
+ should "test basics" do
5
+ assert defined?( FunWith::StringColors )
6
+ assert defined?( FunWith::StringColors::StringPaintExtensions )
7
+
8
+ assert FunWith::StringColors.respond_to?( :activate )
9
+ FunWith::StringColors.activate
10
+
11
+ assert defined?( String::ANSI_COLORS )
12
+
13
+ for method in [:paint, :paint?]
14
+ assert "".respond_to?(method), "String.new doesn't respond to #{method.inspect}"
15
+ end
16
+ end
17
+
18
+ should "print prettily" do
19
+ for color in String::ANSI_COLORS.keys
20
+ puts "[" + "Hello World".paint(color) + "]" + "[" + "Hello World".paint(color, :bold) + "]" + "[" + "Hello World".paint(color, :bold, :reverse ) + "]" + "[" + "Hello World".paint(color, :bold, :reverse, :reset ) + "]"
21
+ end
22
+
23
+ str = ""
24
+ for color in %w("1 2 3 4 5 6 7 8 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107)
25
+ str << "#{color}: #{ 'hello world'.paint(color) } <done>\n"
26
+ end
27
+
28
+ puts str
29
+ end
30
+
31
+ should "clear strings properly" do
32
+ s1 = "hello"
33
+ s2 = "hello".paint( :bold, :reverse, :bg_pink, :blue, :underline )
34
+ puts "#{s1} => #{s2}"
35
+ assert_equal s1, s2.paint( :reset )
36
+ end
37
+
38
+ should "not alter output when .paint() receives nil/unrecognized" do
39
+ assert_equal "hello", "hello".paint(nil)
40
+ end
41
+ end
metadata ADDED
@@ -0,0 +1,72 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fun_with_string_colors
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Bryce Anderson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-04-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: fun_with_testing
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '0.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '0.0'
27
+ description: Paint your strings for prettier console output. Description should not
28
+ equal summary.
29
+ email: keeputahweird@gmail.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files:
33
+ - LICENSE.txt
34
+ - README.rdoc
35
+ files:
36
+ - .document
37
+ - Gemfile
38
+ - LICENSE.txt
39
+ - README.rdoc
40
+ - Rakefile
41
+ - VERSION
42
+ - lib/fun_with/string_colors.rb
43
+ - lib/fun_with/string_colors/string_paint_extensions.rb
44
+ - lib/fun_with/string_colors/string_paint_inclusions.rb
45
+ - lib/fun_with_string_colors.rb
46
+ - test/helper.rb
47
+ - test/test_fun_with_string_colors.rb
48
+ homepage: http://github.com/darthschmoo/fun_with_string_colors
49
+ licenses:
50
+ - MIT
51
+ metadata: {}
52
+ post_install_message:
53
+ rdoc_options: []
54
+ require_paths:
55
+ - lib
56
+ required_ruby_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ! '>='
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ required_rubygems_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ requirements: []
67
+ rubyforge_project:
68
+ rubygems_version: 2.2.2
69
+ signing_key:
70
+ specification_version: 4
71
+ summary: Paint your strings for prettier console output.
72
+ test_files: []