2
You don't really want to use this module. Try insults.py instead.
5
from twisted.internet import protocol
7
class InsultsClient(protocol.Protocol):
12
self.width = self.height = None
13
self.xpos = self.ypos = 0
14
self.commandQueue = []
17
def setSize(self, width, height):
24
self.windowSizeChanged()
26
def dataReceived(self, data):
27
from twisted.internet import reactor
35
self.escapeCall = reactor.callLater(self.escapeTimeout,
37
elif ch in 'ABCD' and self.inEscape:
39
self.escapeCall.cancel()
41
self.keyReceived('<Up>')
43
self.keyReceived('<Down>')
45
self.keyReceived('<Right>')
47
self.keyReceived('<Left>')
59
self.transport.write('\x1b=\x1b[?1h')
61
def gotoXY(self, x, y):
62
"""Go to a position on the screen.
66
self.commandQueue.append(('gotoxy', x, y))
68
def writeCh(self, ch):
69
"""Write a character to the screen. If we're at the end of the row,
72
if self.xpos < self.width - 1:
73
self.commandQueue.append(('write', ch))
76
def writeStr(self, s):
77
"""Write a string to the screen. This does not wrap a the edge of the
78
screen, and stops at \\r and \\n.
80
s = s[:self.width-self.xpos]
85
self.commandQueue.append(('write', s))
88
def eraseToLine(self):
89
"""Erase from the current position to the end of the line.
91
self.commandQueue.append(('eraseeol',))
93
def eraseToScreen(self):
94
"""Erase from the current position to the end of the screen.
96
self.commandQueue.append(('eraseeos',))
98
def clearScreen(self):
99
"""Clear the screen, and return the cursor to 0, 0.
101
self.commandQueue = [('cls',)]
102
self.xpos = self.ypos = 0
104
def setAttributes(self, *attrs):
105
"""Set the attributes for drawing on the screen.
107
self.commandQueue.append(('attributes', attrs))
110
"""Redraw the screen.
113
for command in self.commandQueue:
114
if command[0] == 'gotoxy':
115
redraw += '\x1b[%i;%iH' % (command[2]+1, command[1]+1)
116
elif command[0] == 'write':
118
elif command[0] == 'eraseeol':
120
elif command[0] == 'eraseeos':
122
elif command[0] == 'cls':
123
redraw += '\x1b[H\x1b[J'
124
elif command[0] == 'attributes':
125
redraw += '\x1b[%sm' % ';'.join(map(str, command[1]))
128
self.commandQueue = []
129
self.transport.write(redraw)
131
def windowSizeChanged(self):
132
"""Called when the size of the window changes.
133
Might want to redraw the screen here, or something.
136
def keyReceived(self, key):
137
"""Called when the user hits a key.