module Gm::Notepad::Readline

A configuration module for the Readline module

Constants

QUERY_TABLE_NAMES_PREFIX
TABLE_EXPANSION_REGEXP

Public Class Methods

completion_function(string, table_registry: Container.resolve(:table_registry)) click to toggle source
# File lib/gm/notepad/readline.rb, line 9
def self.completion_function(string, table_registry: Container.resolve(:table_registry))
  entries = []
  if match = string.match(QUERY_TABLE_NAMES_PREFIX)
    entries += table_registry.table_names.grep(/^#{Regexp.escape(match[:table_name])}/).map { |name| "+#{name}" }
  end
  if match = string.match(TABLE_EXPANSION_REGEXP)
    test_string = string.sub(match[:table_container], "{")
    entries += table_registry.table_names.grep(/^#{Regexp.escape(match[:table_name])}/).map { |name| "#{test_string}#{name}}"}
  end
  entries += history_for(string)
  entries.uniq.sort
end
history_for(string) click to toggle source
# File lib/gm/notepad/readline.rb, line 22
def self.history_for(string)
  ::Readline::HISTORY.grep(/^#{Regexp.escape(string)}/)
end
input_getter(**config) click to toggle source
# File lib/gm/notepad/readline.rb, line 49
def self.input_getter(**config)
  -> { ::Readline.readline("", true) }
end