class Thor::Shell::Basic
Public Instance Methods
prepare_message(message, *color, paint: true)
click to toggle source
# File lib/dnsblim/thor.rb, line 51 def prepare_message(message, *color, paint: true) case paint when true spaces = " " * padding spaces + Paint[message.to_s, *color] when false spaces = " " * padding spaces + set_color(message.to_s, *color) else spaces = " " * padding spaces + Paint[message.to_s, *color] end end
print_wrapped(message, options = {})
click to toggle source
@note Override Thor::Shell::Basic.print_wrapped
@overload Thor::Shell::Basic.print_wrapped
1. Replace 6 - with 6 spaces 2. Replace 4 - with 4 spaces 3. Replace 2 - with 2 spaces 4. Replace #$ at the beginning of lines with '\n'
# File lib/dnsblim/thor.rb, line 88 def print_wrapped(message, options = {}) message.lstrip! message.gsub!(/\n\s+/, "\n") message = message.split("\n") message.each do |line| line.gsub!(/^------/, ' ' * 6) if line[0..5] == '-' * 6 line.gsub!(/^----/, ' ' * 4) if line[0..3] == '-' * 4 line.gsub!(/^--/, ' ' * 2) if line[0..1] == '-' * 2 line.gsub!(/^#\$/, "\n") if line[0..1] == '#$' line.gsub!(/^#%/, " ") if line[0..1] == '#%' line.gsub!(/^#\*/, line[2..-1]) if line[0..1] == '#*' stdout.puts line end end
say(message = "", color = nil, force_new_line = (message.to_s !~ /( |\t)\Z/), paint: true)
click to toggle source
Say (print) something to the user. If the sentence ends with a whitespace or tab character, a new line is not appended (print + flush). Otherwise are passed straight to puts (behavior got from Highline).
Example¶ ↑
say(“I know you knew that.”)
# File lib/dnsblim/thor.rb, line 73 def say(message = "", color = nil, force_new_line = (message.to_s !~ /( |\t)\Z/), paint: true) buffer = prepare_message(message, *color, paint: paint) buffer << "\n" if force_new_line && !message.to_s.end_with?("\n") stdout.print(buffer) stdout.flush end