Module: CARPS::UI

Defined in:
lib/carps/ui/warn.rb,
lib/carps/ui/error.rb,
lib/carps/ui/question.rb,
lib/carps/ui/highlight.rb

Class Method Summary collapse

Class Method Details

.confirm(question) ⇒ Object

Ask a question, return a boolean



35
36
37
38
39
# File 'lib/carps/ui/question.rb', line 35

def UI::confirm question
   h = HighLine.new
   resp = h.ask h.color("#{question}\n(Type anything beginning with y to accept)", :green)
   resp[0] == "y"
end

.highlight(text) ⇒ Object

Highlight text



25
26
27
28
# File 'lib/carps/ui/highlight.rb', line 25

def UI::highlight text
   h = HighLine.new
   puts h.color text, :magenta, :bold
end

.put_error(msg, default_error = true) ⇒ Object

Output an error message

If the second parameter is true, the error message will begin with “Error:”



28
29
30
31
32
33
34
35
36
# File 'lib/carps/ui/error.rb', line 28

def UI::put_error msg, default_error=true
   h = HighLine.new
   prelude = ""
   if default_error
      prelude = "Error:  "
   end
   $stderr.write h.color("#{prelude}#{msg}", :error)
   puts "\a"
end

.question(msg) ⇒ Object

Ask a question. Get a string for an answer

Calls untaint on the answer



44
45
46
47
48
49
# File 'lib/carps/ui/question.rb', line 44

def UI::question msg
   h = HighLine.new
   res = h.ask h.color(msg, :green)
   # Trust the user
   res.untaint
end

.secret(msg) ⇒ Object

Ask a question and don’t echo what is typed.

Calls untaint on the password



54
55
56
57
58
59
# File 'lib/carps/ui/question.rb', line 54

def UI::secret msg
   h = HighLine.new
   ooh = h.ask(h.color(msg, :green)) {|q| q.echo = "*"}
   h.untaint
   ooh
end

.warn(reason, *msgs) ⇒ Object

Print a warning message to stderr



25
26
27
28
29
30
31
32
33
# File 'lib/carps/ui/warn.rb', line 25

def UI::warn reason, *msgs
   h = HighLine.new
   $stderr.write h.color("Warning:\n", :warning)
   $stderr.write h.color(reason + "\n", :warning)
   msgs.each do |msg|
      $stderr.write msg + "\n"
   end
   puts "\a" 
end