From 552c42f51f75eeeaa5a46e2df28fd5dab77261da Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Sat, 1 Jun 2019 00:34:38 +0900 Subject: [PATCH] Seprate raw keystroke config for each platforms --- lib/reline.rb | 26 +------------------------- lib/reline/ansi.rb | 12 ++++++++++++ lib/reline/general_io.rb | 2 ++ lib/reline/windows.rb | 12 ++++++++++++ 4 files changed, 27 insertions(+), 25 deletions(-) diff --git a/lib/reline.rb b/lib/reline.rb index 2f5a155636..46856d1a51 100644 --- a/lib/reline.rb +++ b/lib/reline.rb @@ -326,31 +326,7 @@ module Reline @@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 diff --git a/lib/reline/ansi.rb b/lib/reline/ansi.rb index 1ead89b8ff..e6b3344285 100644 --- a/lib/reline/ansi.rb +++ b/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 diff --git a/lib/reline/general_io.rb b/lib/reline/general_io.rb index 526c780084..b015b951e6 100644 --- a/lib/reline/general_io.rb +++ b/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) diff --git a/lib/reline/windows.rb b/lib/reline/windows.rb index b64ea97295..95c30c0246 100644 --- a/lib/reline/windows.rb +++ b/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}