Module: Geordi::Interaction
- Included in:
- CLI, ChromedriverUpdater, Cucumber, DBCleaner, DumpLoader, FirefoxForSelenium, FirefoxForSelenium::Installer, Remote, Util, Gitpt
- Defined in:
- lib/geordi/interaction.rb
Instance Method Summary collapse
-
#announce(text) ⇒ Object
Start your command by ‘announce`-ing what you’re about to do.
-
#fail(text) ⇒ Object
Exit execution with status code 1 and give a short note what happened, e.g.
-
#note(text) ⇒ Object
Any hints, comments, infos or explanations should be ‘note`d.
-
#note_cmd(text) ⇒ Object
Like ‘note`, but pink.
-
#prompt(text, default = nil, agreement_regex = nil) ⇒ Object
Returns the user’s input.
- #strip_heredoc(string) ⇒ Object
-
#success(text) ⇒ Object
When you’re done, inform the user with a ‘success` and a short message.
-
#warn(text) ⇒ Object
Like ‘note`, but yellow.
Instance Method Details
#announce(text) ⇒ Object
Start your command by ‘announce`-ing what you’re about to do
7 8 9 10 |
# File 'lib/geordi/interaction.rb', line 7 def announce(text) = "\n# #{text}" puts "\e[4;34m#{}\e[0m" # blue underline end |
#fail(text) ⇒ Object
Exit execution with status code 1 and give a short note what happened, e.g. “Failed” or “Cancelled”
33 34 35 36 37 |
# File 'lib/geordi/interaction.rb', line 33 def fail(text) = "\nx #{text}" puts "\e[31m#{}\e[0m" # red exit(1) end |
#note(text) ⇒ Object
Any hints, comments, infos or explanations should be ‘note`d. Please do not print any output (data, file contents, lists) with `note`.
14 15 16 |
# File 'lib/geordi/interaction.rb', line 14 def note(text) puts '> ' + text end |
#note_cmd(text) ⇒ Object
Like ‘note`, but pink. Use to print (bash) commands. Also see Util.system!
26 27 28 29 |
# File 'lib/geordi/interaction.rb', line 26 def note_cmd(text) = "> #{text}" puts "\e[35m#{}\e[0m" # pink end |
#prompt(text, default = nil, agreement_regex = nil) ⇒ Object
Returns the user’s input. If agreement_regex is given, returns whether the input matches the regex.
53 54 55 56 57 58 59 60 61 62 |
# File 'lib/geordi/interaction.rb', line 53 def prompt(text, default = nil, agreement_regex = nil) = "#{text} " << "[#{default}] " if default print "\e[36m#{}\e[0m" # cyan input = $stdin.gets.strip input = default if input.empty? && default agreement_regex ? !!(input =~ agreement_regex) : input end |
#strip_heredoc(string) ⇒ Object
45 46 47 48 49 |
# File 'lib/geordi/interaction.rb', line 45 def strip_heredoc(string) leading_whitespace = (string.match(/\A( +)[^ ]+/) || [])[1] string.gsub! /^#{leading_whitespace}/, '' if leading_whitespace string end |
#success(text) ⇒ Object
When you’re done, inform the user with a ‘success` and a short message
40 41 42 43 |
# File 'lib/geordi/interaction.rb', line 40 def success(text) = "\n> #{text}" puts "\e[32m#{}\e[0m" # green end |
#warn(text) ⇒ Object
Like ‘note`, but yellow. Use to warn the user.
19 20 21 22 |
# File 'lib/geordi/interaction.rb', line 19 def warn(text) = "> #{text}" puts "\e[33m#{}\e[0m" # yellow end |