tco 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +15 -0
- data/CHANGELOG.md +20 -0
- data/README.md +18 -15
- data/gemrc +2 -0
- data/lib/tco.rb +1 -1
- data/lib/tco/colouring.rb +4 -1
- data/lib/tco/config.rb +7 -3
- data/lib/tco/version.rb +1 -1
- data/spec/lib_spec.rb +142 -0
- data/tco.gemspec +1 -0
- metadata +21 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 68e7ffb606d28f3c346906e055d3e7ccf36af5e5
|
4
|
+
data.tar.gz: f6874a5cc654e36e9eb3d26b94d0fc876cd0a6b4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4fc1871dd26de790f23bdd58bcd44881f3dad0a3896139fd735896745eb32d48bf96015f3aa2769b6fb71cebca84bd5930d1c96f0a1a914cc5e2d66853030b7f
|
7
|
+
data.tar.gz: 62efa2e47ad194e7dcab4f870c3809ed1f0470c06387b4457188ac4b46780562baf6374c0f72d54dc2f770dde0c11394ce48774ec814b2da95fe7a41be89aa51
|
data/.travis.yml
ADDED
data/CHANGELOG.md
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
## 0.1.2 (2014-05-10)
|
2
|
+
|
3
|
+
Features:
|
4
|
+
|
5
|
+
- added a config option to globally disable colouring
|
6
|
+
|
7
|
+
Bugfixes:
|
8
|
+
|
9
|
+
- the 'options' section is now handled properly
|
10
|
+
- a few docs improvements
|
11
|
+
|
12
|
+
## 0.1.1 (2014-04-24)
|
13
|
+
|
14
|
+
Features:
|
15
|
+
|
16
|
+
- added Tco#configure (a simpler way to change the configuration)
|
17
|
+
|
18
|
+
Bugfixes:
|
19
|
+
|
20
|
+
- the `-d` option works again
|
data/README.md
CHANGED
@@ -1,6 +1,10 @@
|
|
1
1
|
# tco - terminal colours made simple
|
2
2
|
|
3
3
|
[![Gem Version](https://badge.fury.io/rb/tco.png)](http://badge.fury.io/rb/tco)
|
4
|
+
[![Inline docs](http://inch-pages.github.io/github/pazdera/tco.png)](http://inch-pages.github.io/github/pazdera/tco)
|
5
|
+
[![Build Status][BS img]][Build Status]
|
6
|
+
[Build Status]: https://travis-ci.org/pazdera/tco
|
7
|
+
[BS img]: https://travis-ci.org/pazdera/tco.png
|
4
8
|
|
5
9
|
The purpose of the **tco** gem is to make colouring in the terminal as
|
6
10
|
convenient and as simple as possible. It provides a library for your Ruby gems
|
@@ -33,7 +37,7 @@ string into 15 parts. Check out the following examples.
|
|
33
37
|
The `tco` terminal utility allows you to do the simple things you might need
|
34
38
|
in your bash scripts:
|
35
39
|
|
36
|
-
[![Using tco to colour text](http://
|
40
|
+
[![Using tco to colour text](http://broken.build/assets/images/posts/tco-terminal.png)](http://broken.build/assets/images/posts/tco-terminal.png)
|
37
41
|
|
38
42
|
However, using `tco` directly from Ruby gives you much more flexibility. The
|
39
43
|
following short piece of code will draw a rainbow inside your terminal:
|
@@ -48,7 +52,7 @@ rainbow = ["#622e90", "#2d3091", "#00aaea", "#02a552", "#fdea22", "#eb443b", "#f
|
|
48
52
|
end
|
49
53
|
```
|
50
54
|
|
51
|
-
[![tco showing a simple rainbow](http://
|
55
|
+
[![tco showing a simple rainbow](http://broken.build/assets/images/posts/tco-rainbow.png)](http://broken.build/assets/images/posts/tco-rainbow.png)
|
52
56
|
|
53
57
|
And if you add a bit of `rmagick` to the equation, you can even render whole
|
54
58
|
images in your terminal with no more than 10 lines of code.
|
@@ -64,7 +68,7 @@ Magick::Image.read("tux.png")[0].each_pixel do |pixel, col, row|
|
|
64
68
|
end
|
65
69
|
```
|
66
70
|
|
67
|
-
[![Tux drawn with tco](http://
|
71
|
+
[![Tux drawn with tco](http://broken.build/assets/images/posts/tco-tux.png)](http://broken.build/assets/images/posts/tco-tux.png)
|
68
72
|
|
69
73
|
These were just the basic things you can do with `tco`. There are many more
|
70
74
|
options and features available, many of them are described in the **Usage**
|
@@ -115,17 +119,15 @@ top of the user and system config files.
|
|
115
119
|
```ruby
|
116
120
|
require "tco"
|
117
121
|
|
118
|
-
|
119
|
-
|
120
|
-
tco_conf["
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
Tco::reconfigure tco_conf
|
122
|
+
Tco::configure do |tco_conf|
|
123
|
+
tco_conf.names["white"] = "#000"
|
124
|
+
tco_conf.styles["pass"] = {
|
125
|
+
"fg" => "#000",
|
126
|
+
"bg" => "#00ff00",
|
127
|
+
"bright" => false,
|
128
|
+
"underline" => false,
|
129
|
+
}
|
130
|
+
end
|
129
131
|
```
|
130
132
|
|
131
133
|
Apart from that, the library then contains a few more advanced things which
|
@@ -211,7 +213,8 @@ configuration file would look like this:
|
|
211
213
|
```yaml
|
212
214
|
# This is unnecessary (extended palette is enabled by default).
|
213
215
|
# However, you can set this to ansi if you use an older terminal.
|
214
|
-
|
216
|
+
options:
|
217
|
+
palette: "extended"
|
215
218
|
|
216
219
|
colour_values:
|
217
220
|
"@0": "#3b3b3b"
|
data/gemrc
ADDED
data/lib/tco.rb
CHANGED
data/lib/tco/colouring.rb
CHANGED
@@ -34,6 +34,7 @@ module Tco
|
|
34
34
|
def initialize(configuration)
|
35
35
|
@palette = Palette.new configuration.options["palette"]
|
36
36
|
@output_type = configuration.options["output"]
|
37
|
+
@disabled = configuration.options["disabled"]
|
37
38
|
|
38
39
|
configuration.colour_values.each do |id, value|
|
39
40
|
@palette.set_colour_value(parse_colour_id(id), parse_rgb_value(value))
|
@@ -57,7 +58,9 @@ module Tco
|
|
57
58
|
# line). This is due to some problems I've been having with some
|
58
59
|
# terminal emulators not handling multi-line coloured sequences well.
|
59
60
|
def decorate(string, (fg, bg, bright, underline))
|
60
|
-
|
61
|
+
if (!STDOUT.isatty) || @output_type == :raw || @disabled
|
62
|
+
return string
|
63
|
+
end
|
61
64
|
|
62
65
|
fg = get_colour_instance fg
|
63
66
|
bg = get_colour_instance bg
|
data/lib/tco/config.rb
CHANGED
@@ -30,7 +30,8 @@ module Tco
|
|
30
30
|
def initialize(locations=[])
|
31
31
|
@options = {
|
32
32
|
"palette" => "extended",
|
33
|
-
"output" => "term"
|
33
|
+
"output" => "term",
|
34
|
+
"disabled" => false
|
34
35
|
}
|
35
36
|
@colour_values = {}
|
36
37
|
@names = {
|
@@ -67,10 +68,13 @@ module Tco
|
|
67
68
|
if conf_file.has_key? "options"
|
68
69
|
if conf_file["options"].is_a? Hash
|
69
70
|
conf_file["options"].each do |id, value|
|
70
|
-
@
|
71
|
+
@options[id] = case id
|
72
|
+
when "disabled" then parse_bool value
|
73
|
+
else value
|
74
|
+
end
|
71
75
|
end
|
72
76
|
else
|
73
|
-
raise "The '
|
77
|
+
raise "The 'options' config option must be a hash."
|
74
78
|
end
|
75
79
|
end
|
76
80
|
|
data/lib/tco/version.rb
CHANGED
data/spec/lib_spec.rb
ADDED
@@ -0,0 +1,142 @@
|
|
1
|
+
# tco - terminal colouring application and library
|
2
|
+
# Copyright (c) 2013, 2014 Radek Pazdera
|
3
|
+
|
4
|
+
# MIT License
|
5
|
+
|
6
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
7
|
+
# of this software and associated documentation files (the "Software"), to deal
|
8
|
+
# in the Software without restriction, including without limitation the rights
|
9
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
10
|
+
# copies of the Software, and to permit persons to whom the Software is
|
11
|
+
# furnished to do so, subject to the following conditions:
|
12
|
+
|
13
|
+
# The above copyright notice and this permission notice shall be included in
|
14
|
+
# all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
19
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
21
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
22
|
+
# THE SOFTWARE.
|
23
|
+
|
24
|
+
require "tco"
|
25
|
+
require "tco/config"
|
26
|
+
|
27
|
+
describe Tco do
|
28
|
+
describe "String class extension" do
|
29
|
+
before :all do
|
30
|
+
config = Tco::Config.new
|
31
|
+
config.options["palette"] = "extended"
|
32
|
+
config.options["output"] = "raw"
|
33
|
+
Tco::reconfigure config
|
34
|
+
end
|
35
|
+
|
36
|
+
describe "#fg" do
|
37
|
+
it "works with references" do
|
38
|
+
result = Tco::fg "@17", "London"
|
39
|
+
result.should eql "\e[38;5;17mLondon\e[0m"
|
40
|
+
end
|
41
|
+
|
42
|
+
it "works with rgb" do
|
43
|
+
result = Tco::fg "#00005F", "London"
|
44
|
+
result.should eql "\e[38;5;17mLondon\e[0m"
|
45
|
+
end
|
46
|
+
|
47
|
+
it "works with hex" do
|
48
|
+
result = Tco::fg "0x00005F", "London"
|
49
|
+
result.should eql "\e[38;5;17mLondon\e[0m"
|
50
|
+
end
|
51
|
+
|
52
|
+
it "works with names" do
|
53
|
+
result = Tco::fg "black", "London"
|
54
|
+
result.should eql "\e[38;5;0mLondon\e[0m"
|
55
|
+
end
|
56
|
+
|
57
|
+
it "fails with references lesser than zero" do
|
58
|
+
expect { Tco::fg "@-17", "London" }.to raise_error
|
59
|
+
end
|
60
|
+
|
61
|
+
it "fails with references bigger than 255" do
|
62
|
+
expect { Tco::fg "@256", "London" }.to raise_error
|
63
|
+
end
|
64
|
+
|
65
|
+
it "fails with bad hex colours" do
|
66
|
+
expect { Tco::fg "0x00ZZ00", "London" }.to raise_error
|
67
|
+
end
|
68
|
+
|
69
|
+
it "fails with bad colour names" do
|
70
|
+
expect { Tco::fg "apple", "London" }.to raise_error
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
describe "#bg" do
|
75
|
+
it "works with references" do
|
76
|
+
result = Tco::bg "@17", "London"
|
77
|
+
result.should eql "\e[48;5;17mLondon\e[0m"
|
78
|
+
end
|
79
|
+
|
80
|
+
it "works with rgb" do
|
81
|
+
result = Tco::bg "#00005F", "London"
|
82
|
+
result.should eql "\e[48;5;17mLondon\e[0m"
|
83
|
+
end
|
84
|
+
|
85
|
+
it "works with hex" do
|
86
|
+
result = Tco::bg "0x00005F", "London"
|
87
|
+
result.should eql "\e[48;5;17mLondon\e[0m"
|
88
|
+
end
|
89
|
+
|
90
|
+
it "works with names" do
|
91
|
+
result = Tco::bg "black", "London"
|
92
|
+
result.should eql "\e[48;5;0mLondon\e[0m"
|
93
|
+
end
|
94
|
+
|
95
|
+
it "fails with references lesser than zero" do
|
96
|
+
expect { Tco::bg "@-17", "London" }.to raise_error
|
97
|
+
end
|
98
|
+
|
99
|
+
it "fails with references bigger than 255" do
|
100
|
+
expect { Tco::bg "@256", "London" }.to raise_error
|
101
|
+
end
|
102
|
+
|
103
|
+
it "fails with bad hex colours" do
|
104
|
+
expect { Tco::bg "0x00ZZ00", "London" }.to raise_error
|
105
|
+
end
|
106
|
+
|
107
|
+
it "fails with bad colour names" do
|
108
|
+
expect { Tco::bg "apple", "London" }.to raise_error
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
describe "#bright" do
|
113
|
+
it "makes the fond bold" do
|
114
|
+
result = Tco::bright "London"
|
115
|
+
result.should eql "\e[1mLondon\e[0m"
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
describe "#underline" do
|
120
|
+
it "underlines the text" do
|
121
|
+
result = Tco::underline "London"
|
122
|
+
result.should eql "\e[4mLondon\e[0m"
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
it "can be combined" do
|
127
|
+
result = Tco::bg "@17", Tco::fg("@17", Tco::underline(Tco::bright "London"))
|
128
|
+
result.should eql "\e[48;5;17m\e[38;5;17m\e[4m\e[1mLondon\e[0m\e[0m\e[0m\e[0m"
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
describe "Configuration" do
|
133
|
+
it "disables colouring" do
|
134
|
+
Tco::configure do |c|
|
135
|
+
c.options["disabled"] = true
|
136
|
+
end
|
137
|
+
|
138
|
+
result = Tco::fg "#00005F", "London"
|
139
|
+
result.should eql "London"
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
data/tco.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tco
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Radek Pazdera
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-05-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - '>='
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
55
69
|
description: |-
|
56
70
|
tco is a commandline tool and also a Ruby module that
|
57
71
|
allows its users to easily colourize the terminal
|
@@ -64,6 +78,8 @@ extensions: []
|
|
64
78
|
extra_rdoc_files: []
|
65
79
|
files:
|
66
80
|
- .gitignore
|
81
|
+
- .travis.yml
|
82
|
+
- CHANGELOG.md
|
67
83
|
- Gemfile
|
68
84
|
- LICENSE.txt
|
69
85
|
- README.md
|
@@ -73,6 +89,7 @@ files:
|
|
73
89
|
- examples/tux.png
|
74
90
|
- examples/tux.rb
|
75
91
|
- examples/union_jack.rb
|
92
|
+
- gemrc
|
76
93
|
- lib/tco.rb
|
77
94
|
- lib/tco/colouring.rb
|
78
95
|
- lib/tco/config.rb
|
@@ -80,6 +97,7 @@ files:
|
|
80
97
|
- lib/tco/parser.rb
|
81
98
|
- lib/tco/style.rb
|
82
99
|
- lib/tco/version.rb
|
100
|
+
- spec/lib_spec.rb
|
83
101
|
- spec/parser_spec.rb
|
84
102
|
- spec/string_ext_spec.rb
|
85
103
|
- spec/tco_spec.rb
|
@@ -111,6 +129,7 @@ signing_key:
|
|
111
129
|
specification_version: 4
|
112
130
|
summary: A tool and a library for terminal output colouring
|
113
131
|
test_files:
|
132
|
+
- spec/lib_spec.rb
|
114
133
|
- spec/parser_spec.rb
|
115
134
|
- spec/string_ext_spec.rb
|
116
135
|
- spec/tco_spec.rb
|