colsole 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/colsole.rb +6 -5
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cbc8652316a38aa489da38bf41ab5b8ed80345cf
4
- data.tar.gz: f2c9326df03216c679ece2e781865535205c2404
3
+ metadata.gz: 3db079cae8519d734654ce7125535d50b257cf97
4
+ data.tar.gz: 27f0788a827c47b3604138a9f15f4f4b52b2a8fc
5
5
  SHA512:
6
- metadata.gz: ae10295f566048a817f080ba423d78da32b3e2420f23bb7f825aca9eb54cd896ab04fdab528926505af360ecc9e85ba4f00ab41e0ddf4008fb162d1fa7b78917
7
- data.tar.gz: 886142fa600050681d2bf8ea11b89907749a1797b75abb0089aa7940097c189a07687479a7d236f56389771b42cd8ac31fa5fe60f52da87774617b683ba22898
6
+ metadata.gz: 3479056ccd79ded2108630b7c2ad0cbb6be413d309b61ba29913c79fe3cbd78e004aa78e45bf01aa400b9d60d88c18757d94b8a0a736f1d27d9d3c3d50d901f8
7
+ data.tar.gz: 70a10ee63a68db38f2cd83ef765061ac852d503a9470fb556991ed6400d3347060f909c5e150af80e31f67b4c5677a6154de87b7a3a9f29200eba37dce4ef99d
@@ -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 strimg - wrap a string and maintain indentation
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(str, length=80, character=$/)
64
- lead = str[/^\s+/]
64
+ def word_wrap(text, length=78)
65
+ lead = text[/^\s*/]
65
66
  length -= lead.size
66
- str.scan(/.{#{length}}|.+/).map { |x| "#{lead}#{x.strip}" }.join(character)
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.
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: colsole
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Danny Ben Shitrit