Class: Question::Input
- Inherits:
-
Object
- Object
- Question::Input
- Defined in:
- lib/question/input.rb
Instance Method Summary collapse
- #ask ⇒ Object
- #colorized_question ⇒ Object
-
#initialize(question, default: nil) ⇒ Input
constructor
A new instance of Input.
- #render ⇒ Object
Constructor Details
#initialize(question, default: nil) ⇒ Input
Returns a new instance of Input.
3 4 5 6 7 8 |
# File 'lib/question/input.rb', line 3 def initialize(question, default:nil) @question = question @finished = false @default = default @answer = nil end |
Instance Method Details
#ask ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# 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 ⇒ Object
32 33 34 35 36 |
# File 'lib/question/input.rb', line 32 def colorized_question colorized_question = "? ".cyan colorized_question += @question colorized_question += ": " end |