module Prompt

CLI Prompt utilities

Public Instance Methods

choose_number(query = '->', max) click to toggle source
# File lib/bunch/url_generator.rb, line 42
def choose_number(query = '->', max)
  stty_save = `stty -g`.chomp
  sel = nil
  begin
    while !sel =~ /^\d+$/ || sel.to_i <= 0 || sel.to_i > max
      sel = Readline.readline("#{query}", true)
      return nil if sel =~ /^\s*$/
    end
  rescue Interrupt
    system('stty', stty_save) # Restore
    exit
  end
  sel ? sel.to_i : nil
end
get_line(query = '->') click to toggle source
# File lib/bunch/url_generator.rb, line 57
def get_line(query = '->')
  stty_save = `stty -g`.chomp
  begin
    line = Readline.readline("#{query}: ", true)
  rescue Interrupt
    system('stty', stty_save) # Restore
    exit
  end
  line.chomp
end
get_text(query = 'Enter text, ^d to end') click to toggle source
# File lib/bunch/url_generator.rb, line 68
def get_text(query = 'Enter text, ^d to end')
  stty_save = `stty -g`.chomp
  lines = []
  puts query
  begin
    while (line = Readline.readline)
      lines << line
    end
  rescue Interrupt
    system('stty', stty_save) # Restore
    exit
  end
  lines.join("\n").chomp
end
url_encode_text() click to toggle source
# File lib/bunch/url_generator.rb, line 83
def url_encode_text
  text = get_text
  puts
  CGI.escape(text)
end