Class: String
Constant Summary collapse
- AnsiMap =
{"k" => 0, "r" => 1, "g" => 2, "y" => 3, "b" => 4, "m" => 5, "c" => 6, "w" => 7, "d" => 9}
Instance Method Summary collapse
- #color(color, fg = true) ⇒ Object
-
#wrap(max_chars_per_line = 80) ⇒ Object
Wraps long string by lines, using whitespace boundaries.
Instance Method Details
#color(color, fg = true) ⇒ Object
12 13 14 15 16 |
# File 'lib/swak/toplevel.rb', line 12 def color(color, fg=true) raise "Illegal color" unless AnsiMap.include?(color) color_int = AnsiMap[color] return "[#{fg ? 3 : 4}#{color_int}m#{self}[#{fg ? 3 : 4}9m" end |
#wrap(max_chars_per_line = 80) ⇒ Object
Wraps long string by lines, using whitespace boundaries
19 20 21 |
# File 'lib/swak/toplevel.rb', line 19 def wrap(max_chars_per_line=80) return gsub(/\n/," ").scan(/\S.{0,#{max_chars_per_line-2}}\S(?=\s|$)|\S+/).join("\n") end |