21
21
# Bah, this would be easier to test if curses/terminfo didn't have so
22
22
# much non-introspectable global state.
23
23
24
+ from collections import deque
25
+
24
26
from pyrepl import keymap
25
27
from pyrepl .console import Event
26
28
from pyrepl import curses
34
36
35
37
36
38
_keynames = {
37
- "delete" : "kdch1" ,
38
- "down" : "kcud1" ,
39
- "end" : "kend" ,
40
- "enter" : "kent" ,
41
- "f1" : "kf1" , "f2" : "kf2" , "f3" : "kf3" , "f4" : "kf4 " ,
42
- "f5" : "kf5" , "f6" : "kf6" , "f7" : "kf7" , "f8" : "kf8 " ,
43
- "f9" : "kf9" , "f10" : "kf10" , "f11" : "kf11" , "f12" : "kf12 " ,
44
- "f13" : "kf13" , "f14" : "kf14" , "f15" : "kf15" , "f16" : "kf16 " ,
45
- "f17" : "kf17" , "f18" : "kf18" , "f19" : "kf19" , "f20" : "kf20 " ,
46
- "home" : "khome " ,
47
- "insert" : "kich1 " ,
48
- "left" : "kcub1" ,
49
- "page down" : "knp" ,
50
- "page up" : "kpp" ,
51
- "right" : "kcuf1" ,
52
- "up" : "kcuu1" ,
53
- }
39
+ "delete" : "kdch1" ,
40
+ "down" : "kcud1" ,
41
+ "end" : "kend" ,
42
+ "enter" : "kent" ,
43
+ "home" : "khome " ,
44
+ "insert" : "kich1 " ,
45
+ "left" : "kcub1 " ,
46
+ "page down" : "knp " ,
47
+ "page up" : "kpp " ,
48
+ "right" : "kcuf1 " ,
49
+ "up" : "kcuu1 " ,
50
+ }
51
+
52
+
53
+ #function keys x in 1-20 -> fX: kfX
54
+ _keynames . update (( 'f%d' % i , 'kf%d' % i ) for i in range ( 1 , 21 ))
55
+
54
56
55
57
def general_keycodes ():
56
58
keycodes = {}
@@ -62,7 +64,6 @@ def general_keycodes():
62
64
return keycodes
63
65
64
66
65
-
66
67
def EventQueue (fd , encoding ):
67
68
keycodes = general_keycodes ()
68
69
if os .isatty (fd ):
@@ -72,16 +73,17 @@ def EventQueue(fd, encoding):
72
73
trace ('keymap {k!r}' , k = k )
73
74
return EncodedQueue (k , encoding )
74
75
76
+
75
77
class EncodedQueue (object ):
76
78
def __init__ (self , keymap , encoding ):
77
79
self .k = self .ck = keymap
78
- self .events = []
80
+ self .events = deque ()
79
81
self .buf = bytearray ()
80
- self .encoding = encoding
82
+ self .encoding = encoding
81
83
82
84
def get (self ):
83
85
if self .events :
84
- return self .events .pop ( 0 )
86
+ return self .events .popleft ( )
85
87
else :
86
88
return None
87
89
0 commit comments