Module: Scripto::PrintCommands
Constant Summary collapse
- RESET =
"\e[0m".freeze
- GREEN =
"\e[1;37;42m".freeze
- YELLOW =
"\e[1;37;43m".freeze
- RED =
"\e[1;37;41m".freeze
Instance Attribute Summary collapse
-
#verbose ⇒ Object
Returns the value of attribute verbose.
Instance Method Summary collapse
-
#banner(str, color: GREEN) ⇒ Object
Print a colored banner to $stderr in green.
-
#fatal(str) ⇒ Object
Print a red error banner to $stderr, then exit.
-
#vbanner(str = nil) ⇒ Object
Print a colored banner to $stderr, but only if #verbose?.
-
#verbose! ⇒ Object
Turn on verbose mode.
-
#verbose? ⇒ Boolean
Is verbose mode turned on?.
-
#vprintf(str, *args) ⇒ Object
Printf to $stderr, but only if #verbose?.
-
#vputs(str = nil) ⇒ Object
Puts to $stderr, but only if #verbose?.
-
#warning(str) ⇒ Object
Print a yellow warning banner to $stderr.
Instance Attribute Details
#verbose ⇒ Object
Returns the value of attribute verbose.
8 9 10 |
# File 'lib/scripto/print_commands.rb', line 8 def verbose @verbose end |
Instance Method Details
#banner(str, color: GREEN) ⇒ Object
Print a colored banner to $stderr in green.
37 38 39 40 41 |
# File 'lib/scripto/print_commands.rb', line 37 def (str, color: GREEN) now = Time.new.strftime('%H:%M:%S') s = "#{str} ".ljust(72, ' ') $stderr.puts "#{color}[#{now}] #{s}#{RESET}" end |
#fatal(str) ⇒ Object
Print a red error banner to $stderr, then exit.
49 50 51 52 |
# File 'lib/scripto/print_commands.rb', line 49 def fatal(str) (str, color: RED) exit(1) end |
#vbanner(str = nil) ⇒ Object
Print a colored banner to $stderr, but only if #verbose?.
22 23 24 |
# File 'lib/scripto/print_commands.rb', line 22 def (str = nil) (str) if verbose? end |
#verbose! ⇒ Object
Turn on verbose mode. #vbanner, #vputs and #vprintf will start printing now, and file ops will be printed too.
17 18 19 |
# File 'lib/scripto/print_commands.rb', line 17 def verbose! @verbose = true end |
#verbose? ⇒ Boolean
Is verbose mode turned on?
11 12 13 |
# File 'lib/scripto/print_commands.rb', line 11 def verbose? !!@verbose end |
#vprintf(str, *args) ⇒ Object
Printf to $stderr, but only if #verbose?.
32 33 34 |
# File 'lib/scripto/print_commands.rb', line 32 def vprintf(str, *args) $stderr.printf(str, *args) if verbose? end |
#vputs(str = nil) ⇒ Object
Puts to $stderr, but only if #verbose?.
27 28 29 |
# File 'lib/scripto/print_commands.rb', line 27 def vputs(str = nil) $stderr.puts(str) if verbose? end |
#warning(str) ⇒ Object
Print a yellow warning banner to $stderr.
44 45 46 |
# File 'lib/scripto/print_commands.rb', line 44 def warning(str) ("Warning: #{str}", color: YELLOW) end |