I am writing a messanger, and I need a some textbox, with some advanced features.
I had seen a curses.textpad, but it doesn't suit my needs.
Well, if I type Cyrillic chars, getch() return wrong characters, like
Ð¿Ñ Ð²ÐивеÑ
import curses
class inputbox:
def get():
win = curses.newwin(3, 35, 4, 4)
win.keypad(True)
inp = True
text = ""
while inp:
ch = win.getch()
if ch == 10:
text += "\n"
inp = False
if ch == 263 or ch == curses.KEY_BACKSPACE:
text = text[:len(text)-1]
currpos = win.getyx()
win.addstr(currpos[0], currpos[1], " ")
win.move(currpos[0], currpos[1])
else:
text += chr(ch)
win.refresh()
return text
def main(stdscr):
curses.echo()
inp = inputbox()
text = inputbox.get()
stdscr.addstr(0, 0, text)
stdscr.getstr()
if __name__ == "__main__":
curses.wrapper(main)