colsole 0.3.3 → 0.4.0
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 +4 -4
- data/README.md +36 -1
- data/lib/colsole.rb +16 -6
- data/lib/colsole/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6635dbbf550e4f14b3fce39cdd3bf9ef110f1195
|
4
|
+
data.tar.gz: 8957b89565d28da19efa69a56ec3b76cd5d77b55
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0e8d462f68985228c5aac42bba50f76fadcfcc3a064aa44f39dfe560509e5b4b03caacc8bcc01d1ab4a2167d90fb22b56ac482d6a9910decb65f847da2ec2784
|
7
|
+
data.tar.gz: 4438c599dd9bd5e716b943e43f1d89bad00e9470006c735b17008a545928129f1173a4da0f4851f71822cd9756ecbdc069c0f50b2e4c81c2ad73c6c8b36cb302
|
data/README.md
CHANGED
@@ -6,9 +6,13 @@ Colsole
|
|
6
6
|
[](https://codeclimate.com/github/DannyBen/colsole)
|
7
7
|
[](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
|
+
[](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
|
-
#
|
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
|
-
|
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
|
data/lib/colsole/version.rb
CHANGED
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.
|
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-
|
11
|
+
date: 2016-04-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: runfile
|