Method: HighLine::Terminal#readline_read

Defined in:
lib/highline/terminal.rb

#readline_read(question, highline) ⇒ Object

Use readline to read one line

Parameters:

  • question (HighLine::Question)

    question from where to get autocomplete candidate strings



112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/highline/terminal.rb', line 112

def readline_read(question, highline)
  # prep auto-completion
  unless question.selection.empty?
    Reline.completion_proc = lambda do |str|
      question.selection.grep(/\A#{Regexp.escape(str)}/)
    end
  end

  # TODO: Check if this is still needed after Reline
  # work-around ugly readline() warnings
  old_verbose = $VERBOSE
  $VERBOSE    = nil

  raw_answer  = run_preserving_stty do
    prompt = highline.render_and_ident_statement(question)
    Reline.readline(prompt, true)
  end

  $VERBOSE = old_verbose

  raw_answer
end