Module: Geordi::Interaction

Included in:
CLI, Cucumber, DumpLoader, FirefoxForSelenium, FirefoxForSelenium::Installer, Remote, Util, Gitpt
Defined in:
lib/geordi/interaction.rb

Instance Method Summary collapse

Instance Method Details

#announce(text) ⇒ Object



4
5
6
7
# File 'lib/geordi/interaction.rb', line 4

def announce(text)
  message = "\n# #{text}"
  puts "\e[4;34m#{message}\e[0m" # blue underline
end

#fail(text) ⇒ Object



23
24
25
26
27
# File 'lib/geordi/interaction.rb', line 23

def fail(text)
  message = "\nx #{text}"
  puts "\e[31m#{message}\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)
  message = "> #{text}"
  puts "\e[35m#{message}\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)
  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

#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)
  message = "\n> #{text}"
  puts "\e[32m#{message}\e[0m" # green
end

#warn(text) ⇒ Object



13
14
15
16
# File 'lib/geordi/interaction.rb', line 13

def warn(text)
  message = "> #{text}"
  puts "\e[33m#{message}\e[0m" # yellow
end