Skip to content

Commit

Permalink
Combine MAPPINGS(single byte input to symbol) with key_bindings(escap…
Browse files Browse the repository at this point in the history
…e sequence to symbol)
  • Loading branch information
tompng committed Dec 6, 2024
1 parent a6fe45f commit aac77dc
Show file tree
Hide file tree
Showing 15 changed files with 551 additions and 600 deletions.
8 changes: 5 additions & 3 deletions lib/reline.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ module Reline

class ConfigEncodingConversionError < StandardError; end

Key = Struct.new(:char, :combined_char, :with_meta) do
# EOF key: { char: nil, method_symbol: nil }
# Other key: { char: String, method_symbol: Symbol }
Key = Struct.new(:char, :method_symbol, :unused_boolean) do
# For dialog_proc `key.match?(dialog.name)`
def match?(sym)
combined_char.is_a?(Symbol) && combined_char == sym
method_symbol && method_symbol == sym
end
end
CursorPos = Struct.new(:x, :y)
Expand Down Expand Up @@ -341,7 +343,7 @@ def readline(prompt = '', add_hist = false)
read_io(config.keyseq_timeout) { |inputs|
line_editor.set_pasting_state(io_gate.in_pasting?)
inputs.each do |key|
if key.char == :bracketed_paste_start
if key.method_symbol == :bracketed_paste_start
text = io_gate.read_bracketed_paste
line_editor.insert_multiline_text(text)
line_editor.scroll_into_view
Expand Down
1 change: 0 additions & 1 deletion lib/reline/io/windows.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ def set_default_key_bindings(config)
[224, 83] => :key_delete, # Del
[224, 71] => :ed_move_to_beg, # Home
[224, 79] => :ed_move_to_end, # End
[ 0, 41] => :ed_unassigned, # input method on/off
[ 0, 72] => :ed_prev_history, # ↑
[ 0, 80] => :ed_next_history, # ↓
[ 0, 77] => :ed_next_char, # →
Expand Down
14 changes: 10 additions & 4 deletions lib/reline/key_actor/base.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
class Reline::KeyActor::Base
def initialize(mapping = [])
@mapping = mapping
def initialize(mappings = nil)
@matching_bytes = {}
@key_bindings = {}
add_mappings(mappings) if mappings
end

def get_method(key)
@mapping[key]
def add_mappings(mappings)
add([27], :ed_ignore)
128.times do |key|
func = mappings[key]
meta_func = mappings[key | 0b10000000]
add([key], func) if func
add([27, key], meta_func) if meta_func
end
end

def add(key, func)
Expand Down
Loading

0 comments on commit aac77dc

Please sign in to comment.