module Reline

Constants

CursorPos
FILENAME_COMPLETION_PROC
HISTORY
IOGate
IS_WINDOWS
USERNAME_COMPLETION_PROC

Public Class Methods

ambiguous_width() click to toggle source
# File lib/reline.rb, line 347
def self.ambiguous_width
  @@ambiguous_width
end
basic_quote_characters() click to toggle source
# File lib/reline.rb, line 94
def self.basic_quote_characters
  @@basic_quote_characters
end
basic_quote_characters=(v) click to toggle source
# File lib/reline.rb, line 97
def self.basic_quote_characters=(v)
  @@basic_quote_characters = v.encode(Encoding::default_external)
end
basic_word_break_characters() click to toggle source
# File lib/reline.rb, line 78
def self.basic_word_break_characters
  @@basic_word_break_characters
end
basic_word_break_characters=(v) click to toggle source
# File lib/reline.rb, line 81
def self.basic_word_break_characters=(v)
  @@basic_word_break_characters = v.encode(Encoding::default_external)
end
completer_quote_characters() click to toggle source
# File lib/reline.rb, line 102
def self.completer_quote_characters
  @@completer_quote_characters
end
completer_quote_characters=(v) click to toggle source
# File lib/reline.rb, line 105
def self.completer_quote_characters=(v)
  @@completer_quote_characters = v.encode(Encoding::default_external)
end
completer_word_break_characters() click to toggle source
# File lib/reline.rb, line 86
def self.completer_word_break_characters
  @@completer_word_break_characters
end
completer_word_break_characters=(v) click to toggle source
# File lib/reline.rb, line 89
def self.completer_word_break_characters=(v)
  @@completer_word_break_characters = v.encode(Encoding::default_external)
end
completion_append_character() click to toggle source
# File lib/reline.rb, line 62
def self.completion_append_character
  @@completion_append_character
end
completion_append_character=(val) click to toggle source
# File lib/reline.rb, line 65
def self.completion_append_character=(val)
  if val.nil?
    @@completion_append_character = nil
  elsif val.size == 1
    @@completion_append_character = val.encode(Encoding::default_external)
  elsif val.size > 1
    @@completion_append_character = val[0].encode(Encoding::default_external)
  else
    @@completion_append_character = nil
  end
end
completion_case_fold() click to toggle source
# File lib/reline.rb, line 126
def self.completion_case_fold
  @@completion_case_fold
end
completion_case_fold=(v) click to toggle source
# File lib/reline.rb, line 129
def self.completion_case_fold=(v)
  @@completion_case_fold = v
end
completion_proc() click to toggle source
# File lib/reline.rb, line 134
def self.completion_proc
  @@completion_proc
end
completion_proc=(p) click to toggle source
# File lib/reline.rb, line 137
def self.completion_proc=(p)
  raise ArgumentError unless p.is_a?(Proc)
  @@completion_proc = p
end
delete_text(start = nil, length = nil) click to toggle source
# File lib/reline.rb, line 179
def self.delete_text(start = nil, length = nil)
  @@line_editor&.delete_text(start, length)
end
dig_perfect_match_proc() click to toggle source
# File lib/reline.rb, line 151
def self.dig_perfect_match_proc
  @@dig_perfect_match_proc
end
dig_perfect_match_proc=(p) click to toggle source
# File lib/reline.rb, line 154
def self.dig_perfect_match_proc=(p)
  @@dig_perfect_match_proc = p
end
emacs_editing_mode() click to toggle source
# File lib/reline.rb, line 213
def self.emacs_editing_mode
  @@config.editing_mode = :emacs
  nil
end
emacs_editing_mode?() click to toggle source
# File lib/reline.rb, line 222
def self.emacs_editing_mode?
  @@config.editing_mode_is?(:emacs)
end
filename_quote_characters() click to toggle source
# File lib/reline.rb, line 110
def self.filename_quote_characters
  @@filename_quote_characters
end
filename_quote_characters=(v) click to toggle source
# File lib/reline.rb, line 113
def self.filename_quote_characters=(v)
  @@filename_quote_characters = v.encode(Encoding::default_external)
end
get_screen_size() click to toggle source
# File lib/reline.rb, line 226
def self.get_screen_size
  Reline::IOGate.get_screen_size
end
input=(val) click to toggle source
# File lib/reline.rb, line 188
def self.input=(val)
  raise TypeError unless val.respond_to?(:getc) or val.nil?
  if val.respond_to?(:getc)
    if defined?(Reline::ANSI) and IOGate == Reline::ANSI
      Reline::ANSI.input = val
    elsif IOGate == Reline::GeneralIO
      Reline::GeneralIO.input = val
    end
  end
end
insert_text(text) click to toggle source
# File lib/reline.rb, line 158
def self.insert_text(text)
  @@line_editor&.insert_text(text)
  self
end
line_buffer() click to toggle source
# File lib/reline.rb, line 167
def self.line_buffer
  @@line_editor&.line
end
output=(val) click to toggle source
# File lib/reline.rb, line 200
def self.output=(val)
  raise TypeError unless val.respond_to?(:write) or val.nil?
  @@output = val
  if defined?(Reline::ANSI) and IOGate == Reline::ANSI
    Reline::ANSI.output = val
  end
end
point() click to toggle source
# File lib/reline.rb, line 171
def self.point
  @@line_editor ? @@line_editor.byte_pointer : 0
end
point=(val) click to toggle source
# File lib/reline.rb, line 175
def self.point=(val)
  @@line_editor.byte_pointer = val
end
pre_input_hook() click to toggle source
# File lib/reline.rb, line 143
def self.pre_input_hook
  @@pre_input_hook
