Module: Autoweb::UI

Included in:
Command, Command::Base, Input
Defined in:
lib/autoweb/ui.rb

Defined Under Namespace

Classes: Input, RetryError

Instance Method Summary collapse

Instance Method Details

#askObject



81
82
83
# File 'lib/autoweb/ui.rb', line 81

def ask
  gets.strip
end

#ask_loop(message, &block) ⇒ Object



71
72
73
74
75
76
77
78
79
# File 'lib/autoweb/ui.rb', line 71

def ask_loop(message,&block)
  display2 message+" "
  begin
    yield Input.new(ask)
  rescue RetryError => e
    display2 message
    retry      
  end
end

#confirm(message = nil, options = {}) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/autoweb/ui.rb', line 49

def confirm(message=nil, options={})
  if message.nil?
    message = "Are you sure you wish to continue?"
  end
  
  message << "(y/q/h)"
  
  ask_loop(message) do |input|
    if input.yes?
      yield
    else
      input.process_default(:help=>options[:help])
    end
  end
  ask.downcase == 'y'
end

#display(msg, new_line = true) ⇒ Object



30
31
32
33
34
35
36
37
38
# File 'lib/autoweb/ui.rb', line 30

def display(msg, new_line = true)
  msg = msg.to_s.gsub(/_/) { ' ' } 
  if new_line
    STDOUT.puts msg
  else
    STDOUT.print msg
  end
  STDOUT.flush
end

#display2(msg) ⇒ Object



45
46
47
# File 'lib/autoweb/ui.rb', line 45

def display2(msg)
  display(msg,false)
end

#error(msg = "error") ⇒ Object



40
41
42
43
# File 'lib/autoweb/ui.rb', line 40

def error(msg="error")
  display msg
  exit(1)
end

#format_date(date) ⇒ Object



66
67
68
69
# File 'lib/autoweb/ui.rb', line 66

def format_date(date)
  date = Time.parse(date) if date.is_a?(String)
  date.strftime("%Y-%m-%d %H:%M %Z")
end

#shell(cmd) ⇒ Object



85
86
87
# File 'lib/autoweb/ui.rb', line 85

def shell(cmd)
  FileUtils.cd(Dir.pwd) {|d| return `#{cmd}`}
end