Class: Achoo::Term

Inherits:
Object
  • Object
show all
Defined in:
lib/achoo/term.rb,
lib/achoo/term.rb,
lib/achoo/term/menu.rb,
lib/achoo/term/table.rb

Defined Under Namespace

Classes: Menu, Table

Class Method Summary collapse

Class Method Details

.ask(question = '') ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/achoo/term.rb', line 25

def self.ask(question='')
  answer = nil
  loop do
    print bold("#{question}> ")
    $stdout.flush
    answer = gets

    # Answer is nil if user hits C-d on an empty input
    if answer.nil?
      puts
      exit
    end
    
    answer.strip! unless answer.nil?

    # FIX move this to achoo.rb?
    unless $stdin.tty?
      puts answer
    end
    break unless a_little_something(answer)
  end
  answer
end

.bold(text) ⇒ Object



10
# File 'lib/achoo/term.rb', line 10

def self.bold(text); "\e[1m#{text}\e[0m"; end

.choose(question, entries, special = nil, additional_valid_answers = []) ⇒ Object



49
50
51
52
# File 'lib/achoo/term.rb', line 49

def self.choose(question, entries, special=nil, additional_valid_answers=[])
  menu = Achoo::Term::Menu.new(question, entries, special, additional_valid_answers)
  menu.print_ask_and_validate
end

.fatal(text) ⇒ Object



16
# File 'lib/achoo/term.rb', line 16

def self.fatal(text); "\e[1;31m#{text}\e[0m"; end

.passwordObject



18
19
20
21
22
23
# File 'lib/achoo/term.rb', line 18

def self.password
  `stty -echo`
  pas = ask('Password')
  `stty echo`
  pas
end

.underline(text) ⇒ Object



12
# File 'lib/achoo/term.rb', line 12

def self.underline(text); "\e[4m#{text}\e[0m"; end

.warn(text) ⇒ Object



14
# File 'lib/achoo/term.rb', line 14

def self.warn(text); "\e[1;33m#{text}\e[0m"; end