Class: Dooby::CLIHelper

Inherits:
Object show all
Defined in:
lib/dooby/cli_helper.rb

Constant Summary collapse

DEL_TASKS =
"Sure you want to delete all the items???".red_on_white.bold
TRASH =
"Sure you want to delete the .dooby directory???".red_on_white.bold

Class Method Summary collapse

Class Method Details

.flush?Boolean

Returns:

  • (Boolean)


7
8
9
# File 'lib/dooby/cli_helper.rb', line 7

def self.flush?
  agree DEL_TASKS, true      
end

.keep_asking(question, autocompletion = []) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/dooby/cli_helper.rb', line 15

def self.keep_asking(question, autocompletion = [])
  Readline.basic_word_break_characters = 
      Readline.basic_word_break_characters.delete("@")
  Readline.completion_append_character = " "
  Readline.completion_proc = proc { |s| autocompletion.grep( /^#{Regexp.escape(s)}/ ) }
  
  stty_save = `stty -g`.chomp
  
  while value = Readline.readline(question, true)
      exit if value == 'q'
      yield value.chomp.strip
  end      

  rescue Interrupt
    system("stty", stty_save)
    exit
end

.trash?Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/dooby/cli_helper.rb', line 11

def self.trash?
  agree TRASH, true
end