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)

Parameters:
  • 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

Returns:
  • (String) - class name. Ex: "HighLine::Terminal::IOConsole"
def character_mode
  self.class.name
end

def get_character; end # rubocop:disable Naming/AccessorMethodName

Returns:
  • (String) - one character
def get_character; end # rubocop:disable Naming/AccessorMethodName

def get_line(question, highline)

Parameters:
  • 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)

Parameters:
  • 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)

Parameters:
  • () --
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)

Parameters:
  • output (IO) -- output stream
  • input (IO) -- input stream
def initialize(input, output)
  @input  = input
  @output = output
end

def initialize_system_extensions; end

It is called by {.get_terminal}.
An initialization callback.
def initialize_system_extensions; end

def jruby?

Running on JRuby?
def jruby?
  defined?(RUBY_ENGINE) && RUBY_ENGINE == "jruby"
end

def raw_no_echo_mode; end

Enter Raw No Echo mode.
def raw_no_echo_mode; end

def raw_no_echo_mode_exec

then restore the terminal state.
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)

Parameters:
  • 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

Restore terminal to its default mode
def restore_mode; end

def restore_stty

Restores terminal state using shell stty command.
def restore_stty
  system("stty", @stty_save) if @stty_save
end

def rubinius?

Running on Rubinius?
def rubinius?
  defined?(RUBY_ENGINE) && RUBY_ENGINE == "rbx"
end

def run_preserving_stty

Yield a block using stty shell commands to preserve the terminal state.
def run_preserving_stty
  save_stty
  yield
ensure
  restore_stty
end

def save_stty

Saves terminal state using shell stty command.
def save_stty
  @stty_save = begin
                 `stty -g`.chomp if input.tty?
               rescue StandardError
                 nil
               end
end

def terminal_size

Returns:
  • (Array) - two value terminal
def terminal_size
  [80, 24]
end

def windows?

Running on Windows?
def windows?
  defined?(RUBY_PLATFORM) && (RUBY_PLATFORM =~ /mswin|mingw|cygwin/)
end