lib/textbringer/window.rb in textbringer-0.2.0 vs lib/textbringer/window.rb in textbringer-0.2.1

- old
+ new

@@ -259,10 +259,11 @@ @buffer = nil @top_of_window = nil @bottom_of_window = nil @point_mark = nil @deleted = false + @raw_key_buffer = [] @key_buffer = [] end def echo_area? false @@ -347,34 +348,34 @@ @window.nodelay = false end end def wait_input(msecs) - unless @key_buffer.empty? - return @key_buffer.first + if !@raw_key_buffer.empty? || !@key_buffer.empty? + return @raw_key_buffer.first || @key_buffer.first end @window.timeout = msecs begin c = @window.get_char if c - Curses.unget_char(c) + @raw_key_buffer.push(c) end c ensure @window.timeout = -1 end end def has_input? - unless @key_buffer.empty? + if !@raw_key_buffer.empty? || !@key_buffer.empty? return true end @window.nodelay = true begin c = @window.get_char if c - Curses.unget_char(c) + @raw_key_buffer.push(c) end !c.nil? ensure @window.nodelay = false end @@ -780,10 +781,14 @@ def get_char if @key_buffer.empty? PDCurses.PDC_save_key_modifiers(1) if PDCurses.dll_loaded? begin need_retry = false - key = @window.get_char + if @raw_key_buffer.empty? + key = @window.get_char + else + key = @raw_key_buffer.shift + end if PDCurses.dll_loaded? mods = PDCurses.PDC_get_key_modifiers if key.is_a?(String) && key.ascii_only? if (mods & PDCurses::KEY_MODIFIER_CONTROL) != 0 key = key == ?? ? "\x7f" : (key.ord & 0x9f).chr