From 1bf981b4836dc7d48535fcfcdf0d1a4e6d8ffb84 Mon Sep 17 00:00:00 2001 From: troido Date: Wed, 18 Apr 2018 23:59:40 +0200 Subject: client can now read strings from chat input --- asciifarm/client/inputhandler.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'asciifarm/client/inputhandler.py') diff --git a/asciifarm/client/inputhandler.py b/asciifarm/client/inputhandler.py index 1d907e9..5296f9d 100644 --- a/asciifarm/client/inputhandler.py +++ b/asciifarm/client/inputhandler.py @@ -1,8 +1,11 @@ -from commandhandler import CommandHandler -from .keynames import nameFromKey import curses import curses.ascii +import shlex + +from commandhandler import CommandHandler, InvalidCommandException +from .keynames import nameFromKey + class InputHandler: @@ -38,6 +41,12 @@ class InputHandler: else: self.commandHandler.chat(message) + def startTyping(self): + self.typing = True + self.showString() + + def showString(self): + self.client.display.setInputString(self.string, self.cursor if self.typing else -1) def addKey(self, key): if curses.ascii.isprint(key): @@ -47,7 +56,7 @@ class InputHandler: self.string = self.string[:self.cursor-1] + self.string[self.cursor:] self.cursor = max(self.cursor - 1, 0) elif key == curses.KEY_RIGHT: - self.cursor = max(self.cursor + 1, len(self.string)) + self.cursor = min(self.cursor + 1, len(self.string)) elif key == curses.KEY_LEFT: self.cursor = max(self.cursor - 1, 0) elif key == curses.KEY_DC: @@ -68,6 +77,8 @@ class InputHandler: self.typing = False self.processString(message) + self.showString() + -- cgit