Module: Mybot::Fmt
Constant Summary collapse
- WIDTH =
10
Instance Method Summary collapse
- #asterisks(str) ⇒ Object
- #colored(str, *colors) ⇒ Object
- #print_cmd(type, msg, *colors) ⇒ Object
- #print_cmd!(type, msg, *colors) ⇒ Object
- #print_progress(n) ⇒ Object
- #print_stderr(data, force = false) ⇒ Object
- #print_stdout(data, force = false) ⇒ Object
- #spaces(str) ⇒ Object
Instance Method Details
#asterisks(str) ⇒ Object
48 49 50 |
# File 'lib/mybot/fmt.rb', line 48 def asterisks(str) "*" * str.size end |
#colored(str, *colors) ⇒ Object
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/mybot/fmt.rb', line 33 def colored(str, *colors) if $MYBOT_USE_COLORS colors.each do |c| str = str.send(c) end str else str end end |
#print_cmd(type, msg, *colors) ⇒ Object
7 8 9 10 11 |
# File 'lib/mybot/fmt.rb', line 7 def print_cmd(type, msg, *colors) if $MYBOT_SHOW_CMD $stdout.print "#{spaces(type)}#{colored(type, *colors)} #{msg.to_s}" end end |
#print_cmd!(type, msg, *colors) ⇒ Object
13 14 15 |
# File 'lib/mybot/fmt.rb', line 13 def print_cmd!(type, msg, *colors) print_cmd type, "#{msg}\n", *colors end |
#print_progress(n) ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/mybot/fmt.rb', line 25 def print_progress(n) if $MYBOT_SHOW_CMD cmd = colored "progress", :blue, :bold $stdout.print "\r#{spaces('progress')}#{cmd} #{n}%" puts if n == 100 end end |
#print_stderr(data, force = false) ⇒ Object
21 22 23 |
# File 'lib/mybot/fmt.rb', line 21 def print_stderr(data, force = false) $stdout.print colored(data, :red) if $MYBOT_SHOW_OUTPUT || force end |
#print_stdout(data, force = false) ⇒ Object
17 18 19 |
# File 'lib/mybot/fmt.rb', line 17 def print_stdout(data, force = false) $stdout.print colored(data, :green) if $MYBOT_SHOW_OUTPUT || force end |
#spaces(str) ⇒ Object
44 45 46 |
# File 'lib/mybot/fmt.rb', line 44 def spaces(str) " " * (WIDTH - str.size) end |