paint-shortcuts 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d57c0fd9ddd3a842fc19ac0ac3d942e70c518c60
4
+ data.tar.gz: ad2e60a6053be8eee6f7b2f08de0653817b35b32
5
+ SHA512:
6
+ metadata.gz: cd9e902ae80a6968b72caa163a8ae91957342485be45d2f90f9a8c05ca28c72cacd2c204225808a24c228a914e56460475450bb7f7650f007eebb69f86809159
7
+ data.tar.gz: daa6eaeb4829e3b0de16535e06056c1dd7aef02401af9aa1f3ff5081dda03d449c6f0e26b0b5a3802d090ef7201f44831f5d4da01ca8fae2619f076ecdfb2509
@@ -0,0 +1,42 @@
1
+ === 1.0.0
2
+ * Improved performance
3
+ * Option for :random colors removed (see readme)
4
+ * Seperate Paint::SHORTCUTS into extra gem
5
+ * Drop support for Ruby 1 (inoffically still support 1.9.3)
6
+
7
+ === 0.9.0
8
+ * Don't colorize strings via shortcuts when Paint.mode == 0
9
+ * Freeze bundled ascii color data
10
+
11
+ === 0.8.7
12
+ * Fix caching bug for random ansi color
13
+
14
+ === 0.8.6
15
+ * Add missing require 'rbconfig' and travis test everything
16
+
17
+ === 0.8.5
18
+ * Support 256 color on windows' ConEmu
19
+
20
+ === 0.8.4
21
+ * Fix post-install message unicode
22
+
23
+ === 0.8.3
24
+ * Paint.[] also accepts uppercased hex strings (gh#2)
25
+ * Performance tweaks (thanks to murphy) (gh#4, #5)
26
+ * API change: deactivate colorizing with Paint.mode = 0
27
+
28
+ === 0.8.2
29
+ * Paint.[] with only a single string argument does not colorize the string anymore, but returns the plain string
30
+ * New pseudo color :random - returns a random ansi color
31
+
32
+ === 0.8.1
33
+ * Improve rgb function with better gray scale values
34
+ * Add Paint.mode:
35
+ * Set to 0 to deactivate colorizing
36
+ * Set to 16 or 8 and all color generation methods will generate simple ansi colors
37
+ * Set to 256 for 256 color support
38
+ * Tries to automatically detect your terminal's features
39
+ * Minor changes
40
+
41
+ === 0.8.0
42
+ * Initial release
@@ -0,0 +1,22 @@
1
+ The MIT LICENSE
2
+
3
+ Copyright (c) 2011-2015 Jan Lelis
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.
@@ -0,0 +1,137 @@
1
+ = Ruby Paint {<img src="https://badge.fury.io/rb/paint.svg" />}[http://badge.fury.io/rb/paint] {<img src="https://travis-ci.org/janlelis/paint.png" />}[https://travis-ci.org/janlelis/paint]
2
+
3
+ Paint manages terminal colors and effects for you. It combines the strengths of *term-ansicolor*, *rainbow* and other similar projects into a simple to use, however still flexible terminal colorization gem with no core extensions by default.
4
+
5
+ == Features
6
+ * No string extensions (suitable for library development)
7
+ * Supports setting 256 colors (for capable terminals)
8
+ * Supports setting any effects (although most terminals won't support it)
9
+ * Simple to use
10
+ * Faster than most similar gems due to caching
11
+ * Fall-back modes for non-256-color terminals (<tt>Paint.mode</tt>), supported modes:
12
+ * 256 colors
13
+ * 16 colors (only ansi colors, combined with bright effect)
14
+ * 8 colors (only ansi colors)
15
+ * 0 colors (deactivate)
16
+
17
+ == Setup
18
+ Add to Gemfile:
19
+
20
+ gem 'paint'
21
+
22
+ and run `bundle install`
23
+
24
+ In Ruby do:
25
+
26
+ require 'paint'
27
+
28
+ == Usage
29
+ The only method you need to know to get started is: <tt>Paint.[]</tt>
30
+
31
+ The first argument given to <tt>Paint.[]</tt> is the string to colorize (if the object is not a string, <tt>to_s</tt> will be called on it). The other arguments describe how to modify/colorize the string. Let's learn by example:
32
+
33
+ Paint['Ruby', :red] # sets ansi color red
34
+ Paint['Ruby', :red, :bright] # also applies bright/bold effect
35
+ Paint['Ruby', :bright, :red] # does the same as above
36
+ Paint['Ruby', :red, :bright, :underline] # effects can often be combined
37
+ Paint['Ruby', :red, :blue] # the second color you define is for background
38
+ Paint['Ruby', nil, :blue] # pass a nil before a color to ignore foreground and only set background color
39
+ Paint['Ruby', [100, 255, 5]] # you can define rgb colors that map to one of 256 colors. Only supported on 256-color terminals, of course
40
+ Paint['Ruby', "gold", "snow"] # Paint supports rgb.txt color names, note that the arguments are strings (:yellow != "yellow")!
41
+ Paint['Ruby', "#123456"] # html like definitions are possible.
42
+ Paint['Ruby', "fff"] # another html hex definition
43
+ Paint['Ruby', :inverse] # swaps fore- and background
44
+ Paint['Ruby', :italic, :encircle, :rapid_blink, :overline] # probably not supported effects
45
+ Paint['Ruby'] # don't pass any argument and the string will not be changed
46
+
47
+ When you pass multiple colors, the first one is taken as foreground color and the second one defines the background color, every other will be ignored. To only change the background color, you have to pass a <tt>nil</tt> first. Effects can be passed in any order.
48
+
49
+ You can find more examples in the specs.
50
+
51
+ == Windows Support
52
+ For ANSI support in Windows OS, you can use {ansicon}[https://github.com/adoxa/ansicon] or {ConEmu}[http://code.google.com/p/conemu-maximus5/].
53
+
54
+ == More details about terminal colors and effects
55
+ Terminal colors/effects are set by {ansi escape sequences}[http://en.wikipedia.org/wiki/ANSI_escape_code]. These are strings that look like this: <tt>\e[X;X;X;X;X]m</tt> where X are integers with some meaning. For example, 0 means reset, 31 means red foreground and 41 red background. When you tell Paint to use one of the eight ansi base colors as foreground color, it just inserts a number between 30 and 37 in the sequence. The following colors are available:
56
+
57
+ :black, :red, :green, :yellow, :blue, :magenta, :cyan, :white, (:default)
58
+
59
+ When combined with the <tt>:bright</tt> (= <tt>:bold</tt>) effect, the color in the terminal emulator often differs a little bit.
60
+
61
+ Through special sequences it's also possible to set 256-colors, instead of 8, which is also supported by many - but not all - terminals. Paint automatically translates given rgb colors to a suitable color of the 256 available colors.
62
+
63
+ When using the <tt>Paint.[]</tt> method, Paint wraps the given string between the calculated escape sequence and an reset sequence (<tt>"\e[0m"</tt>). You can get the raw escape sequence by using the <tt>Paint.color</tt> method.
64
+
65
+ === Effects
66
+ Also see {en.wikipedia.org/wiki/ANSI_escape_code}[http://en.wikipedia.org/wiki/ANSI_escape_code]:
67
+
68
+ ==== Often supported
69
+
70
+ 0) :reset, :nothing
71
+ 1) :bright, :bold
72
+ 4) :underline
73
+ 7) :inverse, :negative
74
+ 8) :conceal, :hide
75
+ 22) :clean
76
+ 24) :underline_off
77
+ 26) :inverse_off, :positive
78
+ 27) :conceal_off, :show, :reveal
79
+
80
+ ==== Not widely supported
81
+
82
+ 2) :faint
83
+ 3) :italic
84
+ 5) :blink, :slow_blink
85
+ 6) :rapid_blink
86
+ 9) :crossed, :crossed_out
87
+ 10) :default_font, :font0
88
+ 11-19) :font1, :font2, :font3, :font4, :font5, :font6, :font7, :font8, :font9
89
+ 20) :fraktur
90
+ 21) :bright_off, :bold_off, :double_underline
91
+ 23) :italic_off, :fraktur_off
92
+ 25) :blink_off
93
+ 29) :crossed_off, :crossed_out_off
94
+ 51) :frame
95
+ 52) :encircle
96
+ 53) :overline
97
+ 54) :frame_off, :encircle_off
98
+ 55) :overline_off
99
+
100
+ == Paint.mode
101
+ You can choose between four ways to use <tt>Paint.[]</tt> by setting <tt>Paint.mode</tt> to one of the following:
102
+ * 256: full support
103
+ * 16: don't use 256 colors, but the ansi eight ones (combined with bright effect)
104
+ * 8: don't use 256 colors, but the ansi eight ones
105
+ * 0: don't colorize at all
106
+
107
+ Paint tries to automatically detect the proper value, please open an issue if <tt>Paint.detect_mode</tt> yields a wrong value for you.
108
+
109
+ == Random ANSI colors
110
+
111
+ With 1.0, the :random feature was removed, because it interfered with the caching mechanism. If you still need it, you will have to workaround by generating random colors yourself, before passing them into the Paint method:
112
+
113
+ Paint['Ruby', Paint.random] # get one of eight random ansi foreground colors
114
+ Paint['Ruby', Paint.random(true)] # get one of eight random ansi background colors
115
+
116
+ == Utilities
117
+ There are some supporting methods available. You can get a <tt>p</tt> like alternative for calling <tt>puts Paint.[]</tt>:
118
+
119
+ require 'paint/pa'
120
+ pa "Ruby", :red, :underline # same as puts Paint["Ruby", :red, :underline]
121
+
122
+ Another helper method is <tt>Paint.unpaint</tt>, which removes any ansi colors:
123
+
124
+ Paint.unpaint( Paint['Ruby', :red, :bright] ).should == 'Ruby'
125
+
126
+ == Advanced Usage: Shortcuts
127
+ There is an extension gem available that allows you to define custom color shortcuts. See {SHORTCUTS.rdoc}[https://github.com/janlelis/paint/blob/master/SHORTCUTS.rdoc] for more information.
128
+
129
+ == J-_-L
130
+
131
+ Copyright (c) 2011-2015 Jan Lelis <http://janlelis.com>, released under the MIT license.
132
+
133
+ Mainly influenced by rainbow[https://github.com/sickill/rainbow] and {term-ansicolor}[https://github.com/flori/term-ansicolor]. Contributors[https://github.com/janlelis/paint/contributors]:
134
+ * {CyberShadow}[https://github.com/CyberShadow]
135
+ * {korun}[https://github.com/korun]
136
+ * {mhaylock}[https://github.com/mhaylock]
137
+ * {korny}[https://github.com/rubychan]
@@ -0,0 +1,51 @@
1
+ = Paint::SHORTCUTS
2
+
3
+ == Setup
4
+ Add to Gemfile:
5
+
6
+ gem 'paint-shortcuts'
7
+
8
+ and run `bundle install`
9
+
10
+ In Ruby do:
11
+
12
+ require 'paint/shortcuts'
13
+
14
+ == Description
15
+ Now for the fancy part: You can create color shortcuts for your gems and scripts! Note: You don't have to use this feature (and only stick to <tt>Paint.[]</tt> instead) ;)
16
+
17
+ It's easy: Just setup a hash of symbol keys and escape string values at: <tt>Paint::SHORTCUTS[:your_namespace]</tt>. They are stored directly as escape sequences for performance reasons (this also means, you need different namespaces for different <tt>Paint.mode</tt>s). Example:
18
+
19
+ Paint::SHORTCUTS[:example] = {
20
+ :white => Paint.color(:black),
21
+ :red => Paint.color(:red, :bright),
22
+ :title => Paint.color(:underline),
23
+ }
24
+
25
+ The methods become "rubymagically" available in a <tt>Paint</tt> child model:
26
+
27
+ Paint::Example.red 'Ruby' # => "\e[31;1mRuby\e[0m"
28
+ Paint::Example.white # => "\e[37m"
29
+
30
+ As you can see, the helper methods look useful and can take either one (wrap string) or none (only color) arguments ...but they aren't really <em>short</em> yet.
31
+
32
+ Fortunately, you can include them:
33
+
34
+ include Paint::Example
35
+ red # => "\e[31;1m"
36
+ white 'Ruby' # => "\e[30m"
37
+
38
+ All shortcuts, defined in your shortcut namespace at this time, are now (privately) available in your current namespace (without using a method_missing implementation).
39
+
40
+ Furthermore, there are two variations of this approach:
41
+
42
+ include Paint::Example::String
43
+ "Ruby".title # => "\e[4mRuby\e[0m"
44
+ 5.red # => "\e[31;1m5\e[0m"
45
+
46
+ In this case, <tt>self</tt> will be converted to a string and wrapped with the specific color code. Note, that the helper methods doesn't take any arguments when using this inclusion method.
47
+
48
+ The third way allows you to get a single color helper method to avoid cluttering namespaces:
49
+
50
+ include Paint::Example::Prefix::ExampleName
51
+ "Ruby".example_name(:red) # => "\e[31;1mRuby\e[0m"
@@ -0,0 +1,98 @@
1
+ require_relative 'shortcuts_version'
2
+
3
+ require 'paint'
4
+
5
+ module Paint
6
+ # Hash for defining color/effect shortcuts
7
+ SHORTCUTS = {
8
+ # :example => { # would create a Paint::Example constant...
9
+ # :light_red => "\e[31;1m", # with a method .light_red
10
+ # }
11
+ }
12
+ SHORTCUTS.default = {}
13
+
14
+ class << self
15
+ # Paint::SomeModule --> Paint::SHORTCUTS[:some_module]
16
+ def const_missing(mod_name)
17
+ # get shortcuts
18
+ shortcuts = SHORTCUTS[mod_name.to_s.gsub(/[A-Z]/,'_\0').downcase[1..-1].to_sym] || []
19
+
20
+ # create module
21
+ class_eval "module #{mod_name}; end"
22
+ mod = const_get(mod_name)
23
+
24
+ # define direct behaviour, class methods
25
+ mod.define_singleton_method :method_missing do |color_name, *args|
26
+ if color_code = shortcuts[color_name]
27
+ string = Array(args).join
28
+ return string if Paint.mode.zero?
29
+
30
+ if args.empty?
31
+ color_code
32
+ else
33
+ color_code + string + NOTHING
34
+ end
35
+ else
36
+ nil
37
+ end
38
+ end
39
+
40
+ mod.define_singleton_method :respond_to_missing? do |color_name, *args|
41
+ shortcuts.include?(color_name) || super(color_name, *args)
42
+ end
43
+
44
+ # define include behaviour, instance methods
45
+ mod.define_singleton_method :included do |_|
46
+ shortcuts.each{ |color_name, color_code|
47
+ define_method color_name do |*args|
48
+ string = Array(args).join
49
+ return string if Paint.mode.zero?
50
+
51
+ if args.empty?
52
+ color_code
53
+ else
54
+ color_code + string + NOTHING
55
+ end
56
+ end
57
+ }
58
+ private(*shortcuts.keys) unless shortcuts.empty?
59
+ end
60
+
61
+ # include variations, defined in child modules
62
+ mod.class_eval "module String; end"
63
+ string = mod.const_get(:String)
64
+ string.define_singleton_method :included do |_|
65
+ shortcuts.each{ |color_name, color_code|
66
+ define_method color_name do
67
+ if Paint.mode.zero?
68
+ to_s
69
+ else
70
+ color_code + to_s + NOTHING
71
+ end
72
+ end
73
+ }
74
+ end
75
+
76
+ # OK, let's take it one level further ;)
77
+ mod.class_eval "module Prefix; end"
78
+ prefix_prefix = mod.const_get(:Prefix)
79
+ prefix_prefix.define_singleton_method :const_missing do |prefix_name|
80
+ class_eval "module #{prefix_name}; end"
81
+ prefix = const_get(prefix_name)
82
+
83
+ prefix.define_singleton_method :included do |_|
84
+ define_method prefix_name.to_s.gsub(/[A-Z]/,'_\0').downcase[1..-1].to_sym do |color_name|
85
+ if color_code = shortcuts[color_name]
86
+ return to_s if Paint.mode.zero?
87
+ color_code + to_s + NOTHING
88
+ end
89
+ end
90
+ end
91
+
92
+ prefix
93
+ end
94
+
95
+ mod
96
+ end
97
+ end
98
+ end
@@ -0,0 +1,3 @@
1
+ module Paint
2
+ SHORTCUTS_VERSION = '1.0.0'
3
+ end
@@ -0,0 +1,29 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ require File.dirname(__FILE__) + "/lib/paint/shortcuts_version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "paint-shortcuts"
7
+ s.version = Paint::SHORTCUTS_VERSION
8
+ s.authors = ["Jan Lelis"]
9
+ s.email = "mail@janlelis.de"
10
+ s.homepage = "https://github.com/janlelis/paint"
11
+ s.summary = "Terminal painter! Shortcut extension."
12
+ s.description = "Extends the paint gem to support custom color shortcuts."
13
+ s.license = 'MIT'
14
+ s.files = %w[
15
+ paint-shortcuts.gemspec
16
+ lib/paint/shortcuts.rb
17
+ lib/paint/shortcuts_version.rb
18
+ ]
19
+ s.extra_rdoc_files = %w[
20
+ README.rdoc
21
+ SHORTCUTS.rdoc
22
+ CHANGELOG.rdoc
23
+ MIT-LICENSE.txt
24
+ ]
25
+
26
+ s.required_ruby_version = '>= 1.9.3'
27
+ s.add_dependency 'paint', '~> 1.0'
28
+ s.add_development_dependency 'rspec', '~> 3.2'
29
+ end
metadata ADDED
@@ -0,0 +1,82 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: paint-shortcuts
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Jan Lelis
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-03-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: paint
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.2'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.2'
41
+ description: Extends the paint gem to support custom color shortcuts.
42
+ email: mail@janlelis.de
43
+ executables: []
44
+ extensions: []
45
+ extra_rdoc_files:
46
+ - README.rdoc
47
+ - SHORTCUTS.rdoc
48
+ - CHANGELOG.rdoc
49
+ - MIT-LICENSE.txt
50
+ files:
51
+ - CHANGELOG.rdoc
52
+ - MIT-LICENSE.txt
53
+ - README.rdoc
54
+ - SHORTCUTS.rdoc
55
+ - lib/paint/shortcuts.rb
56
+ - lib/paint/shortcuts_version.rb
57
+ - paint-shortcuts.gemspec
58
+ homepage: https://github.com/janlelis/paint
59
+ licenses:
60
+ - MIT
61
+ metadata: {}
62
+ post_install_message:
63
+ rdoc_options: []
64
+ require_paths:
65
+ - lib
66
+ required_ruby_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: 1.9.3
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ requirements: []
77
+ rubyforge_project:
78
+ rubygems_version: 2.4.6
79
+ signing_key:
80
+ specification_version: 4
81
+ summary: Terminal painter! Shortcut extension.
82
+ test_files: []