class HighLine::Terminal
The specialized Terminals all decend from this HighLine::Terminal class
input and output to.
Basic Terminal class which HighLine will direct
def self.get_terminal(input, output)
-
output
(IO
) -- output stream -
input
(IO
) -- input stream
def self.get_terminal(input, output) # First of all, probe for io/console begin require "io/console" require "highline/terminal/io_console" terminal = HighLine::Terminal::IOConsole.new(input, output) rescue LoadError require "highline/terminal/unix_stty" terminal = HighLine::Terminal::UnixStty.new(input, output) end terminal.initialize_system_extensions terminal end
def character_mode
-
(String)
- class name. Ex: "HighLine::Terminal::IOConsole"
def character_mode self.class.name end
def get_character; end # rubocop:disable Naming/AccessorMethodName
-
(String)
- one character
def get_character; end # rubocop:disable Naming/AccessorMethodName
def get_line(question, highline)
-
highline
(HighLine
) -- -
question
(HighLine::Question
) --
def get_line(question, highline) raw_answer = if question.readline get_line_with_readline(question, highline) else get_line_default(highline) end question.format_answer(raw_answer) end
def get_line_default(highline)
-
highline
() --
def get_line_default(highline) raise EOFError, "The input stream is exhausted." if highline.track_eof? && highline.input.eof? highline.input.gets end
def get_line_with_readline(question, highline)
-
(
) --
def get_line_with_readline(question, highline) require "reline" # load only if needed raw_answer = readline_read(question, highline) if !raw_answer && highline.track_eof? raise EOFError, "The input stream is exhausted." end raw_answer || "" end
def initialize(input, output)
-
output
(IO
) -- output stream -
input
(IO
) -- input stream
def initialize(input, output) @input = input @output = output end
def initialize_system_extensions; end
An initialization callback.
def initialize_system_extensions; end
def jruby?
def jruby? defined?(RUBY_ENGINE) && RUBY_ENGINE == "jruby" end
def raw_no_echo_mode; end
def raw_no_echo_mode; end
def raw_no_echo_mode_exec
Yieds a block to be executed in Raw No Echo mode and
def raw_no_echo_mode_exec raw_no_echo_mode yield ensure restore_mode end
def readline_read(question, highline)
-
question
(HighLine::Question
) -- question from where to get
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
def restore_mode; end
def restore_mode; end
def restore_stty
def restore_stty system("stty", @stty_save) if @stty_save end
def rubinius?
def rubinius? defined?(RUBY_ENGINE) && RUBY_ENGINE == "rbx" end
def run_preserving_stty
def run_preserving_stty save_stty yield ensure restore_stty end
def save_stty
def save_stty @stty_save = begin `stty -g`.chomp if input.tty? rescue StandardError nil end end
def terminal_size
-
(Array
- two value terminal)
def terminal_size [80, 24] end
def windows?
def windows? defined?(RUBY_PLATFORM) && (RUBY_PLATFORM =~ /mswin|mingw|cygwin/) end