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

[WIP] Add support cursor keys. #2

Merged
merged 1 commit into from
Apr 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions lib/reline.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,16 @@ def self.inner_readline(prompt = '', add_hist = false, multiline, &confirm_multi
@line_editor.completion_proc = @completion_proc
@line_editor.retrieve_completion_block = method(:retrieve_completion_block)
@line_editor.rerender

config = {
key_mapping: {
# TODO
# "a" => "bb",
# "z" => "aa",
# "y" => "ak",
[27, 91, 65] => :ed_prev_history, # ↑
[27, 91, 66] => :ed_next_history, # ↓
[27, 91, 67] => :ed_next_char, # →
[27, 91, 68] => :ed_prev_char # ←
}
}

key_stroke = Reline::KeyStroke.new(config)
begin
while c = getc
Expand Down
4 changes: 4 additions & 0 deletions lib/reline/key_stroke.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ class Reline::KeyStroke
def start_with?(other)
other.size <= size && other == self.take(other.size)
end

def bytes
self
end
end
}

Expand Down
2 changes: 2 additions & 0 deletions lib/reline/line_editor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,8 @@ def input_key(key)
else
@meta_prefix = true
end
elsif Symbol === key and respond_to?(key, true)
process_key(key, key, method(key))
else
normal_char(key)
end
Expand Down