l43_color 0.1.1 → 0.1.2
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 +26 -1
- data/lib/l43/color/output.rb +19 -0
- data/lib/l43/color.rb +2 -2
- metadata +5 -22
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 1319a310056d8ca08661853d85d0a6e8d0ce20f5e4e46972de8806c70485176a
|
|
4
|
+
data.tar.gz: 7e51e78e7bf42304435c07ceef25e3062c46ddc210f94a8ea30b1028126c1171
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ff55e1e19bc5a3594fc9613edc1a18f6a36ec68b8348bfc59987727ce6dd12b1fcbfb59d59a64bed12ed30d430a44b7dec7cff13c9965f2a30729fb26af02042
|
|
7
|
+
data.tar.gz: f4b0fe27d91d40b50926a374081df1673ddbbffc7fbcc54b3bce6a8b410380135aaa2ae4c7635eedabe92784337d9640b96b681782917645f1e4cf56b714c87b
|
data/README.md
CHANGED
|
@@ -104,9 +104,34 @@ Or we can use them to output to stderr
|
|
|
104
104
|
expect { putcol([:bg_red, "hello", :ul, "world"], to: $stderr) }
|
|
105
105
|
.to output(expected).to_stderr_from_any_process
|
|
106
106
|
```
|
|
107
|
+
|
|
108
|
+
### Context: `colorize`
|
|
109
|
+
|
|
110
|
+
Given we include `Output` again
|
|
111
|
+
```ruby
|
|
112
|
+
require 'l43/color/output'
|
|
113
|
+
include L43::Color::Output
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
We can also convert text, symbolic chunks and nil to meaningful output
|
|
117
|
+
|
|
118
|
+
Example: Useful for help texts
|
|
119
|
+
```ruby
|
|
120
|
+
expected = " \e[34mhello\e[0m\n"
|
|
121
|
+
expect(colorize(1, :blue, "hello", :reset, nil, reset: false))
|
|
122
|
+
.to eq(expected)
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
And we can also output that stuff
|
|
126
|
+
```ruby
|
|
127
|
+
expected = " \e[34mhello\n"
|
|
128
|
+
expect { putc(1, :blue, "hello", nil, indent: 1, reset: false) }
|
|
129
|
+
.to output(expected).to_stderr_from_any_process
|
|
130
|
+
```
|
|
131
|
+
|
|
107
132
|
## Author
|
|
108
133
|
|
|
109
|
-
Copyright ©
|
|
134
|
+
Copyright © 202[4-6] Robert Dober
|
|
110
135
|
robert.dober@gmail.com
|
|
111
136
|
|
|
112
137
|
# LICENSE
|
data/lib/l43/color/output.rb
CHANGED
|
@@ -5,12 +5,31 @@ module L43
|
|
|
5
5
|
module Color
|
|
6
6
|
module Output
|
|
7
7
|
|
|
8
|
+
def colorize(*chunks, reset: true, indent: 2)
|
|
9
|
+
reset = reset ? :reset : ''
|
|
10
|
+
[*chunks.flatten.map { _format_chunk it, indent: }, reset].flatten.map(&_to_code).join
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def putc(*chunks, device: $stderr, reset: true, indent: 2)
|
|
14
|
+
device.puts(colorize(chunks, reset:, indent:))
|
|
15
|
+
end
|
|
16
|
+
|
|
8
17
|
def putcol(args, to: $stdout)
|
|
9
18
|
dest = _get_device(to)
|
|
10
19
|
dest.puts args.map(&_to_code).join
|
|
11
20
|
end
|
|
12
21
|
|
|
13
22
|
private
|
|
23
|
+
def _format_chunk(chunk, indent:)
|
|
24
|
+
case chunk
|
|
25
|
+
when nil
|
|
26
|
+
"\n"
|
|
27
|
+
when Integer
|
|
28
|
+
" " * chunk * indent
|
|
29
|
+
else
|
|
30
|
+
chunk
|
|
31
|
+
end
|
|
32
|
+
end
|
|
14
33
|
|
|
15
34
|
def _get_device(desc)
|
|
16
35
|
case desc
|
data/lib/l43/color.rb
CHANGED
|
@@ -3,12 +3,12 @@
|
|
|
3
3
|
require_relative 'color/definitions'
|
|
4
4
|
module L43
|
|
5
5
|
module Color extend self
|
|
6
|
-
VERSION = "0.1.
|
|
6
|
+
VERSION = "0.1.2"
|
|
7
7
|
|
|
8
8
|
def ansi_code(name)
|
|
9
9
|
Definitions::COLOR_DEFINITIONS.fetch(name.downcase.to_sym)
|
|
10
10
|
end
|
|
11
|
-
|
|
11
|
+
|
|
12
12
|
end
|
|
13
13
|
end
|
|
14
14
|
# SPDX-License-Identifier: AGPL-3.0-or-later
|
metadata
CHANGED
|
@@ -1,29 +1,14 @@
|
|
|
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.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Robert Dober
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: bin
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
12
|
-
dependencies:
|
|
13
|
-
- !ruby/object:Gem::Dependency
|
|
14
|
-
name: l43_peg
|
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
|
16
|
-
requirements:
|
|
17
|
-
- - "~>"
|
|
18
|
-
- !ruby/object:Gem::Version
|
|
19
|
-
version: 0.1.7
|
|
20
|
-
type: :runtime
|
|
21
|
-
prerelease: false
|
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
-
requirements:
|
|
24
|
-
- - "~>"
|
|
25
|
-
- !ruby/object:Gem::Version
|
|
26
|
-
version: 0.1.7
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
|
+
dependencies: []
|
|
27
12
|
description: |
|
|
28
13
|
Colorize text with ANSI colors.
|
|
29
14
|
Parse and render files with
|
|
@@ -46,7 +31,6 @@ homepage: https://www.codeberg.org/lab419/l43_color.git
|
|
|
46
31
|
licenses:
|
|
47
32
|
- AGPL-3.0-or-later
|
|
48
33
|
metadata: {}
|
|
49
|
-
post_install_message:
|
|
50
34
|
rdoc_options: []
|
|
51
35
|
require_paths:
|
|
52
36
|
- lib
|
|
@@ -54,15 +38,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
54
38
|
requirements:
|
|
55
39
|
- - ">="
|
|
56
40
|
- !ruby/object:Gem::Version
|
|
57
|
-
version:
|
|
41
|
+
version: 4.0.1
|
|
58
42
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
59
43
|
requirements:
|
|
60
44
|
- - ">="
|
|
61
45
|
- !ruby/object:Gem::Version
|
|
62
46
|
version: '0'
|
|
63
47
|
requirements: []
|
|
64
|
-
rubygems_version:
|
|
65
|
-
signing_key:
|
|
48
|
+
rubygems_version: 4.0.9
|
|
66
49
|
specification_version: 4
|
|
67
50
|
summary: Colorize Text
|
|
68
51
|
test_files: []
|