l43_color 0.1.0 → 0.1.1
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.
- checksums.yaml +4 -4
- data/README.md +58 -1
- data/bin/colorize +5 -0
- data/lib/l43/color/cli.rb +17 -0
- data/lib/l43/color/methods.rb +13 -0
- data/lib/l43/color/output.rb +39 -0
- data/lib/l43/color.rb +1 -1
- metadata +11 -6
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ebccf614bfe1b82244f4f6ace438402fac68bef6df5a4509c266bc45f415b249
|
|
4
|
+
data.tar.gz: ff2b98d1a9b42ac04e67154ace1eed41f13f0961ac6edb617aa3c508884e8542
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 48d7442f30326509e880a3d3076c96f4b84fb9aaede13829726f088c5617ba87a50420aec5ce851a6c177d145ed8ba4e5182f2a958ddc2664b00f2d87f1c0b43
|
|
7
|
+
data.tar.gz: 4211e6a868a560171c41d53e1b233500500370ff8432deb157db1418566e736865bd666a53a3e044b52af537bafaf17ebfe9fe341b14ade5d72953416de7c5ef
|
data/README.md
CHANGED
|
@@ -35,7 +35,7 @@ And if we try a nonexisting color we get an error
|
|
|
35
35
|
expect { L43::Color.ansi_code("no_color") }.to raise_error(IndexError, "key not found: :no_color")
|
|
36
36
|
```
|
|
37
37
|
|
|
38
|
-
### Context: Injecting methods into strings
|
|
38
|
+
### Context: Injecting color methods into strings
|
|
39
39
|
|
|
40
40
|
Given the inclusion of the string inject module
|
|
41
41
|
```ruby
|
|
@@ -47,6 +47,63 @@ Then we can make colored strings as follows
|
|
|
47
47
|
expect("red".red).to eq("\e[31mred")
|
|
48
48
|
```
|
|
49
49
|
|
|
50
|
+
### Context: Conveniently named methods
|
|
51
|
+
|
|
52
|
+
Given the following
|
|
53
|
+
```ruby
|
|
54
|
+
require 'l43/color/methods'
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
Then we can get the ANSI codes as functions
|
|
58
|
+
```ruby
|
|
59
|
+
expect(L43::Color::Methods.cyan).to eq("\x1b[36m")
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
And to get rid of the long name this module can be included
|
|
63
|
+
```ruby
|
|
64
|
+
c = Class.new do
|
|
65
|
+
include L43::Color::Methods
|
|
66
|
+
end
|
|
67
|
+
expect(c.new.blue).to eq("\e[34m")
|
|
68
|
+
```
|
|
69
|
+
Or extended
|
|
70
|
+
```ruby
|
|
71
|
+
m = Module.new do
|
|
72
|
+
extend L43::Color::Methods
|
|
73
|
+
end
|
|
74
|
+
expect(m.magenta).to eq("\e[35m")
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### Context: Output Helpers
|
|
78
|
+
|
|
79
|
+
They allow to alternate strings (to be printed verbatim) and symbols that will
|
|
80
|
+
output ANSI codes
|
|
81
|
+
|
|
82
|
+
Given they are included
|
|
83
|
+
```ruby
|
|
84
|
+
require 'l43/color/output'
|
|
85
|
+
include L43::Color::Output
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
Then we can use them to output to stdout
|
|
89
|
+
```ruby
|
|
90
|
+
expected = "\e[31mhello\e[0mworld\n"
|
|
91
|
+
expect { putcol([:red, "hello", :reset, "world"]) }
|
|
92
|
+
.to output(expected).to_stdout_from_any_process
|
|
93
|
+
|
|
94
|
+
expect { putcol([:red, "hello", :reset, "world"], to: :stdout) }
|
|
95
|
+
.to output(expected).to_stdout_from_any_process
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
Or we can use them to output to stderr
|
|
99
|
+
```ruby
|
|
100
|
+
expected = "\e[41mhello\e[4mworld\n"
|
|
101
|
+
expect { putcol([:bg_red, "hello", :ul, "world"], to: :stderr) }
|
|
102
|
+
.to output(expected).to_stderr_from_any_process
|
|
103
|
+
|
|
104
|
+
expect { putcol([:bg_red, "hello", :ul, "world"], to: $stderr) }
|
|
105
|
+
.to output(expected).to_stderr_from_any_process
|
|
106
|
+
```
|
|
50
107
|
## Author
|
|
51
108
|
|
|
52
109
|
Copyright © 2024 Robert Dober
|
data/bin/colorize
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
require_relative 'methods'
|
|
5
|
+
module L43
|
|
6
|
+
module Color
|
|
7
|
+
module Cli extend self
|
|
8
|
+
extend Methods
|
|
9
|
+
|
|
10
|
+
def run(_args)
|
|
11
|
+
$stderr.puts [yellow, "Coming soon"].join
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
# SPDX-License-Identifier: AGPL-3.0-or-later
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative 'definitions'
|
|
4
|
+
module L43
|
|
5
|
+
module Color
|
|
6
|
+
module Methods extend self
|
|
7
|
+
Definitions::COLOR_DEFINITIONS.each do |name, code|
|
|
8
|
+
define_method(name) { code }
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
# SPDX-License-Identifier: AGPL-3.0-or-later
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative '../color'
|
|
4
|
+
module L43
|
|
5
|
+
module Color
|
|
6
|
+
module Output
|
|
7
|
+
|
|
8
|
+
def putcol(args, to: $stdout)
|
|
9
|
+
dest = _get_device(to)
|
|
10
|
+
dest.puts args.map(&_to_code).join
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
private
|
|
14
|
+
|
|
15
|
+
def _get_device(desc)
|
|
16
|
+
case desc
|
|
17
|
+
when IO
|
|
18
|
+
desc
|
|
19
|
+
when :stderr
|
|
20
|
+
$stderr
|
|
21
|
+
when :stdout
|
|
22
|
+
$stdout
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def _to_code
|
|
27
|
+
-> ele do
|
|
28
|
+
case ele
|
|
29
|
+
when Symbol
|
|
30
|
+
Color.ansi_code(ele)
|
|
31
|
+
else
|
|
32
|
+
ele
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
# SPDX-License-Identifier: AGPL-3.0-or-later
|
data/lib/l43/color.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: l43_color
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Robert Dober
|
|
@@ -25,8 +25,9 @@ dependencies:
|
|
|
25
25
|
- !ruby/object:Gem::Version
|
|
26
26
|
version: 0.1.7
|
|
27
27
|
description: |
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
Colorize text with ANSI colors.
|
|
29
|
+
Parse and render files with
|
|
30
|
+
a mini color markup language.
|
|
30
31
|
email: robert.dober@gmail.com
|
|
31
32
|
executables: []
|
|
32
33
|
extensions: []
|
|
@@ -34,12 +35,16 @@ extra_rdoc_files: []
|
|
|
34
35
|
files:
|
|
35
36
|
- LICENSE
|
|
36
37
|
- README.md
|
|
38
|
+
- bin/colorize
|
|
37
39
|
- lib/l43/color.rb
|
|
40
|
+
- lib/l43/color/cli.rb
|
|
38
41
|
- lib/l43/color/definitions.rb
|
|
42
|
+
- lib/l43/color/methods.rb
|
|
43
|
+
- lib/l43/color/output.rb
|
|
39
44
|
- lib/l43/color/string_methods.rb
|
|
40
|
-
homepage: https://
|
|
45
|
+
homepage: https://www.codeberg.org/lab419/l43_color.git
|
|
41
46
|
licenses:
|
|
42
|
-
-
|
|
47
|
+
- AGPL-3.0-or-later
|
|
43
48
|
metadata: {}
|
|
44
49
|
post_install_message:
|
|
45
50
|
rdoc_options: []
|
|
@@ -59,5 +64,5 @@ requirements: []
|
|
|
59
64
|
rubygems_version: 3.5.8
|
|
60
65
|
signing_key:
|
|
61
66
|
specification_version: 4
|
|
62
|
-
summary: Colorize Text
|
|
67
|
+
summary: Colorize Text
|
|
63
68
|
test_files: []
|