Skip to content

Commit

Permalink
Seprate raw keystroke config for each platforms
Browse files Browse the repository at this point in the history
  • Loading branch information
nobu committed May 31, 2019
1 parent 8fc552a commit 552c42f
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 25 deletions.
26 changes: 1 addition & 25 deletions lib/reline.rb
Expand Up @@ -326,31 +326,7 @@ def inner_readline(prompt, add_hist, multiline, &confirm_multiline_termination)
@@line_editor.pre_input_hook = @@pre_input_hook
@@line_editor.rerender

if IS_WINDOWS
config = {
key_mapping: {
[224, 72] => :ed_prev_history, # ↑
[224, 80] => :ed_next_history, # ↓
[224, 77] => :ed_next_char, # →
[224, 75] => :ed_prev_char, # ←
[224, 83] => :key_delete, # Del
[224, 71] => :ed_move_to_beg, # Home
[224, 79] => :ed_move_to_end # End
}
}
else
config = {
key_mapping: {
[27, 91, 65] => :ed_prev_history, # ↑
[27, 91, 66] => :ed_next_history, # ↓
[27, 91, 67] => :ed_next_char, # →
[27, 91, 68] => :ed_prev_char, # ←
[27, 91, 51, 126] => :key_delete, # Del
[27, 91, 49, 126] => :ed_move_to_beg,# Home
[27, 91, 52, 126] => :ed_move_to_end # End
}
}
end
config = Reline::IOGate::RAW_KEYSTROKE_CONFIG

key_stroke = Reline::KeyStroke.new(config)
begin
Expand Down
12 changes: 12 additions & 0 deletions lib/reline/ansi.rb
@@ -1,4 +1,16 @@
class Reline::ANSI
RAW_KEYSTROKE_CONFIG = {
key_mapping: {
[27, 91, 65] => :ed_prev_history, # ↑
[27, 91, 66] => :ed_next_history, # ↓
[27, 91, 67] => :ed_next_char, # →
[27, 91, 68] => :ed_prev_char, # ←
[27, 91, 51, 126] => :key_delete, # Del
[27, 91, 49, 126] => :ed_move_to_beg, # Home
[27, 91, 52, 126] => :ed_move_to_end, # End
}.each_key(&:freeze).freeze,
}.freeze

@@input = STDIN
def self.input=(val)
@@input = val
Expand Down
2 changes: 2 additions & 0 deletions lib/reline/general_io.rb
@@ -1,6 +1,8 @@
require 'timeout'

class Reline::GeneralIO
RAW_KEYSTROKE_CONFIG = {key_mapping: {}.freeze}.freeze

@@buf = []

def self.input=(val)
Expand Down
12 changes: 12 additions & 0 deletions lib/reline/windows.rb
@@ -1,6 +1,18 @@
require 'fiddle/import'

class Reline::Windows
RAW_KEYSTROKE_CONFIG = {
key_mapping: {
[224, 72] => :ed_prev_history, # ↑
[224, 80] => :ed_next_history, # ↓
[224, 77] => :ed_next_char, # →
[224, 75] => :ed_prev_char, # ←
[224, 83] => :key_delete, # Del
[224, 71] => :ed_move_to_beg, # Home
[224, 79] => :ed_move_to_end, # End
}.each_key(&:freeze).freeze,
}.freeze

class Win32API
DLL = {}
TYPEMAP = {"0" => Fiddle::TYPE_VOID, "S" => Fiddle::TYPE_VOIDP, "I" => Fiddle::TYPE_LONG}
Expand Down

0 comments on commit 552c42f

Please sign in to comment.