colsole 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/colsole.rb +6 -5
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3db079cae8519d734654ce7125535d50b257cf97
|
4
|
+
data.tar.gz: 27f0788a827c47b3604138a9f15f4f4b52b2a8fc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3479056ccd79ded2108630b7c2ad0cbb6be413d309b61ba29913c79fe3cbd78e004aa78e45bf01aa400b9d60d88c18757d94b8a0a736f1d27d9d3c3d50d901f8
|
7
|
+
data.tar.gz: 70a10ee63a68db38f2cd83ef765061ac852d503a9470fb556991ed6400d3347060f909c5e150af80e31f67b4c5677a6154de87b7a3a9f29200eba37dce4ef99d
|
data/lib/colsole.rb
CHANGED
@@ -6,11 +6,12 @@
|
|
6
6
|
# - #colorize string - return a colorized strings
|
7
7
|
# - #say string - print a string with colors
|
8
8
|
# - #resay string - same as say, but overwrite current line
|
9
|
-
# - #word_wrap
|
9
|
+
# - #word_wrap string - wrap a string and maintain indentation
|
10
10
|
# - #detect_terminal_size
|
11
11
|
#
|
12
12
|
# Credits:
|
13
13
|
# terminal width detection by Gabrial Horner https://github.com/cldwalker
|
14
|
+
# color mapping by ondrovic http://www.backtrack-linux.org/forums/showthread.php?t=29691&s=f681fb882b13be26ee726e5f335d089e
|
14
15
|
|
15
16
|
module Colsole
|
16
17
|
|
@@ -57,13 +58,13 @@ module Colsole
|
|
57
58
|
end
|
58
59
|
end
|
59
60
|
|
60
|
-
# Converts a long string to be wrapped.
|
61
|
+
# Converts a long string to be wrapped keeping words in tact.
|
61
62
|
# If the string starts with one or more spaces, they will be
|
62
63
|
# preserved in all subsequent lines (i.e., remain indented).
|
63
|
-
def word_wrap(
|
64
|
-
lead =
|
64
|
+
def word_wrap(text, length=78)
|
65
|
+
lead = text[/^\s*/]
|
65
66
|
length -= lead.size
|
66
|
-
|
67
|
+
text.gsub(/(.{1,#{length}})(\s+|\Z)/, "\\1\n#{lead}").rstrip
|
67
68
|
end
|
68
69
|
|
69
70
|
# Parses and returns a color-flagged string.
|