kolorit 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/kolorit/linux.rb +83 -25
- data/lib/kolorit/version.rb +1 -1
- data/lib/kolorit.rb +39 -8
- metadata +7 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fdbfa5dc4a917af5db6c5af7d92c29784754f17afe28e28b9e9b2183bc30812d
|
4
|
+
data.tar.gz: 9c0c4f30ec7147f8b0ef26a794aca493a58eb150a050bb9f9004480efdb4bd0d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 312362814ac515dd8ab83a13531ea3fbbae6abade783a78f640b288869c9e0cdf0d36c1b9be8607328835373a1cb63d95f77081ac2c23fdf9c5c5ec8eff202f7
|
7
|
+
data.tar.gz: 58e3143322813034aee0ebc4fc57d8edf29fa5048fecec0005898aa26b2b5c0661b55d827ca1b4785ee103ea852ca49ebdff88a6c776865c31352b038dfa30cc
|
data/lib/kolorit/linux.rb
CHANGED
@@ -2,37 +2,95 @@
|
|
2
2
|
|
3
3
|
module Kolorit
|
4
4
|
##
|
5
|
-
#
|
6
|
-
# Allow use of
|
5
|
+
# kolor codes for linux systems.
|
6
|
+
# Allow use of kolor methods when included in class.
|
7
7
|
# @see Kolorit
|
8
|
+
# @see https://www.github.com/alx3dev/kolorit/README.md
|
9
|
+
#
|
10
|
+
# @todo Use `def red = kolor(int)` in ruby > 3.0
|
8
11
|
#
|
9
12
|
module Linux
|
10
|
-
def red
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
def
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
def
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
def
|
13
|
+
def red
|
14
|
+
kolor(31)
|
15
|
+
end
|
16
|
+
|
17
|
+
def green
|
18
|
+
kolor(32)
|
19
|
+
end
|
20
|
+
|
21
|
+
def yellow
|
22
|
+
kolor(33)
|
23
|
+
end
|
24
|
+
|
25
|
+
def blue
|
26
|
+
kolor(34)
|
27
|
+
end
|
28
|
+
|
29
|
+
def pink
|
30
|
+
kolor(35)
|
31
|
+
end
|
32
|
+
|
33
|
+
def cyan
|
34
|
+
kolor(36)
|
35
|
+
end
|
36
|
+
|
37
|
+
def gray
|
38
|
+
kolor(37)
|
39
|
+
end
|
40
|
+
|
41
|
+
def bold
|
42
|
+
kolor(1)
|
43
|
+
end
|
44
|
+
|
45
|
+
def italic
|
46
|
+
kolor(3)
|
47
|
+
end
|
48
|
+
|
49
|
+
def underline
|
50
|
+
kolor(4)
|
51
|
+
end
|
52
|
+
|
53
|
+
def blink
|
54
|
+
kolor(5)
|
55
|
+
end
|
56
|
+
|
57
|
+
def reverse_color
|
58
|
+
kolor(7)
|
59
|
+
end
|
60
|
+
alias inverse reverse_color
|
61
|
+
|
62
|
+
# @depreceated Use direct color methods insted #red, #blue ...
|
63
|
+
# this is part of code that make rubocop sad
|
64
|
+
def colorize(clr)
|
65
|
+
case clr.to_sym
|
66
|
+
when :red then red
|
67
|
+
when :green then green
|
68
|
+
when :yellow then yellow
|
69
|
+
when :blue then blue
|
70
|
+
when :pink then pink
|
71
|
+
when :cyan then cyan
|
72
|
+
when :gray then gray
|
73
|
+
when :bold then bold
|
74
|
+
when :italic then italic
|
75
|
+
when :underline then underline
|
76
|
+
when :blink then blink
|
77
|
+
when :reverse_color, :inverse then reverse_color
|
78
|
+
else self
|
79
|
+
end
|
80
|
+
end
|
23
81
|
|
24
82
|
private
|
25
83
|
|
26
|
-
def
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
"\e[#{color_code}m#{self}\e[#{
|
84
|
+
def kolor(color_code)
|
85
|
+
style = case color_code
|
86
|
+
when 1 then 22 # bold
|
87
|
+
when 3 then 23 # italic
|
88
|
+
when 4 then 24 # underline
|
89
|
+
when 5 then 25 # blink
|
90
|
+
when 7 then 27 # reverse_kolor
|
91
|
+
else 0
|
92
|
+
end
|
93
|
+
"\e[#{color_code}m#{self}\e[#{style}m"
|
36
94
|
end
|
37
95
|
end
|
38
96
|
end
|
data/lib/kolorit/version.rb
CHANGED
data/lib/kolorit.rb
CHANGED
@@ -6,6 +6,13 @@ require_relative 'kolorit/version'
|
|
6
6
|
# Handle modules with color codes and methods to colorize string.
|
7
7
|
# Right module is included depending on user OS.
|
8
8
|
#
|
9
|
+
# @example (opt 1) - Require everything and override String class
|
10
|
+
# require 'kolorit' => include color methods in class String
|
11
|
+
#
|
12
|
+
# @example (opt 2) - Require what you need, include where you need it
|
13
|
+
# require 'kolorit/linux' => just require, no override
|
14
|
+
# include Kolorit::Linux => use color methods in your class
|
15
|
+
#
|
9
16
|
# @example Colorize string
|
10
17
|
# 'I am mr Red String'.red
|
11
18
|
# 'I am mr Green String'.green
|
@@ -14,19 +21,43 @@ require_relative 'kolorit/version'
|
|
14
21
|
# @example Available colors
|
15
22
|
# red, green, yellow, blue, pink, cyan, gray
|
16
23
|
#
|
17
|
-
# @example Available
|
24
|
+
# @example Available styles
|
18
25
|
# bold, italic, underline, blink, reverse_color
|
19
26
|
#
|
20
27
|
module Kolorit
|
28
|
+
class << self
|
29
|
+
def env_os_win?
|
30
|
+
ENV['OS'] == 'Windows_NT'
|
31
|
+
end
|
32
|
+
|
33
|
+
def on_windows?
|
34
|
+
if env_os_win?
|
35
|
+
return false if RUBY_PLATFORM =~ /cygwin/
|
36
|
+
|
37
|
+
true
|
38
|
+
else
|
39
|
+
false
|
40
|
+
end
|
41
|
+
end
|
42
|
+
alias windows? on_windows?
|
43
|
+
end
|
21
44
|
end
|
22
45
|
|
46
|
+
raise(StandardError, 'Windows not supported, yet!', []) if Kolorit.on_windows?
|
47
|
+
|
23
48
|
klass = String
|
24
49
|
|
25
|
-
if
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
50
|
+
if Kolorit.windows? && !defined?(Kolorit::Windows)
|
51
|
+
require_relative 'kolorit/windows'
|
52
|
+
klass.include Kolorit::Windows
|
53
|
+
|
54
|
+
elsif !defined?(Kolorit::Linux)
|
55
|
+
begin
|
56
|
+
require 'win32console' if Kolorit.env_os_win?
|
57
|
+
rescue StandardError
|
58
|
+
raise StandardError 'please run: $ gem install win32console.'
|
59
|
+
ensure
|
60
|
+
require_relative 'kolorit/linux'
|
61
|
+
klass.include(Kolorit::Linux)
|
62
|
+
end
|
32
63
|
end
|
metadata
CHANGED
@@ -1,18 +1,19 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kolorit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- alx3dev
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-01-
|
11
|
+
date: 2022-01-30 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: |
|
14
|
-
Print your terminal output in different colors.
|
15
|
-
|
14
|
+
Print your terminal output in different colors. Now compatible with Ruby version 2,
|
15
|
+
not only 3. Linux and Mac, Windows should work with `win32console` but not tested.
|
16
|
+
Early development stage, MIT license.
|
16
17
|
email:
|
17
18
|
- alx3dev@gmail.com
|
18
19
|
executables: []
|
@@ -30,7 +31,7 @@ metadata:
|
|
30
31
|
homepage_uri: https://www.github.com/alx3dev/kolorit
|
31
32
|
source_code_uri: https://www.github.com/alx3dev/kolorit
|
32
33
|
changelog_uri: https://www.github.com/alx3dev/kolorit/CHANGELOG.md
|
33
|
-
documentation_uri: https://rubydoc.info/gems/kolorit/0.1.
|
34
|
+
documentation_uri: https://rubydoc.info/gems/kolorit/0.1.5
|
34
35
|
license_uri: https://www.github.com/alx3dev/kolorit/LICENSE
|
35
36
|
post_install_message:
|
36
37
|
rdoc_options: []
|
@@ -43,7 +44,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
43
44
|
version: 2.6.0
|
44
45
|
- - "<"
|
45
46
|
- !ruby/object:Gem::Version
|
46
|
-
version:
|
47
|
+
version: 3.2.0
|
47
48
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
48
49
|
requirements:
|
49
50
|
- - ">="
|