Skip to content

Commit

Permalink
Merge pull request #2 from osyo-manga/add-support-cursor_key
Browse files Browse the repository at this point in the history
[WIP] Add support cursor keys.
  • Loading branch information
aycabta authored Apr 16, 2019
2 parents c20a84f + 468fbb8 commit 8aa5ea7
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
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

0 comments on commit 8aa5ea7

Please sign in to comment.