2
from twisted.conch.insults import window
4
class Faucet(window.ContainerWidget):
8
def __init__(self, onInput):
9
window.ContainerWidget.__init__(self)
11
self._inputCallback = onInput
13
place = window.TextOutputArea()
14
things = window.TextOutputArea()
15
place_things = window.HBox()
16
place_things.addChild(window.Border(place))
17
place_things.addChild(window.Border(things))
19
output = window.TextOutputArea()
20
scrolledOutput = window.ScrolledArea(output)
21
input = window.TextInput(78, self._onInput)
22
output_input = window.VBox()
23
output_input.addChild(scrolledOutput)
24
output_input.addChild(input)
26
detail_interaction = window.VBox()
27
detail_interaction.addChild(place_things)
28
detail_interaction.addChild(output_input)
30
self.addChild(detail_interaction)
35
self._scroll = scrolledOutput
38
def render(self, width, height, terminal):
39
self._input.maxwidth = width - 2
41
self._toBottom = False
42
n = self._outputText.count('\n')
43
m = ((height - 4) / 2 - 1)
44
self._scroll._viewport.yOffset = max(0, n - m)
46
return window.ContainerWidget.render(self, width, height, terminal)
48
def _onInput(self, text):
49
self._input.setText('')
50
self.addOutputLine('> ' + text)
51
self._inputCallback(text)
53
def setPlace(self, text):
54
self._place.setText(text)
56
def setThings(self, text):
57
self._things.setText(text)
59
def addOutputLine(self, text):
60
self._outputText += text + '\n'
61
self._output.setText(self._outputText)