cape-cod 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.md +22 -0
- data/README.md +65 -0
- data/Rakefile +16 -0
- data/lib/cape-cod/version.rb +5 -0
- data/lib/cape-cod.rb +81 -0
- metadata +98 -0
data/LICENSE.md
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Fuad Saud
|
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,65 @@
|
|
1
|
+
cape-cod
|
2
|
+
========
|
3
|
+
|
4
|
+
|
5
|
+
[]
|
6
|
+
(https://travis-ci.org/fuadsaud/cape-cod)
|
7
|
+
|
8
|
+
cape-cod makes it easy for you to append ANSI es<strong>CAPE-COD</strong>es - HAR! bet you didn't see
|
9
|
+
that coming; I know, I know, I'm a genius - to you strings.
|
10
|
+
|
11
|
+
### *Hey, but don't we have a plenty of gems that do exactly the same thing?*
|
12
|
+
|
13
|
+
**YES**. We can cite [colored](http://github.com/defunkt/colored) - by @defunkt -,
|
14
|
+
[colorize](http://github.com/fazibear/colorize) - by @fazibear -,
|
15
|
+
[term-ansicolor](http://github.com/flori/term-ansicolor), and so on...
|
16
|
+
They are really nice gems, and they solve the escape code problem in different manners
|
17
|
+
but they're all abandoned, some accumulating 3 years old issues.
|
18
|
+
|
19
|
+
My point with this gem is to implement many of the possible ways of appending ANSI escape
|
20
|
+
codes to strings (monkey patching, blocks, etc) and let the user choose whatever he likes.
|
21
|
+
I for instance prefer the colored's monkey patch approach, but for some people it
|
22
|
+
doesn't suit, so other options should be offered.
|
23
|
+
|
24
|
+
Please contribute!
|
25
|
+
|
26
|
+
## Installation
|
27
|
+
|
28
|
+
Add this line to your applications's gemfile:
|
29
|
+
|
30
|
+
```gem 'cape-cod'```
|
31
|
+
|
32
|
+
then run:
|
33
|
+
|
34
|
+
```bundle```
|
35
|
+
|
36
|
+
or simply:
|
37
|
+
|
38
|
+
```gem install cape-cod```
|
39
|
+
|
40
|
+
## Usage
|
41
|
+
|
42
|
+
```require 'cap-cod'```
|
43
|
+
|
44
|
+
You can include cape-cod in you String class:
|
45
|
+
|
46
|
+
```
|
47
|
+
class String; include CapeCod end
|
48
|
+
|
49
|
+
puts 'Praise R'hlor, for the night is dark and full of terrors'.red
|
50
|
+
```
|
51
|
+
|
52
|
+
or use it like this:
|
53
|
+
|
54
|
+
```
|
55
|
+
puts CapeCod.yellow('We all live in a yellow submarine!')
|
56
|
+
```
|
57
|
+
|
58
|
+
|
59
|
+
## Contributing
|
60
|
+
|
61
|
+
Check the guidelines at [CONTRIBUTING.md](CONTRIBUTING.md).
|
62
|
+
|
63
|
+
## License
|
64
|
+
|
65
|
+
Please refer to [LICENSE.md](LICENSE.md).
|
data/Rakefile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'rspec/core/rake_task'
|
3
|
+
|
4
|
+
RSpec::Core::RakeTask.new
|
5
|
+
|
6
|
+
desc 'Start an irb session with cape-cod loaded'
|
7
|
+
task :console do
|
8
|
+
if `which pry`.empty?
|
9
|
+
system('irb -rubygems --require ./lib/cape-cod.rb')
|
10
|
+
else
|
11
|
+
system('pry --require ./lib/cape-cod.rb')
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
desc 'run all specs'
|
16
|
+
task default: :spec
|
data/lib/cape-cod.rb
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
$LOAD_PATH.unshift File.expand_path(
|
4
|
+
File.join(File.dirname(__FILE__), '../lib'))
|
5
|
+
|
6
|
+
module CapeCod
|
7
|
+
|
8
|
+
require 'cape-cod/version'
|
9
|
+
|
10
|
+
ESCAPE_CODES = {
|
11
|
+
reset: 0,
|
12
|
+
bold: 1,
|
13
|
+
dark: 2,
|
14
|
+
italic: 3,
|
15
|
+
underline: 4,
|
16
|
+
blink: 5,
|
17
|
+
rapid_blink: 6,
|
18
|
+
negative: 7,
|
19
|
+
concealed: 8,
|
20
|
+
strikethrough: 9,
|
21
|
+
|
22
|
+
# Foreground color
|
23
|
+
black: 30,
|
24
|
+
red: 31,
|
25
|
+
green: 32,
|
26
|
+
yellow: 33,
|
27
|
+
blue: 34,
|
28
|
+
magenta: 35,
|
29
|
+
cyan: 36,
|
30
|
+
white: 37,
|
31
|
+
|
32
|
+
# Background color
|
33
|
+
on_black: 40,
|
34
|
+
on_red: 41,
|
35
|
+
on_green: 42,
|
36
|
+
on_yellow: 43,
|
37
|
+
on_blue: 44,
|
38
|
+
on_magenta: 45,
|
39
|
+
on_cyan: 46,
|
40
|
+
on_white: 47,
|
41
|
+
}.freeze
|
42
|
+
|
43
|
+
#
|
44
|
+
# Define helper methods for applying the escape codes
|
45
|
+
#
|
46
|
+
ESCAPE_CODES.each do |code, _|
|
47
|
+
define_method code do
|
48
|
+
CapeCod.apply_escape_sequence(code, self)
|
49
|
+
end
|
50
|
+
|
51
|
+
define_singleton_method code do |obj = '', &block|
|
52
|
+
string = obj.to_s
|
53
|
+
return CapeCod.escape_sequence_for(code) if string.empty? unless block
|
54
|
+
|
55
|
+
string += block.call if block
|
56
|
+
|
57
|
+
CapeCod.apply_escape_sequence(code, string)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
private
|
62
|
+
|
63
|
+
#
|
64
|
+
# Returns the ANSI escape sequence for a given escape +code+.
|
65
|
+
#
|
66
|
+
def self.escape_sequence_for(code)
|
67
|
+
"\e[#{ESCAPE_CODES.fetch(code)}m"
|
68
|
+
end
|
69
|
+
|
70
|
+
#
|
71
|
+
# Prepends the given +string+ with the ANSI escape sequence for the given
|
72
|
+
# escape +code+ and append a reset sequence.
|
73
|
+
#
|
74
|
+
def self.apply_escape_sequence(code, string)
|
75
|
+
sequence = escape_sequence_for(code)
|
76
|
+
|
77
|
+
return sequence unless string
|
78
|
+
|
79
|
+
sequence << string << escape_sequence_for(:reset)
|
80
|
+
end
|
81
|
+
end
|
metadata
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cape-cod
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Fuad Saud
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-04-27 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rake
|
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
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: pry
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rspec
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
description: Make your strings look fancy with ANSI escape codes.
|
63
|
+
email: fuadksd@gmail.com
|
64
|
+
executables: []
|
65
|
+
extensions: []
|
66
|
+
extra_rdoc_files: []
|
67
|
+
files:
|
68
|
+
- README.md
|
69
|
+
- Rakefile
|
70
|
+
- LICENSE.md
|
71
|
+
- lib/cape-cod/version.rb
|
72
|
+
- lib/cape-cod.rb
|
73
|
+
homepage: http://github.com/fuadsaud/cape-cod
|
74
|
+
licenses: []
|
75
|
+
post_install_message:
|
76
|
+
rdoc_options: []
|
77
|
+
require_paths:
|
78
|
+
- lib
|
79
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
80
|
+
none: false
|
81
|
+
requirements:
|
82
|
+
- - ! '>='
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
86
|
+
none: false
|
87
|
+
requirements:
|
88
|
+
- - ! '>='
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
requirements: []
|
92
|
+
rubyforge_project:
|
93
|
+
rubygems_version: 1.8.23
|
94
|
+
signing_key:
|
95
|
+
specification_version: 3
|
96
|
+
summary: Make your strings look fancy with ANSI escape codes.
|
97
|
+
test_files: []
|
98
|
+
has_rdoc: false
|