spiffup 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +3 -0
- data/Gemfile +2 -0
- data/LICENSE.txt +21 -0
- data/README.md +62 -0
- data/Rakefile +9 -0
- data/lib/spiffup/string_color.rb +15 -0
- data/lib/spiffup/string_tags.rb +16 -0
- data/lib/spiffup/term_color.rb +34 -0
- data/lib/spiffup/version.rb +9 -0
- data/lib/spiffup.rb +13 -0
- data/spiffup.gemspec +23 -0
- metadata +97 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 23845e2c21b57bc74f6cf81f3efa544851bbaa30
|
4
|
+
data.tar.gz: f04543f5bbfc64d8dd9417e0e21135f21b58ca96
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7fc3f2759d1a3970ed90153a7beaf3b70c7e906aa0f2d19c758b61d309ad77ef1966dd314000ea51c5e04a50c6564306647da6ecbe236ae0c342e0954828a84d
|
7
|
+
data.tar.gz: 98d480c1ee8a86ac4b670b0a7d663fcffd119f2eda0dda07d4988c2c05f26b95f93ac91c96726f2a63bf65fdeb0c782f15ce0cbf982252c7c9361999c7796796
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Paul Duncan
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
# Spiffup
|
2
|
+
|
3
|
+
Make your stdout shine
|
4
|
+
|
5
|
+
## Presentation
|
6
|
+
|
7
|
+
This library provides means to 'prettify' output in Ruby.
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
### Gemfile
|
12
|
+
```ruby
|
13
|
+
gem 'spiffup'
|
14
|
+
```
|
15
|
+
|
16
|
+
### Terminal
|
17
|
+
```bash
|
18
|
+
gem install -V spiffup
|
19
|
+
```
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
### Output colorization via tags
|
24
|
+
|
25
|
+
Output can be colorized simply by adding tags within the text:
|
26
|
+
The *RST* tag can be used to reset the color.
|
27
|
+
Bold text can be produced by using the 'BXXX' tag constants (BGREEN, BRED, ...).
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
require 'spiffup'
|
31
|
+
puts "This is #{Spiffup::GREEN}green#{Spiffup::RST}"
|
32
|
+
```
|
33
|
+
|
34
|
+
### Direct string colorization
|
35
|
+
|
36
|
+
Entire strings can be directly colorized by using the monkey-patched methods _.red_, _.green_, _.blue_, ...
|
37
|
+
Also available are _.bred_, _.bgreen_, _.bblue_ methods for *bold* text.
|
38
|
+
|
39
|
+
```ruby
|
40
|
+
require 'spiffup'
|
41
|
+
currency = 'CHF'
|
42
|
+
amount = 52.4
|
43
|
+
price = "#{amount} #{currency}"
|
44
|
+
puts "Total price: #{price.green}"
|
45
|
+
```
|
46
|
+
|
47
|
+
### Available Colors
|
48
|
+
|
49
|
+
The 8 classical terminal colors are available as the following:
|
50
|
+
|
51
|
+
* black
|
52
|
+
* red
|
53
|
+
* green
|
54
|
+
* brown
|
55
|
+
* blue
|
56
|
+
* magenta
|
57
|
+
* cyan
|
58
|
+
* gray
|
59
|
+
|
60
|
+
## License
|
61
|
+
|
62
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# Spiffup
|
2
|
+
# by Eresse <eresse@eresse.net>
|
3
|
+
|
4
|
+
# Internal Includes
|
5
|
+
require 'spiffup/term_color'
|
6
|
+
|
7
|
+
# Monkey-patch String Class
|
8
|
+
class String
|
9
|
+
|
10
|
+
# Attach Color Methods
|
11
|
+
Spiffup::TermColor::COLS.each do |col, idx|
|
12
|
+
define_method(col) { "#{Spiffup::TermColor::col idx}#{self}#{Spiffup::TermColor::RST}" }
|
13
|
+
define_method("b#{col}") { "#{Spiffup::TermColor::col idx, true}#{self}#{Spiffup::TermColor::RST}" }
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# Spiffup
|
2
|
+
# by Eresse <eresse@eresse.net>
|
3
|
+
|
4
|
+
# Internal Includes
|
5
|
+
require 'spiffup/term_color'
|
6
|
+
|
7
|
+
# Spiffup Module
|
8
|
+
module Spiffup
|
9
|
+
|
10
|
+
# Define String Tags
|
11
|
+
RST = TermColor::RST
|
12
|
+
TermColor::COLS.each do |col, idx|
|
13
|
+
const_set col.upcase, TermColor.col(idx)
|
14
|
+
const_set "B#{col.upcase}", TermColor.col(idx, true)
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# Spiffup
|
2
|
+
# by Eresse <eresse@eresse.net>
|
3
|
+
|
4
|
+
# Spiffup Module
|
5
|
+
module Spiffup
|
6
|
+
|
7
|
+
# Term Color Module
|
8
|
+
module TermColor
|
9
|
+
|
10
|
+
# Colors
|
11
|
+
COLS = {
|
12
|
+
black: 0,
|
13
|
+
red: 1,
|
14
|
+
green: 2,
|
15
|
+
brown: 3,
|
16
|
+
blue: 4,
|
17
|
+
magenta: 5,
|
18
|
+
cyan: 6,
|
19
|
+
gray: 7
|
20
|
+
}
|
21
|
+
|
22
|
+
# Reset
|
23
|
+
RST = "\033[0m"
|
24
|
+
|
25
|
+
# Generate Color
|
26
|
+
# Generates a Terminal Color Code for a given color
|
27
|
+
# @param [Fixnum] x The desired color-index
|
28
|
+
# @param [boolean] bold When true, generate bold effect
|
29
|
+
# @return [String] A Terminal Color Code
|
30
|
+
def self.col x, bold = false
|
31
|
+
"\033[#{bold ? 1 : 0};#{30 + x}m"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/lib/spiffup.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# Spiffup
|
2
|
+
# by Eresse <eresse@eresse.net>
|
3
|
+
|
4
|
+
# Internal Includes
|
5
|
+
require 'spiffup/version'
|
6
|
+
require 'spiffup/term_color'
|
7
|
+
require 'spiffup/string_tags'
|
8
|
+
require 'spiffup/string_color'
|
9
|
+
|
10
|
+
# Spiffup Module
|
11
|
+
# Root Module for Spiffup
|
12
|
+
module Spiffup
|
13
|
+
end
|
data/spiffup.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'spiffup/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'spiffup'
|
8
|
+
spec.version = Spiffup::VERSION
|
9
|
+
spec.authors = ['Eresse']
|
10
|
+
spec.email = ['eresse@eresse.net']
|
11
|
+
|
12
|
+
spec.summary = 'Make your stdout shine'
|
13
|
+
spec.description = 'Provides means to \'prettify\' output in Ruby'
|
14
|
+
spec.homepage = 'http://redmine.eresse.net/projects/spiffup'
|
15
|
+
spec.license = 'MIT'
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.require_paths = ['lib']
|
19
|
+
|
20
|
+
spec.add_development_dependency 'bundler'
|
21
|
+
spec.add_development_dependency 'rake'
|
22
|
+
spec.add_runtime_dependency 'minitest'
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: spiffup
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Eresse
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-02-01 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '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'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: Provides means to 'prettify' output in Ruby
|
56
|
+
email:
|
57
|
+
- eresse@eresse.net
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- Gemfile
|
64
|
+
- LICENSE.txt
|
65
|
+
- README.md
|
66
|
+
- Rakefile
|
67
|
+
- lib/spiffup.rb
|
68
|
+
- lib/spiffup/string_color.rb
|
69
|
+
- lib/spiffup/string_tags.rb
|
70
|
+
- lib/spiffup/term_color.rb
|
71
|
+
- lib/spiffup/version.rb
|
72
|
+
- spiffup.gemspec
|
73
|
+
homepage: http://redmine.eresse.net/projects/spiffup
|
74
|
+
licenses:
|
75
|
+
- MIT
|
76
|
+
metadata: {}
|
77
|
+
post_install_message:
|
78
|
+
rdoc_options: []
|
79
|
+
require_paths:
|
80
|
+
- lib
|
81
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
requirements: []
|
92
|
+
rubyforge_project:
|
93
|
+
rubygems_version: 2.6.10
|
94
|
+
signing_key:
|
95
|
+
specification_version: 4
|
96
|
+
summary: Make your stdout shine
|
97
|
+
test_files: []
|