lib/textbringer/keymap.rb in textbringer-0.1.1 vs lib/textbringer/keymap.rb in textbringer-0.1.2

- old
+ new

@@ -1,8 +1,8 @@ # frozen_string_literal: true -require "ncursesw" +require "curses" module Textbringer class Keymap def initialize @map = {} @@ -41,14 +41,14 @@ private def kbd(key) case key - when Integer, Symbol + when Symbol [key] when String - key.unpack("C*") + key.chars when Array key else raise TypeError, "invalid key type #{key.class}" end @@ -78,11 +78,11 @@ GLOBAL_MAP.define_key(:home, :beginning_of_line) GLOBAL_MAP.define_key(?\C-e, :end_of_line) GLOBAL_MAP.define_key(:end, :end_of_line) GLOBAL_MAP.define_key("\e<", :beginning_of_buffer) GLOBAL_MAP.define_key("\e>", :end_of_buffer) - (0x20..0x7e).each do |c| + (?\x20..?\x7e).each do |c| GLOBAL_MAP.define_key(c, :self_insert) end GLOBAL_MAP.define_key(?\t, :self_insert) GLOBAL_MAP.define_key(?\C-q, :quoted_insert) GLOBAL_MAP.define_key("\C- ", :set_mark) @@ -121,16 +121,11 @@ GLOBAL_MAP.define_key(?\C-g, :keyboard_quit) GLOBAL_MAP.define_key(?\C-s, :isearch_forward) GLOBAL_MAP.define_key(?\C-r, :isearch_backward) GLOBAL_MAP.define_key("\e!", :shell_execute) GLOBAL_MAP.handle_undefined_key do |key| - if key.is_a?(Integer) && key > 0x80 - begin - key.chr(Encoding::UTF_8) - :self_insert - rescue RangeError - nil - end + if key.is_a?(String) && /[\0-\x7f]/ !~ key + :self_insert else nil end end