concolor 0.0.1 → 1.0.0
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 +5 -5
- data/LICENSE.txt +1 -1
- data/README.md +73 -9
- data/Rakefile +12 -1
- data/lib/concolor/extension.rb +12 -0
- data/lib/concolor/mappers/bg_color.rb +27 -0
- data/lib/concolor/mappers/color.rb +27 -0
- data/lib/concolor/mappers/mode.rb +20 -0
- data/lib/concolor/mappers.rb +10 -0
- data/lib/concolor/string.rb +63 -0
- data/lib/concolor/version.rb +18 -3
- data/lib/concolor.rb +9 -41
- metadata +25 -42
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: d5a41a01b07da3fbebfd84f064f85b9466f8a7fabbb464782ac6598b29e0e1c9
|
4
|
+
data.tar.gz: 0006e729b5473a84ac980cbd9f2284ec23da460dbaa1a012b9e8dca26e83f12b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d1dcb670e57eddba7fc42e7bcfb85e765ae6ca33c9e66cffed513d5926f82548a5ff7b43396f2fe48050cb6e3380e42bb9d7b9e79409d8fe62a37e757b38e863
|
7
|
+
data.tar.gz: c2c91fc48edcb91c6da5ca7d37a90a2c71ce46370f6e0b4a15f15826bd66abbf288510cf18c4ba2a65856f8200ef4f2340a0207d572e23818b19869a218c4ae2
|
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -1,23 +1,87 @@
|
|
1
|
-
# Concolor
|
1
|
+
# :computer: Concolor
|
2
2
|
|
3
|
-
|
3
|
+
With `Concolor` you can change the fore- and background colors and text decorations when rendering text on terminals supporting ANSI escape codes. It adds the `concolor` method to `String`.
|
4
|
+
|
5
|
+
[](https://badge.fury.io/rb/concolor) [](https://github.com/bf-rb/concolor/actions) [](https://github.com/bf-rb/concolor/blob/main/LICENSE.txt) [](https://rubydoc.org/gems/concolor/1.0.0)
|
4
6
|
|
5
7
|
## Installation
|
6
8
|
|
7
|
-
|
9
|
+
Just install the *concolor* gem
|
10
|
+
|
11
|
+
```bash
|
12
|
+
gem install concolor
|
13
|
+
```
|
14
|
+
|
15
|
+
or if you use **bundler** put this in your `Gemfile`
|
8
16
|
|
9
17
|
```ruby
|
10
18
|
gem 'concolor'
|
11
19
|
```
|
12
20
|
|
13
|
-
|
21
|
+
## Usage
|
14
22
|
|
15
|
-
|
23
|
+
```ruby
|
24
|
+
require 'concolor'
|
16
25
|
|
17
|
-
|
26
|
+
puts 'Some text'.concolor(:bold, :red)
|
27
|
+
# "\033[31;1mSome text\033[0m"
|
28
|
+
```
|
18
29
|
|
19
|
-
|
30
|
+
### Foreground color (text)
|
20
31
|
|
21
|
-
|
32
|
+
| Symbol | | code |
|
33
|
+
| :--------------- | :-------: | :--: |
|
34
|
+
| `:default` | | *29* |
|
35
|
+
| `:black` |  | *30* |
|
36
|
+
| `:red` |  | *31* |
|
37
|
+
| `:green` |  | *32* |
|
38
|
+
| `:yellow` |  | *33* |
|
39
|
+
| `:blue` |  | *34* |
|
40
|
+
| `:magenta` |  | *35* |
|
41
|
+
| `:cyan` |  | *36* |
|
42
|
+
| `:light_gray` |  | *37* |
|
43
|
+
| `:dark_gray` |  | *90* |
|
44
|
+
| `:light_red` |  | *91* |
|
45
|
+
| `:light_green` |  | *92* |
|
46
|
+
| `:light_yellow` |  | *93* |
|
47
|
+
| `:light_blue` |  | *94* |
|
48
|
+
| `:light_magenta` |  | *95* |
|
49
|
+
| `:light_cyan` |  | *96* |
|
50
|
+
| `:white` |  | *97* |
|
51
|
+
|
52
|
+
### Background color
|
53
|
+
|
54
|
+
| Symbol | | code |
|
55
|
+
| :------------------ | :-------: | :---: |
|
56
|
+
| `:bg_default` | | *49* |
|
57
|
+
| `:bg_black` |  | *40* |
|
58
|
+
| `:bg_red` |  | *41* |
|
59
|
+
| `:bg_green` |  | *42* |
|
60
|
+
| `:bg_yellow` |  | *43* |
|
61
|
+
| `:bg_blue` |  | *44* |
|
62
|
+
| `:bg_magenta` |  | *45* |
|
63
|
+
| `:bg_cyan` |  | *46* |
|
64
|
+
| `:bg_light_gray` |  | *47* |
|
65
|
+
| `:bg_dark_gray` |  | *100* |
|
66
|
+
| `:bg_light_red` |  | *101* |
|
67
|
+
| `:bg_light_green` |  | *102* |
|
68
|
+
| `:bg_light_yellow` |  | *103* |
|
69
|
+
| `:bg_light_blue` |  | *104* |
|
70
|
+
| `:bg_light_magenta` |  | *105* |
|
71
|
+
| `:bg_light_cyan` |  | *106* |
|
72
|
+
| `:bg_white` |  | *107* |
|
73
|
+
|
74
|
+
### Mode (modifying the style of text)
|
22
75
|
|
23
|
-
|
76
|
+
| Symbol | Description | code |
|
77
|
+
| :------------ | :---------- | :---: |
|
78
|
+
| `:reset` | Reset all SGR effects to their default | *0* |
|
79
|
+
| `:bold` | Bold or increased intensity | *1* |
|
80
|
+
| `:faint` | Faint or decreased intensity | *2* |
|
81
|
+
| `:italic` | Italic | *3* |
|
82
|
+
| `:underline` | Singly underlined | *4* |
|
83
|
+
| `:blink` | Blink (slow) | *5* |
|
84
|
+
| `:blink_fast` | Blink (fast) | *6* |
|
85
|
+
| `:reverse` | Reverse (invert the foreground and background colors) | *7* |
|
86
|
+
| `:hide` | Hidden (useful for passwords) | *8* |
|
87
|
+
| `:cross` | Cross-out | *9* |
|
data/Rakefile
CHANGED
@@ -1 +1,12 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'bundler/gem_tasks'
|
4
|
+
require 'rspec/core/rake_task'
|
5
|
+
|
6
|
+
RSpec::Core::RakeTask.new(:spec)
|
7
|
+
|
8
|
+
require 'rubocop/rake_task'
|
9
|
+
|
10
|
+
RuboCop::RakeTask.new
|
11
|
+
|
12
|
+
task default: %i[spec rubocop]
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Concolor
|
4
|
+
# Extension module for String class
|
5
|
+
module Extension
|
6
|
+
# @param options [Array<Symbol>]
|
7
|
+
# @return [Concolor::String]
|
8
|
+
def concolor(*options)
|
9
|
+
::Concolor::String.new(to_s, options: options)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Concolor
|
4
|
+
module Mappers
|
5
|
+
module BgColor
|
6
|
+
DATA = {
|
7
|
+
bg_default: 49,
|
8
|
+
bg_black: 40,
|
9
|
+
bg_red: 41,
|
10
|
+
bg_green: 42,
|
11
|
+
bg_yellow: 43,
|
12
|
+
bg_blue: 44,
|
13
|
+
bg_magenta: 45,
|
14
|
+
bg_cyan: 46,
|
15
|
+
bg_light_gray: 47,
|
16
|
+
bg_dark_gray: 100,
|
17
|
+
bg_light_red: 101,
|
18
|
+
bg_light_green: 102,
|
19
|
+
bg_light_yellow: 103,
|
20
|
+
bg_light_blue: 104,
|
21
|
+
bg_light_magenta: 105,
|
22
|
+
bg_light_cyan: 106,
|
23
|
+
bg_white: 107
|
24
|
+
}.freeze
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Concolor
|
4
|
+
module Mappers
|
5
|
+
module Color
|
6
|
+
DATA = {
|
7
|
+
default: 39,
|
8
|
+
black: 30,
|
9
|
+
red: 31,
|
10
|
+
green: 32,
|
11
|
+
yellow: 33,
|
12
|
+
blue: 34,
|
13
|
+
magenta: 35,
|
14
|
+
cyan: 36,
|
15
|
+
light_gray: 37,
|
16
|
+
dark_gray: 90,
|
17
|
+
light_red: 91,
|
18
|
+
light_green: 92,
|
19
|
+
light_yellow: 93,
|
20
|
+
light_blue: 94,
|
21
|
+
light_magenta: 95,
|
22
|
+
light_cyan: 96,
|
23
|
+
white: 97
|
24
|
+
}.freeze
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Concolor
|
4
|
+
module Mappers
|
5
|
+
module Mode
|
6
|
+
DATA = {
|
7
|
+
reset: 0,
|
8
|
+
bold: 1,
|
9
|
+
faint: 2,
|
10
|
+
italic: 3,
|
11
|
+
underline: 4,
|
12
|
+
blink: 5,
|
13
|
+
blink_fast: 6,
|
14
|
+
reverse: 7,
|
15
|
+
hide: 8,
|
16
|
+
cross: 9
|
17
|
+
}.freeze
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Concolor
|
4
|
+
# Extension module for String class
|
5
|
+
class String
|
6
|
+
# @param str [String] some string object
|
7
|
+
# @param options [Array<Symbol>]
|
8
|
+
def initialize(str = '', options: [])
|
9
|
+
@str = str
|
10
|
+
parsed = parse_options!(options)
|
11
|
+
|
12
|
+
@color = ::Concolor::Mappers::Color::DATA[parsed[:colors].first]
|
13
|
+
@bg_color = ::Concolor::Mappers::BgColor::DATA[parsed[:bg_colors].first]
|
14
|
+
@modes = parsed[:modes].map do |mode|
|
15
|
+
Concolor::Mappers::Mode::DATA[mode]
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
# To string
|
20
|
+
# @return [String]
|
21
|
+
def to_s
|
22
|
+
"\033[#{style}m#{@str}\033[0m"
|
23
|
+
end
|
24
|
+
|
25
|
+
# def [](key)
|
26
|
+
# self
|
27
|
+
# end
|
28
|
+
|
29
|
+
alias inspect to_s
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
# Parse options
|
34
|
+
# @param options [Array<Symbol>]
|
35
|
+
# @return [Hash] { colors: [...], bg_colors: [...], modes: [...] }
|
36
|
+
def parse_options!(options)
|
37
|
+
parsed = { colors: [], bg_colors: [], modes: [] }
|
38
|
+
wrong = []
|
39
|
+
|
40
|
+
options.each do |opt|
|
41
|
+
if Concolor::Mappers::Color::DATA.key?(opt)
|
42
|
+
parsed[:colors].push(opt)
|
43
|
+
elsif Concolor::Mappers::Mode::DATA.key?(opt)
|
44
|
+
parsed[:modes].push(opt)
|
45
|
+
elsif Concolor::Mappers::BgColor::DATA.key?(opt)
|
46
|
+
parsed[:bg_colors].push(opt)
|
47
|
+
else
|
48
|
+
wrong.push(opt)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
return parsed if wrong.empty?
|
53
|
+
|
54
|
+
raise ::ArgumentError, "Wrong options: #{wrong.join(', ')}"
|
55
|
+
end
|
56
|
+
|
57
|
+
# Get style string
|
58
|
+
# @return [String]
|
59
|
+
def style
|
60
|
+
[@color, @bg_color, @modes].flatten.compact.join(';')
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
data/lib/concolor/version.rb
CHANGED
@@ -1,4 +1,19 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
2
3
|
module Concolor
|
3
|
-
|
4
|
-
|
4
|
+
# Gem version module
|
5
|
+
module Version
|
6
|
+
# x.0.0 changes that will break existing users code if they update
|
7
|
+
MAJOR = 1
|
8
|
+
# 0.x.0 changes, such as new functionality/features
|
9
|
+
MINOR = 0
|
10
|
+
# 0.0.x changes, such as small bug fixes
|
11
|
+
PATCH = 0
|
12
|
+
|
13
|
+
# Get current gem version
|
14
|
+
# @return [String]
|
15
|
+
def self.current
|
16
|
+
"#{MAJOR}.#{MINOR}.#{PATCH}"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/concolor.rb
CHANGED
@@ -1,47 +1,15 @@
|
|
1
|
-
#
|
2
|
-
require 'concolor/version'
|
1
|
+
# frozen_string_literal: true
|
3
2
|
|
3
|
+
# Base module
|
4
4
|
module Concolor
|
5
|
+
autoload :Version, 'concolor/version'
|
6
|
+
autoload :Mappers, 'concolor/mappers'
|
7
|
+
autoload :String, 'concolor/string'
|
8
|
+
autoload :Extension, 'concolor/extension'
|
5
9
|
|
6
|
-
def
|
7
|
-
|
8
|
-
# Text color
|
9
|
-
black: 30,
|
10
|
-
red: 31,
|
11
|
-
green: 32,
|
12
|
-
yellow: 33,
|
13
|
-
blue: 34,
|
14
|
-
magenta: 35,
|
15
|
-
cyan: 36,
|
16
|
-
white: 37,
|
17
|
-
|
18
|
-
# Background color
|
19
|
-
black_bg: 40,
|
20
|
-
red_bg: 41,
|
21
|
-
green_bg: 42,
|
22
|
-
yellow_bg: 43,
|
23
|
-
blue_bg: 44,
|
24
|
-
magenta_bg: 45,
|
25
|
-
cyan_bg: 46,
|
26
|
-
white_bg: 47,
|
27
|
-
|
28
|
-
# Text Style
|
29
|
-
bold: 1,
|
30
|
-
underline: 4
|
31
|
-
}
|
32
|
-
|
33
|
-
colorize_string = self.to_s
|
34
|
-
|
35
|
-
args.each do |arg|
|
36
|
-
if style_map.key?(arg)
|
37
|
-
colorize_string = "\033[#{style_map[arg]}m" + colorize_string + "\033[0m"
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
colorize_string
|
10
|
+
def self.auto_include_to(klass)
|
11
|
+
klass.send(:include, Concolor::Extension)
|
42
12
|
end
|
43
13
|
end
|
44
14
|
|
45
|
-
|
46
|
-
include Concolor
|
47
|
-
end
|
15
|
+
Concolor.auto_include_to(String)
|
metadata
CHANGED
@@ -1,46 +1,18 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: concolor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
8
|
-
autorequire:
|
7
|
+
- Alex Merkulov
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
12
|
-
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: bundler
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - "~>"
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '1.7'
|
20
|
-
type: :development
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - "~>"
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '1.7'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: rake
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - "~>"
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '10.0'
|
34
|
-
type: :development
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - "~>"
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '10.0'
|
11
|
+
date: 2022-10-23 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
41
13
|
description: Colorize console text
|
42
14
|
email:
|
43
|
-
-
|
15
|
+
- rormercury@gmail.com
|
44
16
|
executables: []
|
45
17
|
extensions: []
|
46
18
|
extra_rdoc_files: []
|
@@ -49,12 +21,24 @@ files:
|
|
49
21
|
- README.md
|
50
22
|
- Rakefile
|
51
23
|
- lib/concolor.rb
|
24
|
+
- lib/concolor/extension.rb
|
25
|
+
- lib/concolor/mappers.rb
|
26
|
+
- lib/concolor/mappers/bg_color.rb
|
27
|
+
- lib/concolor/mappers/color.rb
|
28
|
+
- lib/concolor/mappers/mode.rb
|
29
|
+
- lib/concolor/string.rb
|
52
30
|
- lib/concolor/version.rb
|
53
|
-
homepage: https://github.com/
|
31
|
+
homepage: https://github.com/bf-rb/concolor
|
54
32
|
licenses:
|
55
33
|
- MIT
|
56
|
-
metadata:
|
57
|
-
|
34
|
+
metadata:
|
35
|
+
homepage_uri: https://github.com/bf-rb/concolor
|
36
|
+
changelog_uri: https://github.com/bf-rb/concolor/blob/main/CHANGELOG.md
|
37
|
+
source_code_uri: https://github.com/bf-rb/concolor
|
38
|
+
documentation_uri: https://rubydoc.org/gems/concolor/1.0.0
|
39
|
+
bug_tracker_uri: https://github.com/bf-rb/concolor/issues
|
40
|
+
rubygems_mfa_required: 'true'
|
41
|
+
post_install_message:
|
58
42
|
rdoc_options: []
|
59
43
|
require_paths:
|
60
44
|
- lib
|
@@ -62,16 +46,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
62
46
|
requirements:
|
63
47
|
- - ">="
|
64
48
|
- !ruby/object:Gem::Version
|
65
|
-
version:
|
49
|
+
version: 2.7.0
|
66
50
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
67
51
|
requirements:
|
68
52
|
- - ">="
|
69
53
|
- !ruby/object:Gem::Version
|
70
54
|
version: '0'
|
71
55
|
requirements: []
|
72
|
-
|
73
|
-
|
74
|
-
signing_key:
|
56
|
+
rubygems_version: 3.1.6
|
57
|
+
signing_key:
|
75
58
|
specification_version: 4
|
76
|
-
summary: Console
|
59
|
+
summary: Console colorize text
|
77
60
|
test_files: []
|