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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 219b95536dadf60c775fc7346daf11c5e5d2150bc634f9effb2c2008b6b83fd6
4
- data.tar.gz: bd0c07c902a020d41f8df17952b6df00330954ffce38809a2b34faec46cf7c47
3
+ metadata.gz: fdbfa5dc4a917af5db6c5af7d92c29784754f17afe28e28b9e9b2183bc30812d
4
+ data.tar.gz: 9c0c4f30ec7147f8b0ef26a794aca493a58eb150a050bb9f9004480efdb4bd0d
5
5
  SHA512:
6
- metadata.gz: 5842b9370bedb89d2daf73ef8018f144271cd3851a164a8157dcc3388541b9773312c24782a113670d9a2b6ec1cd88f14d82b4cb25197dda0b46c77dbf50b914
7
- data.tar.gz: fbda9da5af368ec58ee28bd1bb6927d93655f793c3f184eafb6123b19e8d0e62b320fc4fce7617f2bc9e9803720963d36346e9262d8b902bbc3cce8f2e022836
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
- # Color codes for linux systems.
6
- # Allow use of color methods when included in **String** class.
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 = colorize(31)
11
- def green = colorize(32)
12
- def yellow = colorize(33)
13
- def blue = colorize(34)
14
- def pink = colorize(35)
15
- def cyan = colorize(36)
16
- def gray = colorize(37)
17
-
18
- def bold = colorize(1)
19
- def italic = colorize(3)
20
- def underline = colorize(4)
21
- def blink = colorize(5)
22
- def reverse_color = colorize(7)
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 colorize(color_code)
27
- type = case color_code
28
- when 1 then 22 # bold
29
- when 3 then 23 # italic
30
- when 4 then 24 # underline
31
- when 5 then 25 # blink
32
- when 7 then 27 # reverse_color
33
- else 0
34
- end
35
- "\e[#{color_code}m#{self}\e[#{type}m"
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
@@ -2,5 +2,5 @@
2
2
 
3
3
  module Kolorit
4
4
  # gem version
5
- VERSION = '0.1.4'
5
+ VERSION = '0.1.5'
6
6
  end
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 types
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 ENV['OS'] == 'Windows_NT'
26
- # working on windows color codes
27
- # require_relative 'kolorit/windows'
28
- # klass.include Kolorit::Windows unless RUBY_PLATFORM =~ /cygwin/
29
- else
30
- require_relative 'kolorit/linux'
31
- klass.include(Kolorit::Linux)
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
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-26 00:00:00.000000000 Z
11
+ date: 2022-01-30 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: |
14
- Print your terminal output in different colors. Early development stage,
15
- for now only Linux and Mac. MIT license.
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.4
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: 4.0.0
47
+ version: 3.2.0
47
48
  required_rubygems_version: !ruby/object:Gem::Requirement
48
49
  requirements:
49
50
  - - ">="