colsole 0.3.3 → 0.4.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: b6de4cbd3ede2c98135cbe010b74a600f8dc5e85
4
- data.tar.gz: 1982bb0999e283100ad40997c096331e6005ee16
3
+ metadata.gz: 6635dbbf550e4f14b3fce39cdd3bf9ef110f1195
4
+ data.tar.gz: 8957b89565d28da19efa69a56ec3b76cd5d77b55
5
5
  SHA512:
6
- metadata.gz: b066d600d0d33f8ad0114ce350cf401a5f86d45bb6ac78fa734269a49a70d4823bb914692edbfca6ab895de4ea69dac271654a7adb623434b3e130d9f4bb1807
7
- data.tar.gz: 18544d16a2ed90c759003b22b38083a744b69117e6fc4305734147dd14c5262a3ca6f4d699fb49390ee7d9ca5ad3569f3b7cef1ec14a28fde802796712c9c2ab
6
+ metadata.gz: 0e8d462f68985228c5aac42bba50f76fadcfcc3a064aa44f39dfe560509e5b4b03caacc8bcc01d1ab4a2167d90fb22b56ac482d6a9910decb65f847da2ec2784
7
+ data.tar.gz: 4438c599dd9bd5e716b943e43f1d89bad00e9470006c735b17008a545928129f1173a4da0f4851f71822cd9756ecbdc069c0f50b2e4c81c2ad73c6c8b36cb302
data/README.md CHANGED
@@ -6,9 +6,13 @@ Colsole
6
6
  [![Code Climate](https://codeclimate.com/github/DannyBen/colsole/badges/gpa.svg)](https://codeclimate.com/github/DannyBen/colsole)
7
7
  [![Gem](https://img.shields.io/gem/dt/colsole.svg)](https://rubygems.org/gems/colsole)
8
8
 
9
+ ---
9
10
 
10
11
  Utility functions for colorful console applications.
11
12
 
13
+ ---
14
+
15
+
12
16
  Install
13
17
  --------------------------------------------------
14
18
 
@@ -16,6 +20,16 @@ Install
16
20
  $ gem install colsole
17
21
  ```
18
22
 
23
+ Features
24
+ --------------------------------------------------
25
+
26
+ - Print colored messages
27
+ - Color parts of a message
28
+ - Print neatly aligned status messages
29
+ - Word wrap with indentation consideration
30
+
31
+ See the [Examples file][1] for more.
32
+
19
33
  Primary Functions
20
34
  --------------------------------------------------
21
35
 
@@ -40,6 +54,20 @@ Embed color markers in the string:
40
54
  say "!txtred!I am RED !txtgrn!I am GREEN"
41
55
  ```
42
56
 
57
+ ### `say_status :status, "message" [, :color]`
58
+
59
+ Print a message with a colored status
60
+
61
+ ```ruby
62
+ say_status :create, "perpetual energy"
63
+ ```
64
+
65
+ You can provide a color in the regulat 6 letter code:
66
+
67
+ ```ruby
68
+ say_status :error, "does not compute", :txtred
69
+ ```
70
+
43
71
  ### `word_wrap " string"`
44
72
 
45
73
  Wrap long lines while keeping words intact, and keeping
@@ -84,7 +112,6 @@ Parses and returns a color-flagged string.
84
112
  Respects pipe and auto terminates colored strings.
85
113
 
86
114
  Call without text to see a list/demo of all available colors.
87
-
88
115
 
89
116
  ### `terminal?`
90
117
 
@@ -99,3 +126,11 @@ Checks if the provided string is a command in the path.
99
126
  Returns an array [width, height] of the terminal, or the supplied
100
127
  `fallback_value` if it is unable to detect.
101
128
 
129
+
130
+ Color Codes
131
+ --------------------------------------------------
132
+
133
+ [![Color Codes](https://raw.githubusercontent.com/DannyBen/colsole/master/color-codes.png)](https://raw.githubusercontent.com/DannyBen/colsole/master/color-codes.png)
134
+
135
+
136
+ [1]: https://github.com/DannyBen/colsole/blob/master/example.rb
data/lib/colsole.rb CHANGED
@@ -2,13 +2,14 @@ require "colsole/version"
2
2
 
3
3
  # Colsole - Colorful Console Applications
4
4
  #
5
- # This class provides several utility functions for console
6
- # appliucation developers.
5
+ # This class provides several utility functions for console application
6
+ # developers.
7
7
  #
8
8
  # - #colorize string - return a colorized strings
9
9
  # - #say string - print a string with colors
10
10
  # - #say! string - print a string with colors to stderr
11
11
  # - #resay string - same as say, but overwrite current line
12
+ # - #say_status symbol, string [, color] - print a message with status
12
13
  # - #word_wrap string - wrap a string and maintain indentation
13
14
  # - #detect_terminal_size
14
15
  #
@@ -41,6 +42,13 @@ module Colsole
41
42
  say text, force_color
42
43
  end
43
44
 
45
+ # Prints a line with a colored status and message.
46
+ # Status can be a symbol or a string. Color is optional, defaulted to
47
+ # green (:txtgrn).
48
+ def say_status(status, message, color=:txtgrn)
49
+ say "!#{color}!#{status.to_s.rjust 12} !txtrst! #{message}"
50
+ end
51
+
44
52
  # Returns true if stdout/stderr is interactive terminal
45
53
  def terminal?(stream=:stdout)
46
54
  stream == :stdout ? out_terminal? : err_terminal?
@@ -88,8 +96,6 @@ module Colsole
88
96
  # Respects pipe and auto terminates colored strings.
89
97
  # Call without text to see a list/demo of all available colors.
90
98
  def colorize(text=nil, force_color=false, stream=:stdout)
91
- colors = prepare_colors
92
-
93
99
  if text.nil? # Demo
94
100
  i=33;
95
101
  colors.each do |k,v|
@@ -117,7 +123,11 @@ module Colsole
117
123
 
118
124
  private
119
125
 
120
- # Create a colors array with keys such as :green and :bld_green
126
+ def colors
127
+ @colors ||= prepare_colors
128
+ end
129
+
130
+ # Create a colors array with keys such as :txtgrn and :bldgrn
121
131
  # and values which are the escape codes for the colors.
122
132
  def prepare_colors
123
133
  esc = 27.chr
@@ -141,4 +151,4 @@ module Colsole
141
151
  end
142
152
  end
143
153
 
144
- self.extend Colsole
154
+ self.extend Colsole
@@ -1,3 +1,3 @@
1
1
  module Colsole
2
- VERSION = "0.3.3"
2
+ VERSION = "0.4.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: colsole
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Danny Ben Shitrit
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-17 00:00:00.000000000 Z
11
+ date: 2016-04-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: runfile