diff options
| -rw-r--r-- | asciifarm/client/inputhandler.py | 10 | ||||
| -rw-r--r-- | asciifarm/common/messages.py | 7 |
2 files changed, 9 insertions, 8 deletions
diff --git a/asciifarm/client/inputhandler.py b/asciifarm/client/inputhandler.py index b2e4ac9..0657749 100644 --- a/asciifarm/client/inputhandler.py +++ b/asciifarm/client/inputhandler.py @@ -55,13 +55,10 @@ class InputHandler: self.showString() def showString(self): - self.client.display.setInputString(self.string, self.cursor if self.typing else -1) + self.client.display.setInputString(self.string, self.cursor if self.typing else None) def addKey(self, key): - if key in string.printable: - self.string = self.string[:self.cursor] + key + self.string[self.cursor:] - self.cursor += 1 - elif key == inp.BACKSPACE: + if key == inp.BACKSPACE: self.string = self.string[:self.cursor-1] + self.string[self.cursor:] self.cursor = max(self.cursor - 1, 0) elif key == inp.RIGHT: @@ -90,6 +87,9 @@ class InputHandler: elif key == "^I": # tab # return to game but keep entered string self.typing = False + elif key.isprintable(): + self.string = self.string[:self.cursor] + key + self.string[self.cursor:] + self.cursor += len(key) self.showString() diff --git a/asciifarm/common/messages.py b/asciifarm/common/messages.py index 5ab489b..d3aed9a 100644 --- a/asciifarm/common/messages.py +++ b/asciifarm/common/messages.py @@ -60,9 +60,10 @@ class NameMessage(ClientToServerMessage): assert isinstance(name, str), InvalidNameError("name must be a string") assert (len(name) > 0), InvalidNameError("name needs at least one character") assert (len(bytes(name, "utf-8")) <= 256), InvalidNameError("name may not be longer than 256 utf8 bytes") - for char in name if name[0] != "~" else name[1:]: - category = unicodedata.category(char) - assert category in self.categories, InvalidNameError("all name caracters must be in these unicode categories: " + "|".join(self.categories) + " (except the tilde in a tildename)") + if name[0] != "~": + for char in name: + category = unicodedata.category(char) + assert category in self.categories, InvalidNameError("all name caracters must be in these unicode categories: " + "|".join(self.categories) + " (except for tildenames)") self.name = name def body(self): |
