1
# Copyright 2000-2004 Michael Hudson mwh@python.net
6
# Permission to use, copy, modify, and distribute this software and
7
# its documentation for any purpose is hereby granted without fee,
8
# provided that the above copyright notice appear in all copies and
9
# that both that copyright notice and this permission notice appear in
10
# supporting documentation.
12
# THE AUTHOR MICHAEL HUDSON DISCLAIMS ALL WARRANTIES WITH REGARD TO
13
# THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
14
# AND FITNESS, IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL,
15
# INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
16
# RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
17
# CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
18
# CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20
# Bah, this would be easier to test if curses/terminfo didn't have so
21
# much non-introspectable global state.
24
from console import Event
26
from termios import tcgetattr, VERASE
33
"f1" : "kf1", "f2" : "kf2", "f3" : "kf3", "f4" : "kf4",
34
"f5" : "kf5", "f6" : "kf6", "f7" : "kf7", "f8" : "kf8",
35
"f9" : "kf9", "f10" : "kf10", "f11" : "kf11", "f12" : "kf12",
36
"f13" : "kf13", "f14" : "kf14", "f15" : "kf15", "f16" : "kf16",
37
"f17" : "kf17", "f18" : "kf18", "f19" : "kf19", "f20" : "kf20",
47
class EventQueue(object):
48
def __init__(self, fd):
50
for key, tiname in _keynames.items():
51
keycode = curses.tigetstr(tiname)
53
our_keycodes[keycode] = unicode(key)
54
our_keycodes[tcgetattr(fd)[6][VERASE]] = u'backspace'
55
self.k = self.ck = keymap.compile_keymap(our_keycodes)
60
return self.events.pop(0)
64
return not self.events
65
def insert(self, event):
66
self.events.append(event)
70
if isinstance(k, dict):
74
self.events.append(Event('key', k, ''.join(self.buf) + char))
78
self.events.extend([Event('key', c, c) for c in self.buf])
83
self.events.append(Event('key', char, char))