end
pre_input_hook=(p) click to toggle source
# File lib/reline.rb, line 146
def self.pre_input_hook=(p)
  @@pre_input_hook = p
end
redisplay() click to toggle source
# File lib/reline.rb, line 163
def self.redisplay
  @@line_editor&.rerender
end
special_prefixes() click to toggle source
# File lib/reline.rb, line 118
def self.special_prefixes
  @@special_prefixes
end
special_prefixes=(v) click to toggle source
# File lib/reline.rb, line 121
def self.special_prefixes=(v)
  @@special_prefixes = v.encode(Encoding::default_external)
end
vi_editing_mode() click to toggle source
# File lib/reline.rb, line 208
def self.vi_editing_mode
  @@config.editing_mode = :vi_insert
  nil
end
vi_editing_mode?() click to toggle source
# File lib/reline.rb, line 218
def self.vi_editing_mode?
  @@config.editing_mode_is?(:vi_insert, :vi_command)
end

Private Class Methods

test_mode() click to toggle source
# File lib/reline.rb, line 183
                     def self.test_mode
  remove_const('IOGate') if const_defined?('IOGate')
  const_set('IOGate', Reline::GeneralIO)
end

Public Instance Methods

inner_readline(prompt, add_hist, multiline, &confirm_multiline_termination) click to toggle source
# File lib/reline.rb, line 275
def inner_readline(prompt, add_hist, multiline, &confirm_multiline_termination)
  @@config.read
  otio = Reline::IOGate.prep

  may_req_ambiguous_char_width
  @@line_editor.reset(prompt)
  if multiline
    @@line_editor.multiline_on
    if block_given?
      @@line_editor.confirm_multiline_termination_proc = confirm_multiline_termination
    end
  else
    @@line_editor.multiline_off
  end
  @@line_editor.output = @@output
  @@line_editor.completion_proc = @@completion_proc
  @@line_editor.dig_perfect_match_proc = @@dig_perfect_match_proc
  @@line_editor.pre_input_hook = @@pre_input_hook
  @@line_editor.retrieve_completion_block = method(:retrieve_completion_block)
  @@line_editor.rerender

  if IS_WINDOWS
    config = {
      key_mapping: {
        [224, 72] => :ed_prev_history,    # ↑
        [224, 80] => :ed_next_history,    # ↓
        [224, 77] => :ed_next_char,       # →
        [224, 75] => :ed_prev_char        # ←
      }
    }
  else
    config = {
      key_mapping: {
        [27, 91, 65] => :ed_prev_history,    # ↑
        [27, 91, 66] => :ed_next_history,    # ↓
        [27, 91, 67] => :ed_next_char,       # →
        [27, 91, 68] => :ed_prev_char        # ←
      }
    }
  end

  key_stroke = Reline::KeyStroke.new(config)
  begin
    loop do
      c = Reline::IOGate.getc
      key_stroke.input_to!(c)&.then { |inputs|
        inputs.each { |c|
          @@line_editor.input_key(c)
          @@line_editor.rerender
        }
      }
      break if @@line_editor.finished?
    end
    Reline::IOGate.move_cursor_column(0)
  rescue StandardError => e
    Reline::IOGate.deprep(otio)
    raise e
  end

  Reline::IOGate.deprep(otio)
end
may_req_ambiguous_char_width() click to toggle source
# File lib/reline.rb, line 337
def may_req_ambiguous_char_width
  @@ambiguous_width = 2 if Reline::IOGate == Reline::GeneralIO or STDOUT.is_a?(File)
  return if @@ambiguous_width
  Reline::IOGate.move_cursor_column(0)
  print "\u{25bd}"
  @@ambiguous_width = Reline::IOGate.cursor_pos.x
  Reline::IOGate.move_cursor_column(0)
  Reline::IOGate.erase_after_cursor
end
readline(prompt = '', add_hist = false) click to toggle source
# File lib/reline.rb, line 262
def readline(prompt = '', add_hist = false)
  inner_readline(prompt, add_hist, false)

  line = @@line_editor.line.dup
  line.taint
  if add_hist and line and line.chomp.size > 0
    Reline::HISTORY << line.chomp
  end

  @@line_editor.reset_line if @@line_editor.line.nil?
  line
end
readmultiline(prompt = '', add_hist = false, &confirm_multiline_termination) click to toggle source
# File lib/reline.rb, line 245
def readmultiline(prompt = '', add_hist = false, &confirm_multiline_termination)
  if block_given?
    inner_readline(prompt, add_hist, true, &confirm_multiline_termination)
  else
    inner_readline(prompt, add_hist, true)
  end

  whole_buffer = @@line_editor.whole_buffer.dup
  whole_buffer.taint
  if add_hist and whole_buffer and whole_buffer.chomp.size > 0
    Reline::HISTORY << whole_buffer
  end

  @@line_editor.reset_line if @@line_editor.whole_buffer.nil?
  whole_buffer
end
retrieve_completion_block(line, byte_pointer) click to toggle source
# File lib/reline.rb, line 230
def retrieve_completion_block(line, byte_pointer)
  break_regexp = /[#{Regexp.escape(@@basic_word_break_characters)}]/
  before_pointer = line.byteslice(0, byte_pointer)
  break_point = before_pointer.rindex(break_regexp)
  if break_point
    preposing = before_pointer[0..(break_point)]
    block = before_pointer[(break_point + 1)..-1]
  else
    preposing = ''
    block = before_pointer
  end
  postposing = line.byteslice(byte_pointer, line.bytesize)
  [preposing, block, postposing]
end