concolor 0.0.1 → 1.0.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 +5 -5
- data/LICENSE.txt +1 -1
- data/README.md +88 -8
- data/Rakefile +12 -1
- data/lib/concolor/extension.rb +22 -0
- data/lib/concolor/mappers.rb +61 -0
- data/lib/concolor/string.rb +64 -0
- data/lib/concolor/version.rb +34 -3
- data/lib/concolor.rb +13 -42
- metadata +22 -42
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: f42aa4a0c9aa77f70af7aaa9889cebc7d3f85384e5e509eb3c26c865bc2de573
|
4
|
+
data.tar.gz: ace991096094325ef9d0b23ebcd27053e2aba6a1d24bfdd40d517bef94739469
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9c8aead6bbcb153f25e7d203465b19b5bd295a6f0da0c73fc7a5c1b5da1ddfe6f5f35412a8956e5b8430f8aaaad53ff1ac52da8c6b57c593e486760714f73e1b
|
7
|
+
data.tar.gz: 20220bab5562b31a0d355ae680fcd982cb681f79d5dad575380e7fc0037048a7df8e4a37630b3a77fdd5fe3f422f6b97979c6f59408231b07503942c30285716
|
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -1,23 +1,103 @@
|
|
1
1
|
# Concolor
|
2
2
|
|
3
|
-
|
3
|
+
[](https://rubygems.org/gems/concolor) [](https://github.com/bf-rb/concolor/actions) [](https://bf-rb.github.io/concolor/v1.0.1/)
|
4
|
+
|
5
|
+
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` objects.
|
6
|
+
|
7
|
+
   
|
8
|
+
|
9
|
+
## Used technologies, API, tools, etc
|
10
|
+
|
11
|
+
[ruby-logo]: https://img.shields.io/badge/Ruby-cc342d.svg?style=flat&logo=ruby&logoColor=fff
|
12
|
+
[git-logo]: https://img.shields.io/badge/Git-000.svg?style=flat&logo=git&logoColor=f54d27
|
13
|
+
[github-actions-logo]: https://img.shields.io/badge/GitHub%20Actions-2671e5.svg?style=flat&logo=githubactions&logoColor=fff
|
14
|
+
[rubocop-logo]: https://img.shields.io/badge/RuboCop-f5f5f5.svg?style=flat&logo=rubocop&logoColor=000
|
15
|
+
[vs-code-logo]: https://img.shields.io/badge/VS%20Code-2c2c32.svg?style=flat&logo=visualstudiocode&logoColor=22a8f1
|
16
|
+
[docker-logo]: https://img.shields.io/badge/Docker-003f8c.svg?style=flat&logo=docker&logoColor=fff
|
17
|
+
[ruby-gems-logo]: https://img.shields.io/badge/Ruby%20Gems-e9573f.svg?style=flat&logo=rubygems&logoColor=fff
|
18
|
+
|
19
|
+
[![ruby-logo]](https://www.ruby-lang.org/) [![git-logo]](https://git-scm.com/) [![github-actions-logo]](https://docs.github.com/en/actions) [![rubocop-logo]](https://rubocop.org/) [![vs-code-logo]](https://code.visualstudio.com/) [![docker-logo]](https://www.docker.com/) [![ruby-gems-logo]](https://rubygems.org/)
|
20
|
+
|
21
|
+
## Development
|
22
|
+
|
23
|
+
Gem development information and current project status:
|
24
|
+
|
25
|
+
[](https://github.com/bf-rb/concolor/actions) [](https://github.com/bf-rb/concolor/issues) 
|
4
26
|
|
5
27
|
## Installation
|
6
28
|
|
7
|
-
|
29
|
+
Just install the *concolor* gem
|
30
|
+
|
31
|
+
```bash
|
32
|
+
gem install concolor
|
33
|
+
```
|
34
|
+
|
35
|
+
or if you use **bundler** put this in your `Gemfile`
|
8
36
|
|
9
37
|
```ruby
|
10
38
|
gem 'concolor'
|
11
39
|
```
|
12
40
|
|
13
|
-
|
41
|
+
## Usage
|
14
42
|
|
15
|
-
|
43
|
+
```ruby
|
44
|
+
require 'concolor'
|
16
45
|
|
17
|
-
|
46
|
+
puts 'Some text'.concolor(:bold, :red)
|
47
|
+
# "\033[31;1mSome text\033[0m"
|
48
|
+
```
|
18
49
|
|
19
|
-
|
50
|
+
### Foreground color & Background color
|
20
51
|
|
21
|
-
|
52
|
+
[#000000]: https://via.placeholder.com/15/000000/000000.png
|
53
|
+
[#CD0000]: https://via.placeholder.com/15/CD0000/CD0000.png
|
54
|
+
[#00CD00]: https://via.placeholder.com/15/00CD00/00CD00.png
|
55
|
+
[#CDCD00]: https://via.placeholder.com/15/CDCD00/CDCD00.png
|
56
|
+
[#1E90FF]: https://via.placeholder.com/15/1E90FF/1E90FF.png
|
57
|
+
[#CD00CD]: https://via.placeholder.com/15/CD00CD/CD00CD.png
|
58
|
+
[#00CDCD]: https://via.placeholder.com/15/00CDCD/00CDCD.png
|
59
|
+
[#E5E5E5]: https://via.placeholder.com/15/E5E5E5/E5E5E5.png
|
60
|
+
[#4C4C4C]: https://via.placeholder.com/15/4C4C4C/4C4C4C.png
|
61
|
+
[#FF0000]: https://via.placeholder.com/15/FF0000/FF0000.png
|
62
|
+
[#00FF00]: https://via.placeholder.com/15/00FF00/00FF00.png
|
63
|
+
[#FFFF00]: https://via.placeholder.com/15/FFFF00/FFFF00.png
|
64
|
+
[#4682B4]: https://via.placeholder.com/15/4682B4/4682B4.png
|
65
|
+
[#FF00FF]: https://via.placeholder.com/15/FF00FF/FF00FF.png
|
66
|
+
[#00FFFF]: https://via.placeholder.com/15/00FFFF/00FFFF.png
|
67
|
+
[#FFFFFF]: https://via.placeholder.com/15/FFFFFF/FFFFFF.png
|
68
|
+
|
69
|
+
|
70
|
+
| Foreground color | code | color | Background color | code |
|
71
|
+
| :--------------- | :--: | :--------: | :----------------- | :---: |
|
72
|
+
| `:default` | *29* | | `:bg_default` | *49* |
|
73
|
+
| `:black` | *30* | ![#000000] | `:bg_black` | *40* |
|
74
|
+
| `:red` | *31* | ![#CD0000] | `:bg_red` | *41* |
|
75
|
+
| `:green` | *32* | ![#00CD00] | `:bg_green` | *42* |
|
76
|
+
| `:yellow` | *33* | ![#CDCD00] | `:bg_yellow` | *43* |
|
77
|
+
| `:blue` | *34* | ![#1E90FF] | `:bg_blue` | *44* |
|
78
|
+
| `:magenta` | *35* | ![#CD00CD] | `:bg_magenta` | *45* |
|
79
|
+
| `:cyan` | *36* | ![#00CDCD] | `:bg_cyan` | *46* |
|
80
|
+
| `:light_gray` | *37* | ![#E5E5E5] | `:bg_light_gray` | *47* |
|
81
|
+
| `:dark_gray` | *90* | ![#4C4C4C] | `:bg_dark_gray` | *100* |
|
82
|
+
| `:light_red` | *91* | ![#FF0000] | `:bg_light_red` | *101* |
|
83
|
+
| `:light_green` | *92* | ![#00FF00] | `:bg_light_green` | *102* |
|
84
|
+
| `:light_yellow` | *93* | ![#FFFF00] | `:bg_light_yellow` | *103* |
|
85
|
+
| `:light_blue` | *94* | ![#4682B4] | `:bg_light_blue` | *104* |
|
86
|
+
| `:light_magenta` | *95* | ![#FF00FF] | `:bg_light_magenta`| *105* |
|
87
|
+
| `:light_cyan` | *96* | ![#00FFFF] | `:bg_light_cyan` | *106* |
|
88
|
+
| `:white` | *97* | ![#FFFFFF] | `:bg_white` | *107* |
|
89
|
+
|
90
|
+
### Mode (modifying the style of text)
|
22
91
|
|
23
|
-
|
92
|
+
| Symbol | Description | code |
|
93
|
+
| :------------ | :---------- | :---: |
|
94
|
+
| `:reset` | Reset all SGR effects to their default | *0* |
|
95
|
+
| `:bold` | Bold or increased intensity | *1* |
|
96
|
+
| `:faint` | Faint or decreased intensity | *2* |
|
97
|
+
| `:italic` | Italic | *3* |
|
98
|
+
| `:underline` | Singly underlined | *4* |
|
99
|
+
| `:blink` | Blink (slow) | *5* |
|
100
|
+
| `:blink_fast` | Blink (fast) | *6* |
|
101
|
+
| `:reverse` | Reverse (invert the foreground and background colors) | *7* |
|
102
|
+
| `:hide` | Hidden (useful for passwords) | *8* |
|
103
|
+
| `: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,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Concolor
|
4
|
+
# Extension module
|
5
|
+
#
|
6
|
+
# @example
|
7
|
+
# class CustomString < String
|
8
|
+
# include Concolor::Extension
|
9
|
+
# end
|
10
|
+
#
|
11
|
+
# CustomString.new('Some text').concolor(:bold, :red)
|
12
|
+
# # => "\033[31;1mSome text\033[0m"
|
13
|
+
#
|
14
|
+
# @since 0.0.1
|
15
|
+
module Extension
|
16
|
+
# @param options [Array<Symbol>]
|
17
|
+
# @return [Concolor::String]
|
18
|
+
def concolor(*options)
|
19
|
+
::Concolor::String.new(to_s, options: options)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Concolor
|
4
|
+
# ANSI escape codes mappers
|
5
|
+
#
|
6
|
+
# @since 1.0.1
|
7
|
+
module Mappers
|
8
|
+
COLORS = {
|
9
|
+
default: 39,
|
10
|
+
black: 30,
|
11
|
+
red: 31,
|
12
|
+
green: 32,
|
13
|
+
yellow: 33,
|
14
|
+
blue: 34,
|
15
|
+
magenta: 35,
|
16
|
+
cyan: 36,
|
17
|
+
light_gray: 37,
|
18
|
+
dark_gray: 90,
|
19
|
+
light_red: 91,
|
20
|
+
light_green: 92,
|
21
|
+
light_yellow: 93,
|
22
|
+
light_blue: 94,
|
23
|
+
light_magenta: 95,
|
24
|
+
light_cyan: 96,
|
25
|
+
white: 97
|
26
|
+
}.freeze
|
27
|
+
|
28
|
+
BG_COLORS = {
|
29
|
+
bg_default: 49,
|
30
|
+
bg_black: 40,
|
31
|
+
bg_red: 41,
|
32
|
+
bg_green: 42,
|
33
|
+
bg_yellow: 43,
|
34
|
+
bg_blue: 44,
|
35
|
+
bg_magenta: 45,
|
36
|
+
bg_cyan: 46,
|
37
|
+
bg_light_gray: 47,
|
38
|
+
bg_dark_gray: 100,
|
39
|
+
bg_light_red: 101,
|
40
|
+
bg_light_green: 102,
|
41
|
+
bg_light_yellow: 103,
|
42
|
+
bg_light_blue: 104,
|
43
|
+
bg_light_magenta: 105,
|
44
|
+
bg_light_cyan: 106,
|
45
|
+
bg_white: 107
|
46
|
+
}.freeze
|
47
|
+
|
48
|
+
MODES = {
|
49
|
+
reset: 0,
|
50
|
+
bold: 1,
|
51
|
+
faint: 2,
|
52
|
+
italic: 3,
|
53
|
+
underline: 4,
|
54
|
+
blink: 5,
|
55
|
+
blink_fast: 6,
|
56
|
+
reverse: 7,
|
57
|
+
hide: 8,
|
58
|
+
cross: 9
|
59
|
+
}.freeze
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Concolor
|
4
|
+
# Extension module for String class
|
5
|
+
#
|
6
|
+
# @since 1.0.1
|
7
|
+
class String
|
8
|
+
# @param str [String] some string object
|
9
|
+
# @param options [Array<Symbol>]
|
10
|
+
def initialize(str = '', options: [])
|
11
|
+
@str = str
|
12
|
+
parsed = parse_options!(options)
|
13
|
+
|
14
|
+
@color = ::Concolor::Mappers::COLORS[parsed[:colors].first]
|
15
|
+
@bg_color = ::Concolor::Mappers::BG_COLORS[parsed[:bg_colors].first]
|
16
|
+
@modes = parsed[:modes].map do |mode|
|
17
|
+
Concolor::Mappers::MODES[mode]
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
# To string
|
22
|
+
#
|
23
|
+
# @return [String]
|
24
|
+
def to_s
|
25
|
+
"\033[#{style}m#{@str}\033[0m"
|
26
|
+
end
|
27
|
+
|
28
|
+
alias inspect to_s
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
# Parse options
|
33
|
+
#
|
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::COLORS.key?(opt)
|
42
|
+
parsed[:colors].push(opt)
|
43
|
+
elsif Concolor::Mappers::MODES.key?(opt)
|
44
|
+
parsed[:modes].push(opt)
|
45
|
+
elsif Concolor::Mappers::BG_COLORS.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
|
+
#
|
59
|
+
# @return [String]
|
60
|
+
def style
|
61
|
+
[@color, @bg_color, @modes].flatten.compact.join(';')
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
data/lib/concolor/version.rb
CHANGED
@@ -1,4 +1,35 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
2
3
|
module Concolor
|
3
|
-
|
4
|
-
|
4
|
+
# Gem version module
|
5
|
+
#
|
6
|
+
# @since 0.0.1
|
7
|
+
module Version
|
8
|
+
# x.0.0 changes that will break existing users code if they update
|
9
|
+
MAJOR = 1
|
10
|
+
# 0.x.0 changes, such as new functionality/features
|
11
|
+
MINOR = 0
|
12
|
+
# 0.0.x changes, such as small bug fixes
|
13
|
+
PATCH = 1
|
14
|
+
|
15
|
+
# Get current gem version
|
16
|
+
#
|
17
|
+
# @example
|
18
|
+
# Concolor::Version::CURRENT # => "1.0.1"
|
19
|
+
#
|
20
|
+
# @since 1.0.1
|
21
|
+
CURRENT = "#{MAJOR}.#{MINOR}.#{PATCH}"
|
22
|
+
|
23
|
+
# Get current gem version
|
24
|
+
#
|
25
|
+
# @deprecated use {CURRENT} instead.
|
26
|
+
#
|
27
|
+
# @example
|
28
|
+
# Concolor::Version.current # => "0.0.1"
|
29
|
+
#
|
30
|
+
# @return [String]
|
31
|
+
def self.current
|
32
|
+
"#{MAJOR}.#{MINOR}.#{PATCH}"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/lib/concolor.rb
CHANGED
@@ -1,47 +1,18 @@
|
|
1
|
-
#
|
2
|
-
require 'concolor/version'
|
1
|
+
# frozen_string_literal: true
|
3
2
|
|
3
|
+
# Base module
|
4
|
+
#
|
5
|
+
# @author {https://github.com/alexmercury Alex Merkulov}
|
4
6
|
module Concolor
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
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
|
7
|
+
autoload :Version, 'concolor/version'
|
8
|
+
autoload :Mappers, 'concolor/mappers'
|
9
|
+
autoload :String, 'concolor/string'
|
10
|
+
autoload :Extension, 'concolor/extension'
|
11
|
+
|
12
|
+
# @param klass [Class]
|
13
|
+
def self.auto_include_to(klass)
|
14
|
+
klass.send(:include, Concolor::Extension)
|
42
15
|
end
|
43
16
|
end
|
44
17
|
|
45
|
-
|
46
|
-
include Concolor
|
47
|
-
end
|
18
|
+
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:
|
4
|
+
version: 1.0.1
|
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: 2023-05-17 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,21 @@ 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/string.rb
|
52
27
|
- lib/concolor/version.rb
|
53
|
-
homepage: https://github.com/
|
28
|
+
homepage: https://github.com/bf-rb/concolor
|
54
29
|
licenses:
|
55
30
|
- MIT
|
56
|
-
metadata:
|
57
|
-
|
31
|
+
metadata:
|
32
|
+
homepage_uri: https://github.com/bf-rb/concolor
|
33
|
+
changelog_uri: https://github.com/bf-rb/concolor/blob/main/CHANGELOG.md
|
34
|
+
source_code_uri: https://github.com/bf-rb/concolor
|
35
|
+
documentation_uri: https://bf-rb.github.io/concolor/v1.0.1
|
36
|
+
bug_tracker_uri: https://github.com/bf-rb/concolor/issues
|
37
|
+
rubygems_mfa_required: 'true'
|
38
|
+
post_install_message:
|
58
39
|
rdoc_options: []
|
59
40
|
require_paths:
|
60
41
|
- lib
|
@@ -62,16 +43,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
62
43
|
requirements:
|
63
44
|
- - ">="
|
64
45
|
- !ruby/object:Gem::Version
|
65
|
-
version:
|
46
|
+
version: 2.7.0
|
66
47
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
67
48
|
requirements:
|
68
49
|
- - ">="
|
69
50
|
- !ruby/object:Gem::Version
|
70
51
|
version: '0'
|
71
52
|
requirements: []
|
72
|
-
|
73
|
-
|
74
|
-
signing_key:
|
53
|
+
rubygems_version: 3.4.12
|
54
|
+
signing_key:
|
75
55
|
specification_version: 4
|
76
|
-
summary: Console
|
56
|
+
summary: Console colorize text
|
77
57
|
test_files: []
|