@@ -63,7 +63,7 @@ def _my_getstr(cap, optional=0):
63
63
64
64
# at this point, can we say: AAAAAAAAAAAAAAAAAAAAAARGH!
65
65
def maybe_add_baudrate (dict , rate ):
66
- name = 'B%d' % rate
66
+ name = 'B%d' % rate
67
67
if hasattr (termios , name ):
68
68
dict [getattr (termios , name )] = rate
69
69
@@ -89,12 +89,18 @@ def register(self, fd, flag):
89
89
self .fd = fd
90
90
91
91
def poll (self , timeout = None ):
92
- r , w , e = select .select ([self .fd ],[],[],timeout )
92
+ r , w , e = select .select ([self .fd ], [], [], timeout )
93
93
return r
94
94
95
95
POLLIN = getattr (select , "POLLIN" , None )
96
96
97
97
98
+ required_curses_tistrings = 'bel clear cup el'
99
+ optional_curses_tistrings = (
100
+ 'civis cnorm cub cub1 cud cud1 cud cud1 cuf '
101
+ 'cuf1 cuu cuu1 dch dch1 hpa ich ich1 ind pad ri rmkx smkx' )
102
+
103
+
98
104
class UnixConsole (Console ):
99
105
def __init__ (self , f_in = 0 , f_out = 1 , term = None , encoding = None ):
100
106
if encoding is None :
@@ -117,33 +123,15 @@ def __init__(self, f_in=0, f_out=1, term=None, encoding=None):
117
123
curses .setupterm (term , self .output_fd )
118
124
self .term = term
119
125
120
- self ._bel = _my_getstr ("bel" )
121
- self ._civis = _my_getstr ("civis" , optional = 1 )
122
- self ._clear = _my_getstr ("clear" )
123
- self ._cnorm = _my_getstr ("cnorm" , optional = 1 )
124
- self ._cub = _my_getstr ("cub" , optional = 1 )
125
- self ._cub1 = _my_getstr ("cub1" , 1 )
126
- self ._cud = _my_getstr ("cud" , 1 )
127
- self ._cud1 = _my_getstr ("cud1" , 1 )
128
- self ._cuf = _my_getstr ("cuf" , 1 )
129
- self ._cuf1 = _my_getstr ("cuf1" , 1 )
130
- self ._cup = _my_getstr ("cup" )
131
- self ._cuu = _my_getstr ("cuu" , 1 )
132
- self ._cuu1 = _my_getstr ("cuu1" , 1 )
133
- self ._dch1 = _my_getstr ("dch1" , 1 )
134
- self ._dch = _my_getstr ("dch" , 1 )
135
- self ._el = _my_getstr ("el" )
136
- self ._hpa = _my_getstr ("hpa" , 1 )
137
- self ._ich = _my_getstr ("ich" , 1 )
138
- self ._ich1 = _my_getstr ("ich1" , 1 )
139
- self ._ind = _my_getstr ("ind" , 1 )
140
- self ._pad = _my_getstr ("pad" , 1 )
141
- self ._ri = _my_getstr ("ri" , 1 )
142
- self ._rmkx = _my_getstr ("rmkx" , 1 )
143
- self ._smkx = _my_getstr ("smkx" , 1 )
144
-
126
+ for name in required_curses_tistrings .split ():
127
+ setattr (self , '_' + name , _my_getstr (name ))
128
+
129
+ for name in optional_curses_tistrings .split ():
130
+ setattr (self , '_' + name , _my_getstr (name , optional = 1 ))
131
+
145
132
## work out how we're going to sling the cursor around
146
- if 0 and self ._hpa : # hpa don't work in windows telnet :-(
133
+ # hpa don't work in windows telnet :-(
134
+ if 0 and self ._hpa :
147
135
self .__move_x = self .__move_x_hpa
148
136
elif self ._cub and self ._cuf :
149
137
self .__move_x = self .__move_x_cub_cuf
@@ -264,11 +252,12 @@ def __write_changed_line(self, y, oldline, newline, px):
264
252
# reuse the oldline as much as possible, but stop as soon as we
265
253
# encounter an ESCAPE, because it might be the start of an escape
266
254
# sequene
255
+ #XXX unicode check!
267
256
while x < minlen and oldline [x ] == newline [x ] and newline [x ] != '\x1b ' :
268
257
x += 1
269
258
if oldline [x :] == newline [x + 1 :] and self .ich1 :
270
- if ( y == self .__posxy [1 ] and x > self .__posxy [0 ]
271
- and oldline [px :x ] == newline [px + 1 :x + 1 ] ):
259
+ if (y == self .__posxy [1 ] and x > self .__posxy [0 ] and
260
+ oldline [px :x ] == newline [px + 1 :x + 1 ]):
272
261
x = px
273
262
self .__move (x , y )
274
263
self .__write_code (self .ich1 )
@@ -297,6 +286,7 @@ def __write_changed_line(self, y, oldline, newline, px):
297
286
self .__write (newline [x :])
298
287
self .__posxy = len (newline ), y
299
288
289
+ #XXX: check for unicode mess
300
290
if '\x1b ' in newline :
301
291
# ANSI escape characters are present, so we can't assume
302
292
# anything about the position of the cursor. Moving the cursor
@@ -367,12 +357,12 @@ def prepare(self):
367
357
self .__svtermstate = tcgetattr (self .input_fd )
368
358
raw = self .__svtermstate .copy ()
369
359
raw .iflag |= termios .ICRNL
370
- raw .iflag &= ~ (termios .BRKINT | termios .INPCK |
360
+ raw .iflag &= ~ (termios .BRKINT | termios .INPCK |
371
361
termios .ISTRIP | termios .IXON )
372
- raw .oflag &= ~ ( termios .OPOST )
373
- raw .cflag &= ~ (termios .CSIZE | termios .PARENB )
374
- raw .cflag |= (termios .CS8 )
375
- raw .lflag &= ~ (termios .ICANON | termios .ECHO |
362
+ raw .oflag &= ~ termios .OPOST
363
+ raw .cflag &= ~ (termios .CSIZE | termios .PARENB )
364
+ raw .cflag |= (termios .CS8 )
365
+ raw .lflag &= ~ (termios .ICANON | termios .ECHO |
376
366
termios .IEXTEN | (termios .ISIG * 1 ))
377
367
raw .cc [termios .VMIN ] = 1
378
368
raw .cc [termios .VTIME ] = 0
@@ -414,7 +404,7 @@ def push_char(self, char):
414
404
415
405
def get_event (self , block = 1 ):
416
406
while self .event_queue .empty ():
417
- while 1 :
407
+ while 1 :
418
408
# All hail Unix!
419
409
try :
420
410
self .push_char (os .read (self .input_fd , 1 ))
@@ -541,7 +531,9 @@ def getpending(self):
541
531
542
532
amount = struct .unpack (
543
533
"i" , ioctl (self .input_fd , FIONREAD , "\0 \0 \0 \0 " ))[0 ]
544
- raw = unicode (os .read (self .input_fd , amount ), self .encoding , 'replace' )
534
+ data = os .read (self .input_fd , amount )
535
+ raw = unicode (data , self .encoding , 'replace' )
536
+ #XXX: something is wrong here
545
537
e .data += raw
546
538
e .raw += raw
547
539
return e
@@ -553,9 +545,11 @@ def getpending(self):
553
545
e2 = self .event_queue .get ()
554
546
e .data += e2 .data
555
547
e .raw += e .raw
556
-
548
+
557
549
amount = 10000
558
- raw = unicode (os .read (self .input_fd , amount ), self .encoding , 'replace' )
550
+ data = os .read (self .input_fd , amount )
551
+ raw = unicode (data , self .encoding , 'replace' )
552
+ #XXX: something is wrong here
559
553
e .data += raw
560
554
e .raw += raw
561
555
return e
@@ -566,4 +560,3 @@ def clear(self):
566
560
self .__move = self .__move_tall
567
561
self .__posxy = 0 , 0
568
562
self .screen = []
569
-
0 commit comments