tco 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/bin/tco +10 -0
- data/lib/tco.rb +14 -9
- data/lib/tco/colouring.rb +27 -15
- data/lib/tco/version.rb +1 -1
- metadata +13 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7855a328ecfda6385c65b4ad9ef8945d2ddb07e9
|
4
|
+
data.tar.gz: 94967d9ed4d9fbe718ff0477b1bbc8e36020a95c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 123aa1226971a310e86d69e258a742f5cc04855a9962bbfb794b81ba5b4a2d2d82bea11dfcee1468755c34df30526b6fe59e63646f0b4ff648747aabe09816bb
|
7
|
+
data.tar.gz: d7df16214c894953b7f16ef3962c884cb6195edff262ec060fae0e00783167affb6281ea5f6a0f6ac79c83c911f679a8cc5e4d5f62787eadd504d339e357aa5b
|
data/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
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-
|
4
|
+
[![Inline docs](http://inch-ci.org/github/pazdera/tco.png)](http://inch-ci.org/github/pazdera/tco)
|
5
5
|
[![Build Status][BS img]][Build Status]
|
6
6
|
[Build Status]: https://travis-ci.org/pazdera/tco
|
7
7
|
[BS img]: https://travis-ci.org/pazdera/tco.png
|
data/bin/tco
CHANGED
@@ -60,6 +60,11 @@ parser = OptionParser.new do |opts|
|
|
60
60
|
options[:display] = true
|
61
61
|
end
|
62
62
|
|
63
|
+
desc = "Show the matching colour from the current palette for this spec"
|
64
|
+
opts.on("-m COLOUR", "--match COLOUR", desc) do |colour|
|
65
|
+
options[:match] = colour
|
66
|
+
end
|
67
|
+
|
63
68
|
opts.on("-p PALETTE", "--force-palette PALETTE",
|
64
69
|
"Force either ansi or extended palette") do |palette|
|
65
70
|
options[:palette] = palette
|
@@ -100,6 +105,11 @@ begin
|
|
100
105
|
Kernel.exit! 0
|
101
106
|
end
|
102
107
|
|
108
|
+
if options.has_key? :match
|
109
|
+
Tco::show_matching_colour options[:match]
|
110
|
+
Kernel.exit! 0
|
111
|
+
end
|
112
|
+
|
103
113
|
if options.has_key? :style
|
104
114
|
style = Tco::get_style options[:style]
|
105
115
|
else
|
data/lib/tco.rb
CHANGED
@@ -101,6 +101,19 @@ module Tco
|
|
101
101
|
@colouring = Colouring.new config
|
102
102
|
end
|
103
103
|
|
104
|
+
def self.show_matching_colour(colour_spec)
|
105
|
+
colour = @colouring.get_colour_instance colour_spec
|
106
|
+
colour_index = @colouring.palette.match_colour colour
|
107
|
+
|
108
|
+
fg = @colouring.get_best_font_colour colour
|
109
|
+
bg = @colouring.palette.colours[colour_index]
|
110
|
+
|
111
|
+
puts Tco::colour fg, bg, " "*9
|
112
|
+
puts Tco::colour fg, bg, colour_index.to_s.center(9)
|
113
|
+
puts Tco::colour fg, bg, bg.to_s.center(9)
|
114
|
+
puts Tco::colour fg, bg, " "*9
|
115
|
+
end
|
116
|
+
|
104
117
|
def self.display_palette
|
105
118
|
# TODO: Might be worth sorting, so the pallete is easier to navigate
|
106
119
|
colours = @colouring.palette.colours
|
@@ -117,15 +130,7 @@ module Tco
|
|
117
130
|
# Prepare the squares for the line
|
118
131
|
square_styles = []
|
119
132
|
squares.times do
|
120
|
-
|
121
|
-
white = Tco::Colour.new([255,255,255])
|
122
|
-
|
123
|
-
font_colour = black
|
124
|
-
if colours[c].is_a?(Colour) && (colours[c] - black).abs < (colours[c] - white).abs
|
125
|
-
font_colour = white
|
126
|
-
end
|
127
|
-
|
128
|
-
square_styles.push [c, font_colour, colours[c]]
|
133
|
+
square_styles.push [c, @colouring.get_best_font_colour(colours[c]), colours[c]]
|
129
134
|
c += 1
|
130
135
|
end
|
131
136
|
|
data/lib/tco/colouring.rb
CHANGED
@@ -108,6 +108,33 @@ module Tco
|
|
108
108
|
@output_type = output_type
|
109
109
|
end
|
110
110
|
|
111
|
+
def get_best_font_colour(background)
|
112
|
+
black = Tco::Colour.new([0,0,0])
|
113
|
+
white = Tco::Colour.new([255,255,255])
|
114
|
+
|
115
|
+
if background.is_a?(Colour) &&
|
116
|
+
(background - black).abs < (background - white).abs
|
117
|
+
return white
|
118
|
+
end
|
119
|
+
|
120
|
+
black
|
121
|
+
end
|
122
|
+
|
123
|
+
def get_colour_instance(value)
|
124
|
+
case
|
125
|
+
when value.is_a?(String)
|
126
|
+
resolve_colour_def value
|
127
|
+
when value.is_a?(Array)
|
128
|
+
Colour.new value
|
129
|
+
when value.is_a?(Colour) || value.is_a?(Unknown)
|
130
|
+
value
|
131
|
+
when value == nil
|
132
|
+
nil
|
133
|
+
else
|
134
|
+
raise "Colour value type '#{value.class}' not supported."
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
111
138
|
private
|
112
139
|
def e(seq)
|
113
140
|
if @output_type == :raw
|
@@ -236,20 +263,5 @@ module Tco
|
|
236
263
|
end
|
237
264
|
end
|
238
265
|
end
|
239
|
-
|
240
|
-
def get_colour_instance(value)
|
241
|
-
case
|
242
|
-
when value.is_a?(String)
|
243
|
-
resolve_colour_def value
|
244
|
-
when value.is_a?(Array)
|
245
|
-
Colour.new value
|
246
|
-
when value.is_a?(Colour) || value.is_a?(Unknown)
|
247
|
-
value
|
248
|
-
when value == nil
|
249
|
-
nil
|
250
|
-
else
|
251
|
-
raise "Colour value type '#{value.class}' not supported."
|
252
|
-
end
|
253
|
-
end
|
254
266
|
end
|
255
267
|
end
|
data/lib/tco/version.rb
CHANGED
metadata
CHANGED
@@ -1,55 +1,55 @@
|
|
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.4
|
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-10-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - ~>
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '1.5'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - ~>
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.5'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
description: |-
|
@@ -63,8 +63,8 @@ executables:
|
|
63
63
|
extensions: []
|
64
64
|
extra_rdoc_files: []
|
65
65
|
files:
|
66
|
-
- .gitignore
|
67
|
-
- .travis.yml
|
66
|
+
- ".gitignore"
|
67
|
+
- ".travis.yml"
|
68
68
|
- CHANGELOG.md
|
69
69
|
- Gemfile
|
70
70
|
- LICENSE.txt
|
@@ -100,17 +100,17 @@ require_paths:
|
|
100
100
|
- lib
|
101
101
|
required_ruby_version: !ruby/object:Gem::Requirement
|
102
102
|
requirements:
|
103
|
-
- -
|
103
|
+
- - ">="
|
104
104
|
- !ruby/object:Gem::Version
|
105
105
|
version: '0'
|
106
106
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
|
-
- -
|
108
|
+
- - ">="
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0'
|
111
111
|
requirements: []
|
112
112
|
rubyforge_project: tco
|
113
|
-
rubygems_version: 2.
|
113
|
+
rubygems_version: 2.2.2
|
114
114
|
signing_key:
|
115
115
|
specification_version: 4
|
116
116
|
summary: A tool and a library for terminal output colouring
|