blob: 38d69edfca9c3b5e354f6992ef0cbce77351cc03 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
import curses
class TextInput:
def __init__(self):
self.widget = None
self.text = ""
self.cursor = 0
def setWidget(self, widget):
self.widget = widget
def setText(self, text, cursor):
self.text = text
self.cursor = cursor
self.widget.change()
def update(self):
win = self.widget.getWin()
width, height = win.getSize()
win.erase()
win.addLine((0, 0), self.text)
if self.cursor >= 0 and self.cursor <= len(self.text):
win.setAttr((self.cursor, 0), curses.A_REVERSE)
win.noutrefresh()
|