Module: Geordi::Interaction
- Included in:
- CLI, Cucumber, DumpLoader, FirefoxForSelenium, FirefoxForSelenium::Installer, Remote, Util, Gitpt
- Defined in:
- lib/geordi/interaction.rb
Instance Method Summary collapse
- #announce(text) ⇒ Object
- #fail(text) ⇒ Object
- #note(text) ⇒ Object
- #note_cmd(text) ⇒ Object
-
#prompt(text, default = nil, agreement_regex = nil) ⇒ Object
Returns the user’s input.
- #strip_heredoc(string) ⇒ Object
- #success(text) ⇒ Object
- #warn(text) ⇒ Object
Instance Method Details
#announce(text) ⇒ Object
4 5 6 7 |
# File 'lib/geordi/interaction.rb', line 4 def announce(text) = "\n# #{text}" puts "\e[4;34m#{}\e[0m" # blue underline end |
#fail(text) ⇒ Object
23 24 25 26 27 |
# File 'lib/geordi/interaction.rb', line 23 def fail(text) = "\nx #{text}" puts "\e[31m#{}\e[0m" # red exit(1) end |
#note(text) ⇒ Object
9 10 11 |
# File 'lib/geordi/interaction.rb', line 9 def note(text) puts '> ' + text end |
#note_cmd(text) ⇒ Object
18 19 20 21 |
# File 'lib/geordi/interaction.rb', line 18 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.
42 43 44 45 46 47 48 49 50 51 |
# File 'lib/geordi/interaction.rb', line 42 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
34 35 36 37 38 |
# File 'lib/geordi/interaction.rb', line 34 def strip_heredoc(string) leading_whitespace = (string.match(/\A( +)[^ ]+/) || [])[1] string.gsub! /^#{leading_whitespace}/, '' if leading_whitespace string end |
#success(text) ⇒ Object
29 30 31 32 |
# File 'lib/geordi/interaction.rb', line 29 def success(text) = "\n> #{text}" puts "\e[32m#{}\e[0m" # green end |
#warn(text) ⇒ Object
13 14 15 16 |
# File 'lib/geordi/interaction.rb', line 13 def warn(text) = "> #{text}" puts "\e[33m#{}\e[0m" # yellow end |