Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge key mapping with key bindings #715

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

tompng
Copy link
Member

@tompng tompng commented Jun 2, 2024

Depends on #713
Fourth step of #708

Combines KeyActor::XXX_MAPPING(single byte to method symbol) with key_bindings(escape sequence to method symbol)

This will simplifies implementation of keys. Keyseq timeout waiting behavior becomes more similar to Readline.
We can remove key.instance_of?(String) check.
Reline::Key structure will be simple.

# before
EOF: Key{ char: nil, combined_char: nil, with_meta: false}
Normal key: Key{ char: number, combined_char: number, with_meta: false}
ESC-key: Key{ char: number, combined_char: number|0x80, with_meta: true}
Key-bindings: Key{ char: symbol, combined_char: symbol, with_meta: false}

# after
EOF: Key{ char: nil, combined_char: nil}
Other: Key{ char: string, method_symbol: string}

Future refactor

Key can contain string.
This means we can assign bracketed-pasted string to a key. bracketed_paste and quoted_insert will be simple.
Simplifies bracketed-paste and completion handling, undo-redo handling. Simplifies quoted_insert waiting_proc mechanism and fixes bug.

key.char = read_bracketed_paste if key.method_symbol == :bracketed_paste_start
key.char = read_next_valid_char if key.method_symbol == :quoted_insert
line_editor.update(key)

Implementing compress-meta will be significantly easy.

class Reline::KeyActor::Base
  def add_mappings(mappings)
    ...
    128.times do |key|
      ...
      add([27, key], meta_func)
      add([key | 0x80], meta_func) if compress_meta_enabled # Just add this line
    end
  end
end

@tompng tompng force-pushed the merge_mapping_bindings branch 2 times, most recently from 55db8dc to 2c2bb1f Compare June 5, 2024 05:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

1 participant