Class: Thor::Shell::Basic
- Inherits:
-
Object
- Object
- Thor::Shell::Basic
- Defined in:
- lib/cinch/bot_template/main/thor.rb
Instance Method Summary collapse
- #prepare_message(message, *color, paint: true) ⇒ Object
-
#Thor::Shell::Basic.print_wrapped ⇒ Object
1.
-
#say(message = "", color = nil, force_new_line = (message.to_s !~ /( |\t)\Z/), paint: true) ⇒ Object
Say (print) something to the user.
Instance Method Details
#prepare_message(message, *color, paint: true) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/cinch/bot_template/main/thor.rb', line 51 def (, *color, paint: true) case paint when true spaces = " " * padding spaces + Paint[.to_s, *color] when false spaces = " " * padding spaces + set_color(.to_s, *color) else spaces = " " * padding spaces + Paint[.to_s, *color] end end |
#Thor::Shell::Basic.print_wrapped ⇒ Object
Note:
Override Thor::Shell::Basic.print_wrapped
88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/cinch/bot_template/main/thor.rb', line 88 def print_wrapped(, = {}) .lstrip! .gsub!(/\n\s+/, "\n") = .split("\n") .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") stdout.puts line end end |
#say(message = "", color = nil, force_new_line = (message.to_s !~ /( |\t)\Z/), paint: true) ⇒ Object
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.”)
73 74 75 76 77 78 79 |
# File 'lib/cinch/bot_template/main/thor.rb', line 73 def say( = "", color = nil, force_new_line = (.to_s !~ /( |\t)\Z/), paint: true) buffer = (, *color, paint: paint) buffer << "\n" if force_new_line && !.to_s.end_with?("\n") stdout.print(buffer) stdout.flush end |