tone 0.0.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/README.adoc +64 -8
- data/lib/tone/aliaser.rb +1 -4
- data/lib/tone/client.rb +2 -0
- data/lib/tone/configuration/loader.rb +3 -2
- data/lib/tone/rspec/matchers/have_color.rb +20 -0
- data/lib/tone.rb +4 -1
- data/tone.gemspec +1 -1
- data.tar.gz.sig +0 -0
- metadata +4 -3
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9545daf90651afc61d7c2746db9b12e99cdebf768f1930d5d7933b01573dc301
|
4
|
+
data.tar.gz: 124e32e3aa2201636dc3a6a269c10145dfa5e8c41b7c0b6597ef8254cf631082
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9894a60b8dc02cf1624904dd802f3f824b9ef326b1632beca7c763ca131ea686032296d6d33aa49b3e5a1cfb2d1c72c4d889464d95bf46150bf8dcada2e47ee1
|
7
|
+
data.tar.gz: e81e5dfa92d3e42b789759fa0ea481abd9a3e785b3a0eb72d2de9d4be685e348bc6e5b5363f982c24435f68cf2f6cbe63748ccce86e5bee4d4ad395f75c40da4
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/README.adoc
CHANGED
@@ -4,6 +4,7 @@
|
|
4
4
|
|
5
5
|
:amazing_print_link: link:https://github.com/amazing-print/amazing_print[Amazing Print]
|
6
6
|
:pattern_matching_link: link:https://alchemists.io/articles/ruby_pattern_matching[pattern matching]
|
7
|
+
:rspec_link: link:https://rspec.info[RSpec]
|
7
8
|
|
8
9
|
= Tone
|
9
10
|
|
@@ -18,31 +19,45 @@ toc::[]
|
|
18
19
|
* Provides aliasing of color configurations.
|
19
20
|
* Provides quick access to default and aliased styles.
|
20
21
|
|
22
|
+
== Screenshots
|
23
|
+
|
24
|
+
image::https://alchemists.io/images/projects/tone/screenshot.png[A screenshot of colors,width=200,height=900,role=focal_point]
|
25
|
+
|
21
26
|
== Requirements
|
22
27
|
|
23
28
|
. link:https://www.ruby-lang.org[Ruby].
|
24
29
|
|
25
30
|
== Setup
|
26
31
|
|
27
|
-
To install, run:
|
32
|
+
To install _with_ security, run:
|
28
33
|
|
29
|
-
[source,
|
34
|
+
[source,bash]
|
35
|
+
----
|
36
|
+
# 💡 Skip this line if you already have the public certificate installed.
|
37
|
+
gem cert --add <(curl --compressed --location https://alchemists.io/gems.pem)
|
38
|
+
gem install tone --trust-policy HighSecurity
|
39
|
+
----
|
40
|
+
|
41
|
+
To install _without_ security, run:
|
42
|
+
|
43
|
+
[source,bash]
|
30
44
|
----
|
31
45
|
gem install tone
|
32
46
|
----
|
33
47
|
|
34
|
-
You can also add the gem directly to your project
|
48
|
+
You can also add the gem directly to your project:
|
35
49
|
|
36
|
-
[source,
|
50
|
+
[source,bash]
|
37
51
|
----
|
38
52
|
bundle add tone
|
39
53
|
----
|
40
54
|
|
41
55
|
Once the gem is installed, you only need to require it:
|
42
56
|
|
43
|
-
|
57
|
+
[source,ruby]
|
58
|
+
----
|
44
59
|
require "tone"
|
45
|
-
|
60
|
+
----
|
46
61
|
|
47
62
|
== Usage
|
48
63
|
|
@@ -369,6 +384,47 @@ tone.get_alias :bogus
|
|
369
384
|
# Invalid alias or default: :bogus. (Tone::Error)
|
370
385
|
----
|
371
386
|
|
387
|
+
=== Testing
|
388
|
+
|
389
|
+
When using this gem in your project, you might find it convenient to use the `have_color` {rspec_link} matcher. This matcher is optional and _must be manually required_ for use in your spec helper:
|
390
|
+
|
391
|
+
[source,ruby]
|
392
|
+
----
|
393
|
+
# spec_helper.rb
|
394
|
+
require "tone/rspec/matchers/have_color"
|
395
|
+
----
|
396
|
+
|
397
|
+
Once required, you can leverage the matcher in any spec as follows:
|
398
|
+
|
399
|
+
[source,ruby]
|
400
|
+
----
|
401
|
+
RSpec.describe DemoPresenter do
|
402
|
+
subject(:presenter) { DemoPresenter.new color: }
|
403
|
+
|
404
|
+
let(:color) { Tone.new }
|
405
|
+
|
406
|
+
describe "#to_s" do
|
407
|
+
it "renders colored text" do
|
408
|
+
expect(presenter.to_s).to have_color(color, ["Test 0.0.0: A test.", :bold])
|
409
|
+
end
|
410
|
+
end
|
411
|
+
end
|
412
|
+
----
|
413
|
+
|
414
|
+
The first argument _must be an instanced of Tone_ because you might have custom aliases which must be known in order to validate your spec. All subsequent arguments (one to many) that follow after the first argument can be a list of decoded tuples as would normally be answered by `Tone#decode`.
|
415
|
+
|
416
|
+
In situations where the spec fails, you'll get a formatted error so you can quickly fix as necessary:
|
417
|
+
|
418
|
+
....
|
419
|
+
expected "\e[37mtest\e[0m\n" to have color decoded as:
|
420
|
+
["text", :blue],
|
421
|
+
["\n"]
|
422
|
+
|
423
|
+
but actually is:
|
424
|
+
["test", :white],
|
425
|
+
["\n"]
|
426
|
+
....
|
427
|
+
|
372
428
|
=== Guidelines
|
373
429
|
|
374
430
|
The following are worth considering, when using this gem, to help keep your implementation consistent.
|
@@ -412,14 +468,14 @@ cd tone
|
|
412
468
|
bin/setup
|
413
469
|
----
|
414
470
|
|
415
|
-
You use the IRB console for direct access to all objects:
|
471
|
+
You can use the IRB console for direct access to all objects:
|
416
472
|
|
417
473
|
[source,bash]
|
418
474
|
----
|
419
475
|
bin/console
|
420
476
|
----
|
421
477
|
|
422
|
-
Lastly, there is a `bin/show` script which
|
478
|
+
Lastly, there is a `bin/show` script which displays the default styles for quick visual reference. This is the same script used to generate the screenshots shown at the top of this document.
|
423
479
|
|
424
480
|
[source,bash]
|
425
481
|
----
|
data/lib/tone/aliaser.rb
CHANGED
@@ -46,10 +46,7 @@ module Tone
|
|
46
46
|
end
|
47
47
|
|
48
48
|
def check_duplicate key
|
49
|
-
|
50
|
-
|
51
|
-
fail Error, "Duplicate alias detected (already exists): #{kind}." if custom.key? key
|
52
|
-
fail Error, "Alias mustn't duplicate (override) default: #{kind}." if defaults.key? key
|
49
|
+
fail Error, "Alias mustn't duplicate (override) default: #{key.inspect}." if defaults.key? key
|
53
50
|
end
|
54
51
|
|
55
52
|
def check_style key, style
|
data/lib/tone/client.rb
CHANGED
@@ -1,16 +1,17 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require "pathname"
|
3
4
|
require "yaml"
|
4
5
|
|
5
6
|
module Tone
|
6
7
|
module Configuration
|
7
8
|
# Loads the default configuration into memory as a frozen hash.
|
8
9
|
class Loader
|
9
|
-
def initialize path
|
10
|
+
def initialize path = Pathname("#{__dir__}/defaults.yml")
|
10
11
|
@path = path
|
11
12
|
end
|
12
13
|
|
13
|
-
def call = YAML.
|
14
|
+
def call = YAML.safe_load_file path, symbolize_names: true, freeze: true
|
14
15
|
|
15
16
|
private
|
16
17
|
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec::Matchers.define :have_color do |color, *expected|
|
4
|
+
match do |actual|
|
5
|
+
fail ArgumentError, "First argument must be a color instance." unless color.respond_to? :decode
|
6
|
+
|
7
|
+
@decode = color.decode actual
|
8
|
+
@decode == expected
|
9
|
+
end
|
10
|
+
|
11
|
+
failure_message do |actual|
|
12
|
+
<<~MESSAGE
|
13
|
+
expected #{actual.inspect} to have color decoded as:
|
14
|
+
#{expected.map(&:inspect).join(",\n")}
|
15
|
+
|
16
|
+
but actually is:
|
17
|
+
#{@decode.map(&:inspect).join(",\n")}
|
18
|
+
MESSAGE
|
19
|
+
end
|
20
|
+
end
|
data/lib/tone.rb
CHANGED
data/tone.gemspec
CHANGED
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tone
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brooke Kuhlmann
|
@@ -35,7 +35,7 @@ cert_chain:
|
|
35
35
|
3n5C8/6Zh9DYTkpcwPSuIfAga6wf4nXc9m6JAw8AuMLaiWN/r/2s4zJsUHYERJEu
|
36
36
|
gZGm4JqtuSg8pYjPeIJxS960owq+SfuC+jxqmRA54BisFCv/0VOJi7tiJVY=
|
37
37
|
-----END CERTIFICATE-----
|
38
|
-
date: 2023-04-
|
38
|
+
date: 2023-04-22 00:00:00.000000000 Z
|
39
39
|
dependencies:
|
40
40
|
- !ruby/object:Gem::Dependency
|
41
41
|
name: refinements
|
@@ -84,6 +84,7 @@ files:
|
|
84
84
|
- lib/tone/decoder.rb
|
85
85
|
- lib/tone/encoder.rb
|
86
86
|
- lib/tone/error.rb
|
87
|
+
- lib/tone/rspec/matchers/have_color.rb
|
87
88
|
- tone.gemspec
|
88
89
|
homepage: https://alchemists.io/projects/tone
|
89
90
|
licenses:
|
@@ -111,7 +112,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
111
112
|
- !ruby/object:Gem::Version
|
112
113
|
version: '0'
|
113
114
|
requirements: []
|
114
|
-
rubygems_version: 3.4.
|
115
|
+
rubygems_version: 3.4.12
|
115
116
|
signing_key:
|
116
117
|
specification_version: 4
|
117
118
|
summary: A customizable ANSI text colorizer for your terminal.
|
metadata.gz.sig
CHANGED
Binary file
|