lib/cliutils/pretty_io.rb in cliutils-2.0.3 vs lib/cliutils/pretty_io.rb in cliutils-2.1.0

- old
+ new

@@ -55,17 +55,16 @@ # @param [String] text The text to wrap # @param [String] prefix_str The prefix for each line # @return [String] def _word_wrap(text, prefix_str) if PrettyIO.wrap - return text if PrettyIO.wrap_char_limit <= 0 - + return prefix_str + text if PrettyIO.wrap_char_limit <= 0 limit = PrettyIO.wrap_char_limit - prefix_str.length - text.to_s.gsub(/\n/, ' ') - .gsub(/(.{1,#{ limit }})(\s+|$)/, "#{ prefix_str }\\1\n") - .strip + text.split("\n").collect! do |line| + line.length > limit ? text.gsub(/(.{1,#{ limit }})(\s+|$)/, "#{ prefix_str }\\1\n").strip : prefix_str + line + end * "\n" else - text + prefix_str + text end end end end