module Geordi::Interaction
Public Instance Methods
announce(text)
click to toggle source
Start your command by `announce`-ing what you're about to do
# File lib/geordi/interaction.rb, line 9 def announce(text) message = "\n# #{text}" puts "\e[4;34m#{message}\e[0m" # blue underline end
fail(text)
click to toggle source
Exit execution with status code 1 and give a short note what happened, e.g. “Failed” or “Cancelled”
# File lib/geordi/interaction.rb, line 36 def fail(text) message = "\nx #{text}" puts "\e[31m#{message}\e[0m" # red exit(1) end
note(text)
click to toggle source
Any meta information, i.e. hints, comments, infos or explanations should be printed with `note`. Please do not use it for command output (data, file contents, lists etc).
# File lib/geordi/interaction.rb, line 17 def note(text) puts '> ' + text end
note_cmd(text)
click to toggle source
Like `note`, but pink. Use to print (bash) commands. Also see Util.run!
# File lib/geordi/interaction.rb, line 29 def note_cmd(text) message = "> #{text}" puts "\e[35m#{message}\e[0m" # pink end
prompt(text, default = nil, agreement_regex = nil)
click to toggle source
Returns the user's input. If agreement_regex is given, returns whether the input matches the regex.
# File lib/geordi/interaction.rb, line 51 def prompt(text, default = nil, agreement_regex = nil) message = "#{text} " message << "[#{default}] " if default print "\e[36m#{message}\e[0m" # cyan input = $stdin.gets.strip input = default if input.empty? && default agreement_regex ? !!(input =~ agreement_regex) : input end
success(text)
click to toggle source
When you're done, inform the user with a `success` and a short message. It should be a sentence (i.e. ending with [.!?]).
# File lib/geordi/interaction.rb, line 44 def success(text) message = "\n> #{text}" puts "\e[32m#{message}\e[0m" # green end
warn(text)
click to toggle source
Like `note`, but yellow. Use to warn the user.
# File lib/geordi/interaction.rb, line 22 def warn(text) message = "> #{text}" puts "\e[33m#{message}\e[0m" # yellow end