class Question::Input

Public Class Methods

new(question, default:nil) click to toggle source
# File lib/question/input.rb, line 3
def initialize(question, default:nil)
  @question = question
  @finished = false
  @default = default
  @answer = nil
end

Public Instance Methods

ask() click to toggle source
# File lib/question/input.rb, line 10
def ask
  print TTY::CODE::SAVE
  question = colorized_question
  question += "(#{@default}) ".light_white if @default

  # Use readline so keyboard shortcuts like alt-backspace work
  @answer = Readline.readline(question + TTY::CODE::NOOP, true)
  @answer = @default if @default && @answer.length == 0

  render
  @answer
rescue Interrupt
  exit 1
end
colorized_question() click to toggle source
# File lib/question/input.rb, line 32
def colorized_question
  colorized_question = "? ".cyan
  colorized_question += @question
  colorized_question += ": "
end
render() click to toggle source
# File lib/question/input.rb, line 25
def render
  TTY.clear
  print colorized_question
  print @answer.green
  print "\n"
end