Module: Flucti::Utilities::UserInterface

Extended by:
UserInterface
Included in:
Flucti::Utilities, UserInterface
Defined in:
lib/flucti/utilities/user_interface.rb

Instance Method Summary collapse

Instance Method Details

#confirm(message) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/flucti/utilities/user_interface.rb', line 39

def confirm(message)
  puts_title("/!\\ Warning")
  puts_long(message)
  puts "(You now have 10 seconds to cancel by pressing CTRL+C.)"
  puts

  if ENV['FORCE']
    puts "$FORCE set, proceeding forcefully."
  else
    # 10 second countdown to cancel
    begin
      10.downto(0) { |left| print(left, " "); sleep 1 }
    rescue Interrupt
      puts "\nAction cancelled."
      exit 0
    end
  end
end

#puts_list(entries, *args, &block) ⇒ Object



26
27
28
# File 'lib/flucti/utilities/user_interface.rb', line 26

def puts_list(entries, *args, &block)
  Utilities::ListDisplayer.new(*args, &block).display(entries)
end

#puts_long(message, io = $stdout) ⇒ Object



22
23
24
# File 'lib/flucti/utilities/user_interface.rb', line 22

def puts_long(message, io=$stdout)
  io.puts(adjust_to_terminal(message))
end

#puts_subtitle(title, io = $stdout) ⇒ Object



18
19
20
# File 'lib/flucti/utilities/user_interface.rb', line 18

def puts_subtitle(title, io=$stdout)
  generic_puts_title(io, title, "-", 6)
end

#puts_title(title, io = $stdout) ⇒ Object



14
15
16
# File 'lib/flucti/utilities/user_interface.rb', line 14

def puts_title(title, io=$stdout)
  generic_puts_title(io, title, "=", 3)
end

#qcommand(task_name) ⇒ Object



30
31
32
# File 'lib/flucti/utilities/user_interface.rb', line 30

def qcommand(task_name)
  quote(command(task_name))
end

#quote(str) ⇒ Object Also known as: q



34
35
36
# File 'lib/flucti/utilities/user_interface.rb', line 34

def quote(str)
  %(`#{str}')
end

#terminal_widthObject



6
7
8
9
10
11
12
# File 'lib/flucti/utilities/user_interface.rb', line 6

def terminal_width
  @terminal_width ||= begin
    # Avoid error messages on Windows
    result = RUBY_PLATFORM =~ /mswin/ ? "" : `stty size 2>/dev/null`
    (result.split[1] || 80).to_i
  end
end