Module: Gm::Notepad::Readline
- Defined in:
- lib/gm/notepad/readline.rb
Overview
A configuration module for the Readline module
Constant Summary collapse
- QUERY_TABLE_NAMES_PREFIX =
/^\+(?<table_name>.*)/.freeze
- TABLE_EXPANSION_REGEXP =
%r{(?<table_container>\{(?<table_name>.*))}.freeze
Class Method Summary collapse
- .completion_function(string, table_registry: Container.resolve(:table_registry)) ⇒ Object
- .history_for(string) ⇒ Object
- .input_getter(**config) ⇒ Object
Class Method Details
.completion_function(string, table_registry: Container.resolve(:table_registry)) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 |
# 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) ⇒ Object
22 23 24 |
# File 'lib/gm/notepad/readline.rb', line 22 def self.history_for(string) ::Readline::HISTORY.grep(/^#{Regexp.escape(string)}/) end |
.input_getter(**config) ⇒ Object
49 50 51 |
# File 'lib/gm/notepad/readline.rb', line 49 def self.input_getter(**config) -> { ::Readline.readline("", true) } end |