~ubuntu-branches/ubuntu/vivid/openipmi/vivid

« back to all changes in this revision

Viewing changes to swig/python/openipmigui/_term.py

  • Committer: Bazaar Package Importer
  • Author(s): Noèl Köthe
  • Date: 2006-09-15 17:56:24 UTC
  • mfrom: (1.1.2 upstream) (2.1.1 etch)
  • Revision ID: james.westby@ubuntu.com-20060915175624-ljk0mg3xtcm65tvm
Tags: 2.0.7-1
* new upstream release from 2006-06-08
  Thanks to John Wright <john.wright hp.com> for initial work
  (closes: Bug#380149)
* updated Standards Version
* new binaries openipmicmd, openipmish, rmcp_ping

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# _term.py
 
2
#
 
3
# openipmi generic terminal handling for SoL
 
4
#
 
5
# Author: MontaVista Software, Inc.
 
6
#         Corey Minyard <minyard@mvista.com>
 
7
#         source@mvista.com
 
8
#
 
9
# Copyright 2006 MontaVista Software Inc.
 
10
#
 
11
#  This program is free software; you can redistribute it and/or
 
12
#  modify it under the terms of the GNU Lesser General Public License
 
13
#  as published by the Free Software Foundation; either version 2 of
 
14
#  the License, or (at your option) any later version.
 
15
#
 
16
#
 
17
#  THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
 
18
#  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 
19
#  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 
20
#  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
 
21
#  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
 
22
#  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
 
23
#  OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 
24
#  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
 
25
#  TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
 
26
#  USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
27
#
 
28
#  You should have received a copy of the GNU Lesser General Public
 
29
#  License along with this program; if not, write to the Free
 
30
#  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
31
#
 
32
 
 
33
black = 0
 
34
red = 1
 
35
green = 2
 
36
yellow = 3
 
37
blue = 4
 
38
magenta = 5
 
39
cyan = 6
 
40
white = 7
 
41
 
 
42
BOLD = 1
 
43
UNDERLINE = 2
 
44
INVERSE = 4
 
45
BLINK = 8
 
46
CONCEALED = 16
 
47
 
 
48
class TerminalEmulator:
 
49
    def __init__(self):
 
50
        self.buf = [ ]
 
51
        # Mode is a 2-d array of [ cflags, bg color, fg color ]
 
52
        self.modes = [ ]
 
53
        # Style is (fg, bg, flags)
 
54
        for i in range(0, 24):
 
55
            self.buf.append([ ])
 
56
            self.modes.append([ ])
 
57
            for j in range(0, 80):
 
58
                self.buf[i].append(" ")
 
59
                self.modes[i].append( [0, 0, 7] )
 
60
                pass
 
61
            pass
 
62
        self.cflags = 0
 
63
        self.bg_color = black
 
64
        self.fg_color = white
 
65
        self.x = 0
 
66
        self.y = 0
 
67
        self.height = 24
 
68
        self.width = 80
 
69
        self.InputHandler = self.Input0
 
70
        self.parms = None
 
71
        self.saved_pos = [1, 1]
 
72
        self.scroll_region = [0, self.height-1]
 
73
        self.keypad_alt = False
 
74
        return
 
75
 
 
76
    def check_scroll_down(self):
 
77
        redraw = False
 
78
        starty = self.GetStartY()
 
79
        endy = self.GetEndY()
 
80
        if (self.y == endy):
 
81
            old = self.buf[starty]
 
82
            del(self.buf[starty])
 
83
            self.buf.insert(endy, old)
 
84
            old = self.modes[starty]
 
85
            del(self.modes[starty])
 
86
            self.modes.insert(endy, old)
 
87
            for j in range(0, self.width):
 
88
                self.buf[endy][j] = " "
 
89
                self.modes[endy][j][0] = 0
 
90
                self.modes[endy][j][1] = black
 
91
                self.modes[endy][j][2] = white
 
92
                pass
 
93
            pass
 
94
            self.ScrollLines(starty, endy)
 
95
        else:
 
96
            self.y += 1
 
97
            pass
 
98
        return
 
99
 
 
100
    def check_scroll_up(self):
 
101
        starty = self.GetStartY()
 
102
        endy = self.GetEndY()
 
103
        if (self.y == starty):
 
104
            old = self.buf[endy]
 
105
            del(self.buf[endy])
 
106
            self.buf.insert(starty, old)
 
107
            for j in range(0, self.width):
 
108
                self.buf[starty][j] = ' '
 
109
                self.modes[starty][j][0] = 0
 
110
                self.modes[starty][j][1] = black
 
111
                self.modes[starty][j][2] = white
 
112
                pass
 
113
            pass
 
114
            self.ScrollLinesUp(starty, endy)
 
115
        else:
 
116
            self.y -= 1
 
117
            pass
 
118
        return
 
119
 
 
120
    def output_at(self, x, y, slen):
 
121
        s = ""
 
122
        i = 0
 
123
        last_mode = [ 0, 0, 7 ]
 
124
        lastx = 0
 
125
        while (i < slen):
 
126
            if (len(s) > 0):
 
127
                if (last_mode != self.modes[y][x+i]):
 
128
                    # Character mode change, output what we have and switch.
 
129
                    self.DrawText(last_mode[2], last_mode[1], last_mode[0],
 
130
                                  x, y, s)
 
131
                    s = ""
 
132
                    pass
 
133
                pass
 
134
            else:
 
135
                last_mode = self.modes[y][x+i]
 
136
                lastx = x + i
 
137
                pass
 
138
            s += self.buf[y][x+i]
 
139
            i += 1
 
140
            pass
 
141
        self.DrawText(last_mode[2], last_mode[1], last_mode[0],
 
142
                      lastx, y, s)
 
143
        return
 
144
 
 
145
    def handle_cursor(self):
 
146
        if (self.x == self.width):
 
147
            xpos = self.x - 1
 
148
        else:
 
149
            xpos = self.x
 
150
            pass
 
151
        mode = self.modes[self.y][xpos]
 
152
        self.DrawCursor(mode[2], mode[1], mode[0], xpos, self.y,
 
153
                        self.buf[self.y][xpos])
 
154
        return
 
155
 
 
156
    def restore_cursor(self):
 
157
        if (self.x == self.width):
 
158
            self.output_at(self.x-1, self.y, 1)
 
159
            pass
 
160
        else:
 
161
            self.output_at(self.x, self.y, 1)
 
162
            pass
 
163
        return
 
164
        
 
165
    def output_str(self, s):
 
166
        if (len(s) == 0):
 
167
            return
 
168
        do_scroll = False
 
169
        if (self.x == self.width):
 
170
            # Cursor is at the end of the line, redraw the char where
 
171
            # the cursor is sitting.
 
172
            self.restore_cursor()
 
173
            self.x = 0;
 
174
            self.check_scroll_down()
 
175
            pass
 
176
        while ((self.x + len(s)) > self.width):
 
177
            # The string exceeds the line length, do it in pieces
 
178
            outlen = self.width - self.x
 
179
            do_scroll = True
 
180
            self.buf[self.y][self.x:self.x+outlen] = s[0:outlen]
 
181
            self.output_at(self.x, self.y, outlen)
 
182
            self.x = 0;
 
183
            s = s[outlen:]
 
184
            self.check_scroll_down()
 
185
            pass
 
186
        outlen = len(s)
 
187
        for i in range(0, outlen):
 
188
            self.buf[self.y][self.x+i] = s[i]
 
189
        for i in range(self.x, self.x+outlen):
 
190
            self.modes[self.y][i][0] = self.cflags
 
191
            self.modes[self.y][i][1] = self.bg_color
 
192
            self.modes[self.y][i][2] = self.fg_color
 
193
            pass
 
194
        self.output_at(self.x, self.y, outlen)
 
195
        self.x += outlen
 
196
        self.handle_cursor()
 
197
        return
 
198
 
 
199
    def GetParm(self, n, default = 1):
 
200
        if (self.parms == None):
 
201
            return default
 
202
        elif (len(self.parms) <= n):
 
203
            return default
 
204
        return self.parms[n]
 
205
 
 
206
    # Get the current upper bound of the cursor, used for scroll regions.
 
207
    def GetStartY(self):
 
208
        if ((self.y >= self.scroll_region[0])
 
209
            and (self.y <= self.scroll_region[1])):
 
210
            return self.scroll_region[0]
 
211
        return 0
 
212
 
 
213
    # Get the current lower bound of the cursor, used for scroll regions.
 
214
    def GetEndY(self):
 
215
        if ((self.y >= self.scroll_region[0])
 
216
            and (self.y <= self.scroll_region[1])):
 
217
            return self.scroll_region[1]
 
218
        return self.height - 1
 
219
 
 
220
    # After '\e['
 
221
    def Input2(self, c, s):
 
222
        if (c == 'A'): # Up
 
223
            count = self.GetParm(0)
 
224
            starty = self.GetStartY()
 
225
            self.restore_cursor()
 
226
            if (count > (self.y - starty)):
 
227
                self.y = starty
 
228
            else:
 
229
                self.y -= count
 
230
                pass
 
231
            self.handle_cursor();
 
232
            pass
 
233
        elif (c == 'B'): # Down
 
234
            count = self.GetParm(0)
 
235
            endy = self.GetEndY()
 
236
            self.restore_cursor()
 
237
            if (count > (endy - self.y)):
 
238
                self.y = endy
 
239
            else:
 
240
                self.y += count
 
241
                pass
 
242
            self.handle_cursor();
 
243
            pass
 
244
        elif (c == 'C'): # Right
 
245
            count = self.GetParm(0)
 
246
            self.restore_cursor()
 
247
            if (count > (self.width - self.x - 1)):
 
248
                self.x = self.width - 1
 
249
            else:
 
250
                self.x += count
 
251
                pass
 
252
            self.handle_cursor();
 
253
            pass
 
254
        elif (c == 'D'): # Right
 
255
            count = self.GetParm(0)
 
256
            self.restore_cursor()
 
257
            if (count > self.x):
 
258
                self.x = 0
 
259
            else:
 
260
                self.x -= count
 
261
                pass
 
262
            self.handle_cursor();
 
263
            pass
 
264
        elif (c == '?'): # FIXME: Not sure what this does
 
265
            return "" # Stay in Input2
 
266
        elif ((c >= '0') and (c <= '9')):
 
267
            if (self.parms == None):
 
268
                self.parms = [ int(c) ]
 
269
            else:
 
270
                currparm = len(self.parms) - 1
 
271
                self.parms[currparm] *= 10
 
272
                self.parms[currparm] += int(c)
 
273
                pass
 
274
            return "" # Stay in Input2
 
275
        elif (c == ';'): # Next parm
 
276
            if (self.parms == None):
 
277
                self.parms = [ 0, 0 ]
 
278
            else:
 
279
                self.parms.append(0)
 
280
                pass
 
281
            return "" # Stay in Input2
 
282
        elif (c == 'r'): # Scroll region
 
283
            y1 = self.GetParm(0, -1)
 
284
            y2 = self.GetParm(1, -1)
 
285
            if ((y1 == -1) or (y2 == -1)):
 
286
                if ((y1 == -1) and (y2 == -1)):
 
287
                    self.scroll_region[0] = 0
 
288
                    self.scroll_region[1] = self.height - 1
 
289
                    pass
 
290
                pass
 
291
            elif ((y1 > y2) or (y1 < 1) or (y2 < 1)
 
292
                  or (y1 >= (self.height+1)) or (y2 >= (self.height+1))):
 
293
                # Bogus values, just ignre them.
 
294
                pass
 
295
            else:
 
296
                self.scroll_region[0] = y1 - 1
 
297
                self.scroll_region[1] = y2 - 1
 
298
                pass
 
299
            pass
 
300
        elif ((c == 'H') or (c == 'f')): # Move to position specified
 
301
            y = self.GetParm(0)
 
302
            x = self.GetParm(1)
 
303
            if (x < 1):
 
304
                x = 1
 
305
            elif (x > self.width):
 
306
                x = self.width
 
307
                pass
 
308
            self.restore_cursor()
 
309
            self.x = x - 1
 
310
            self.y = y - 1
 
311
            self.handle_cursor();
 
312
            pass
 
313
        elif (c == 's'): # save cursor position
 
314
            self.saved_pos[0] = self.x
 
315
            self.saved_pos[1] = self.y
 
316
            pass
 
317
        elif (c == 'u'): # Restore cursor position
 
318
            self.restore_cursor()
 
319
            self.x = self.saved_pos[0]
 
320
            self.y = self.saved_pos[1]
 
321
            self.handle_cursor();
 
322
            pass
 
323
        elif (c == 'J'): # Clear screen area
 
324
            mode = self.GetParm(0, -1)
 
325
            if (mode == -1):
 
326
                starty = self.y
 
327
                length = self.height - self.y
 
328
                pass
 
329
            elif (mode == 1):
 
330
                starty = 0
 
331
                length = self.y + 1
 
332
                pass
 
333
            elif (mode == 2):
 
334
                starty = 0
 
335
                length = self.height
 
336
                pass
 
337
            else:
 
338
                starty = 0
 
339
                length = 0
 
340
                pass
 
341
            for y in range(starty, starty + length):
 
342
                for x in range(0, self.width):
 
343
                    self.buf[y][x] = " "
 
344
                    self.modes[y][x][0] = 0
 
345
                    self.modes[y][x][1] = black
 
346
                    self.modes[y][x][2] = white
 
347
                    pass
 
348
                self.output_at(0, y, self.width)
 
349
                pass
 
350
            self.handle_cursor();
 
351
            pass
 
352
        elif (c == 'K'): # Clear line
 
353
            mode = self.GetParm(0, 0)
 
354
            y = self.y
 
355
            if (mode == 0): # To end of line
 
356
                startx = self.x
 
357
                length = self.width - self.x
 
358
                pass
 
359
            elif (mode == 1): # To start of line
 
360
                startx = 0
 
361
                length = self.x + 1
 
362
                pass
 
363
            elif (mode == 2): # Whole line
 
364
                startx = 0
 
365
                length = self.width
 
366
                pass
 
367
            else: # Ignore
 
368
                startx = 0
 
369
                length = 0
 
370
                pass
 
371
            for x in range(startx, startx+length):
 
372
                self.buf[y][x] = " "
 
373
                self.modes[y][x][0] = 0
 
374
                self.modes[y][x][1] = black
 
375
                self.modes[y][x][2] = white
 
376
                pass
 
377
            self.output_at(startx, y, length)
 
378
            self.handle_cursor();
 
379
        elif (c == 'm'): # Graphics mode
 
380
            i = 0
 
381
            val = self.GetParm(i, 0)
 
382
            while (val != -1):
 
383
                if (val == 0):
 
384
                    self.cflags = 0
 
385
                    self.bg_color = black
 
386
                    self.fg_color = white
 
387
                elif (val == 1):
 
388
                    self.cflags |= BOLD
 
389
                elif (val == 4):
 
390
                    self.cflags |= UNDERLINE
 
391
                elif (val == 5):
 
392
                    self.cflags |= BLINK
 
393
                elif (val == 7):
 
394
                    self.cflags |= INVERSE
 
395
                elif (val == 8):
 
396
                    self.cflags |= CONCEALED
 
397
                elif ((val >= 30) and (val <= 37)):
 
398
                    self.fg_color = val - 30
 
399
                elif ((val >= 40) and (val <= 47)):
 
400
                    self.bg_color = val - 40
 
401
                    pass
 
402
                i += 1
 
403
                val = self.GetParm(i, -1)
 
404
                pass
 
405
            pass
 
406
        elif (c == 'g'):
 
407
             # FIXME: \e[2g means clear tabs, so does 3g, 0g or just g
 
408
             # means current tab
 
409
            pass
 
410
        elif (c == 'P'): # delete parm characters (1 default)
 
411
            count = self.GetParm(0, 1)
 
412
            if (count > (self.width - self.x)):
 
413
                count = self.width - self.x
 
414
                pass
 
415
            y = self.y
 
416
            x = self.x
 
417
            for i in range(0, count):
 
418
                del self.buf[y][x]
 
419
                self.buf[y].append(' ')
 
420
                old = self.modes[y][x]
 
421
                del self.modes[y][x]
 
422
                old[0] = 0
 
423
                old[1] = black
 
424
                old[2] = white
 
425
                self.modes[y].append(old)
 
426
                pass
 
427
            self.DeleteChars(x, y, count)
 
428
            self.handle_cursor()
 
429
            pass
 
430
        elif (c == 'M'): # delete parm lines (1 default)
 
431
            count = self.GetParm(0, 1)
 
432
            if (count > (self.height - self.y)):
 
433
                count = self.height - self.y
 
434
                pass
 
435
            for i in range(0, count):
 
436
                old = self.buf[self.y]
 
437
                del self.buf[self.y]
 
438
                self.buf.append(old)
 
439
                old = self.modes[self.y]
 
440
                del self.modes[self.y]
 
441
                self.modes.append(old)
 
442
                for j in range(0, self.width):
 
443
                    self.buf[self.height-1][j] = ' '
 
444
                    self.modes[self.height-1][j][0] = 0
 
445
                    self.modes[self.height-1][j][1] = black
 
446
                    self.modes[self.height-1][j][2] = white
 
447
                    pass
 
448
                self.ScrollLines(self.y, self.height-1)
 
449
                pass
 
450
            self.handle_cursor()
 
451
            pass
 
452
        elif (c == 'L'): # insert parm lines (1 default)
 
453
            self.restore_cursor()
 
454
            count = self.GetParm(0, 1)
 
455
            if (count > (self.height - self.y)):
 
456
                count = self.height - self.y
 
457
                pass
 
458
            for i in range(0, count):
 
459
                old = self.buf[self.height-1]
 
460
                del self.buf[self.height-1]
 
461
                self.buf.insert(self.y, old)
 
462
                for j in range(0, self.width):
 
463
                    self.buf[self.y][j] = ' '
 
464
                    self.modes[self.y][j][0] = 0
 
465
                    self.modes[self.y][j][1] = black
 
466
                    self.modes[self.y][j][2] = white
 
467
                    pass
 
468
                self.ScrollLinesUp(self.y, self.height-1)
 
469
                pass
 
470
            self.handle_cursor()
 
471
            pass
 
472
        elif (c == 'Z'): # Move to previous tab stop
 
473
            self.restore_cursor()
 
474
            self.x = ((self.x-1) / 8) * 8
 
475
            self.handle_cursor();
 
476
            pass
 
477
        elif (c == '@'): # insert parm chars (1 default)
 
478
            self.restore_cursor()
 
479
            count = self.GetParm(0, 1)
 
480
            if (count > (self.width - self.x)):
 
481
                count = self.width - self.x
 
482
                pass
 
483
            y = self.y
 
484
            x = self.x
 
485
            for i in range(0, count):
 
486
                del self.buf[y][self.width-1]
 
487
                old = self.modes[y][self.width-1]
 
488
                del self.modes[y][self.width-1]
 
489
                old[0] = 0
 
490
                old[1] = black
 
491
                old[2] = white
 
492
                self.buf[y].insert(self.x, ' ')
 
493
                self.modes[y].insert(self.x, old)
 
494
                pass
 
495
            self.InsertChars(x, y, count)
 
496
            self.handle_cursor()
 
497
            pass
 
498
        elif (c == 'S'): # scroll forward parm lines (1 default)
 
499
            self.restore_cursor()
 
500
            count = self.GetParm(0, 1)
 
501
            if (count > self.height):
 
502
                count = self.height
 
503
                pass
 
504
            for i in range(0, count):
 
505
                old = self.buf[0]
 
506
                del self.buf[0]
 
507
                self.buf.append(old)
 
508
                old = self.modes[0]
 
509
                del self.modes[0]
 
510
                self.modes.append(old)
 
511
                for j in range(0, self.width):
 
512
                    self.buf[self.height-1][j] = ' '
 
513
                    self.modes[self.height-1][j][0] = 0
 
514
                    self.modes[self.height-1][j][1] = black
 
515
                    self.modes[self.height-1][j][2] = white
 
516
                    pass
 
517
                self.ScrollLines(0, self.height-1)
 
518
                pass
 
519
            self.handle_cursor()
 
520
            pass
 
521
        elif (c == 'T'): # scroll back parm lines (1 default)
 
522
            self.restore_cursor()
 
523
            count = self.GetParm(0, 1)
 
524
            if (count > self.height):
 
525
                count = self.height
 
526
                pass
 
527
            for i in range(0, count):
 
528
                old = self.buf[self.height-1]
 
529
                del self.buf[self.height-1]
 
530
                self.buf.insert(0, old)
 
531
                old = self.modes[self.height-1]
 
532
                del self.modes[self.height-1]
 
533
                self.modes.insert(0, old)
 
534
                for j in range(0, self.width):
 
535
                    self.buf[0][j] = ' '
 
536
                    self.modes[0][j][0] = 0
 
537
                    self.modes[0][j][1] = black
 
538
                    self.modes[0][j][2] = white
 
539
                    pass
 
540
                self.ScrollLinesUp(0, self.height-1)
 
541
                pass
 
542
            self.handle_cursor()
 
543
            pass
 
544
        elif (c == 'G'): # Move cursor to column parm (1 default)
 
545
            self.restore_cursor()
 
546
            pos = self.GetParm(0, 1)
 
547
            if (pos > self.width):
 
548
                pos = self.width
 
549
                pass
 
550
            elif (pos < 1):
 
551
                return ""
 
552
            self.x = pos - 1
 
553
            self.handle_cursor()
 
554
            pass
 
555
        elif (c == 'd'): # Move cursor to line parm (1 default)
 
556
            self.restore_cursor()
 
557
            pos = self.GetParm(0, 1)
 
558
            if (pos > self.height):
 
559
                pos = self.height
 
560
                pass
 
561
            elif (pos < 1):
 
562
                return ""
 
563
            self.y = pos - 1
 
564
            self.handle_cursor()
 
565
            pass
 
566
        elif (c == 'X'): # erase parm characters (1 default) (no cursor move)
 
567
            count = self.GetParm(0, 1)
 
568
            if (count > (self.height - self.y)):
 
569
                count = self.height - self.y
 
570
                pass
 
571
            for i in range(0, count):
 
572
                self.buf[self.y][self.x+i] = " "
 
573
                self.modes[self.y][self.x+i][0] = 0
 
574
                self.modes[self.y][self.x+i][1] = black
 
575
                self.modes[self.y][self.x+i][2] = white
 
576
                pass
 
577
            self.output_at(self.x, self.y, count)
 
578
            self.handle_cursor()
 
579
            pass
 
580
        elif (c == 'c'): # Identify terminal
 
581
            # Identify ourself as "linux"
 
582
            self.HandleTerminalOutput("\x1b[?62;9;c")
 
583
            pass
 
584
        self.InputHandler = self.Input0
 
585
        return ""
 
586
 
 
587
    # After an escape
 
588
    def Input1(self, c, s):
 
589
        if (c == '['):
 
590
            self.InputHandler = self.Input2
 
591
            return ""
 
592
        elif (c == 'D'): # Scroll down
 
593
            self.restore_cursor()
 
594
            self.check_scroll_down()
 
595
            self.handle_cursor();
 
596
        elif (c == 'M'): # Scroll up
 
597
            self.restore_cursor()
 
598
            self.check_scroll_up()
 
599
            self.handle_cursor();
 
600
            pass
 
601
        elif (c == 'H'): # FIXME: Set tabulator stop in all rows at current column
 
602
            pass
 
603
        elif (c == 'c'): # reset terminal
 
604
            for y in range(0, self.height):
 
605
                for x in range(0, self.width):
 
606
                    self.buf[y][x] = " "
 
607
                    self.modes[y][x][0] = 0
 
608
                    self.modes[y][x][1] = black
 
609
                    self.modes[y][x][2] = white
 
610
                    pass
 
611
                self.output_at(0, y, self.width)
 
612
                pass
 
613
            self.x = 0
 
614
            self.y = 0
 
615
            self.cflags = 0
 
616
            self.bg_color = black
 
617
            self.fg_color = white
 
618
            self.handle_cursor();
 
619
            pass
 
620
        elif ((c >= '0') and (c <= '9')):
 
621
            if (self.parms == None):
 
622
                self.parms = [ int(c) ]
 
623
            else:
 
624
                currparm = len(self.parms) - 1
 
625
                self.parms[currparm] *= 10
 
626
                self.parms[currparm] += int(c)
 
627
                pass
 
628
            return "" # Stay in Input1
 
629
        elif (c == 'n'): # Terminal state
 
630
            op = self.GetParm(0, 0)
 
631
            if (op == 5): # Requesting terminal status
 
632
                self.HandleTerminalOutput("\x1b0n") # We are ok
 
633
            elif (op == 6): # Current cursor position
 
634
                self.HandleTerminalOutput("\x1b%d;%dR" % (self.y+1, self.x+1))
 
635
            pass
 
636
        elif (c == '='): # alternate keypad mode
 
637
            self.keypat_alt = True
 
638
            pass
 
639
        elif (c == '>'): # alternate keypad mode off
 
640
            self.keypat_alt = False
 
641
            pass
 
642
        self.InputHandler = self.Input0
 
643
        return ""
 
644
 
 
645
    # "normal" input mode
 
646
    def Input0(self, c, s):
 
647
        if ((c >= ' ') and (c <= '~')):
 
648
            return s + c
 
649
        else:
 
650
            self.output_str(s)
 
651
            if (c == '\n'):
 
652
                self.restore_cursor()
 
653
                self.check_scroll_down()
 
654
                self.handle_cursor();
 
655
                pass
 
656
            elif (c == '\r'):
 
657
                self.restore_cursor()
 
658
                self.x = 0
 
659
                self.handle_cursor();
 
660
                pass
 
661
            elif (c == '\t'):
 
662
                self.restore_cursor()
 
663
                if (self.x >= self.width-8):
 
664
                    self.x = self.width-1
 
665
                else:
 
666
                    self.x = ((self.x / 8) * 8) + 8
 
667
                    pass
 
668
                self.handle_cursor();
 
669
                pass
 
670
            elif (c == '\007'): #bell
 
671
                self.Bell()
 
672
            elif (c == '\010'): #backspace
 
673
                if (self.x > 0):
 
674
                    self.restore_cursor()
 
675
                    self.x -= 1
 
676
                    self.handle_cursor();
 
677
                    pass
 
678
                pass
 
679
            elif (c == '\x1b'):
 
680
                self.parms = None
 
681
                self.InputHandler = self.Input1
 
682
                pass
 
683
            pass
 
684
        return ""
 
685
    
 
686
    def ProcessInput(self, data):
 
687
        s = ""
 
688
        for c in data:
 
689
            s = self.InputHandler(c, s)
 
690
            pass
 
691
        self.output_str(s)
 
692
        return
 
693
 
 
694
    def ResizeTerminal(self, w, h):
 
695
        return
 
696
 
 
697
    def Width(self):
 
698
        return self.width
 
699
 
 
700
    def Height(self):
 
701
        return self.height
 
702
 
 
703
    def Update(self):
 
704
        return
 
705
 
 
706
    def Reset(self):
 
707
        return
 
708
    
 
709
    pass
 
710
 
 
711