pad_utils 1.4.0 → 1.5.0

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
  SHA1:
3
- metadata.gz: 46369e29476640a59df9f7c0a8ac5864bbc24361
4
- data.tar.gz: c5a3ac14efe6a8d7700c0afc3e0420ecbe986cc2
3
+ metadata.gz: 5d05062387d59a912847835bd77a221c5b247b8c
4
+ data.tar.gz: 91271e1d7cf3a0b23c8c27610892e6671a3e92ef
5
5
  SHA512:
6
- metadata.gz: 2da2c9f8d35ec72b2246a398f4560e8b94fe010190c6f7a61f3b7b9680a5f76772145e2474e040c4cf8fc407a504ea3aac9a99b6e9e5e3d880fb076e575c880a
7
- data.tar.gz: 0fa3dd9e8a963b0e8fff13bae15a1816fc6a8a0f9ed1a479784bf40b65573f31cf9fb431764387cc50b65d4afe7026516ca1ec810233f3da3449770d750baaad
6
+ metadata.gz: a414d2aac63346c3962aa926639eefdea815f759ae3dbe4c0fdb9daea49e9a9b575339a5fe90d8338d03c881e90f89c157183c6e2144a0599533f5452b8a1774
7
+ data.tar.gz: 9a6465eacbb4333d517dc7c5b3488006a32a9d2758467858cdfe656fb39722edb79248a03ff5007c714a7eff94d9df5b3892308ccc89059834ffaae0722f21af
@@ -0,0 +1,50 @@
1
+ module PadUtils
2
+
3
+ # Colorizes the cli output.
4
+ #
5
+ # Colors have aliases:
6
+ #
7
+ # * `:blue` => `:note`, `:emphasis`
8
+ # * `:red` => `:error`, `:danger`, `:alert`, `:failure`
9
+ # * `:green` => `:correct`, `:success`, `:info`
10
+ #
11
+ # @param text [String] the string to output
12
+ # @param highlight [Symbol, nil] the color to be used (`:red`, `:green`, `:blue`, `nil`)
13
+ # @param wrap [Boolean] if `true`, will wrap the text at 80 characters
14
+ # @return [Void] nothing
15
+ # @example
16
+ # PadUtils.puts_c "Hello World", :green
17
+ def self.puts_c(text, highlight = nil, wrap = true)
18
+ # Set color codes
19
+ red = 31
20
+ green = 32
21
+ blue = 36
22
+
23
+ # Set color to use
24
+ current_color = nil
25
+ case highlight
26
+ when :red, :error, :danger, :alert, :failure
27
+ current_color = red
28
+ when :green, :correct, :success, :info
29
+ current_color = green
30
+ when :blue, :note, :emphasis
31
+ current_color = blue
32
+ else
33
+ current_color = nil
34
+ end
35
+
36
+ # Wrap the text
37
+ if wrap
38
+ text = text.gsub(/\n/, ' ').gsub(/(.{1,#{79}})(\s+|$)/, "\\1\n").strip
39
+ end
40
+
41
+ # Just display text if no color chosen. Else, colorize it.
42
+ if current_color == nil
43
+ STDOUT.puts text
44
+ else
45
+ STDOUT.puts "\e[#{current_color}m#{text}\e[0m"
46
+ end
47
+
48
+ end
49
+
50
+ end
@@ -1,4 +1,4 @@
1
1
  module PadUtils
2
2
  # PadUtils version number
3
- VERSION = "1.4.0"
3
+ VERSION = "1.5.0"
4
4
  end
data/lib/pad_utils.rb CHANGED
@@ -5,6 +5,7 @@ require_relative "pad_utils/pad_time"
5
5
  require_relative "pad_utils/pad_logger"
6
6
  require_relative "pad_utils/pad_menu"
7
7
  require_relative "pad_utils/pad_json"
8
+ require_relative "pad_utils/pad_color"
8
9
 
9
10
  # Main namespace for PadUtils.
10
11
  #
@@ -12,7 +13,6 @@ require_relative "pad_utils/pad_json"
12
13
  # @example
13
14
  # PadUtils.some_method(param)
14
15
  module PadUtils
15
- # TODO: Add a cli coloring feature
16
16
 
17
17
  def self.main(arg)
18
18
  puts
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pad_utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.0
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nico Schuele
@@ -25,6 +25,7 @@ files:
25
25
  - Rakefile
26
26
  - bin/padutils
27
27
  - lib/pad_utils.rb
28
+ - lib/pad_utils/pad_color.rb
28
29
  - lib/pad_utils/pad_files.rb
29
30
  - lib/pad_utils/pad_json.rb
30
31
  - lib/pad_utils/pad_logger.rb