From 5da66af8dbce7cc5c08d142591907e8474a5bbda Mon Sep 17 00:00:00 2001 From: troido Date: Wed, 3 Jan 2018 01:17:45 +0100 Subject: inputhanding now handles keyname lookup. enter is now also named --- asciifarm/client/inputhandling.hy | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) (limited to 'asciifarm/client/inputhandling.hy') diff --git a/asciifarm/client/inputhandling.hy b/asciifarm/client/inputhandling.hy index 80043c9..b006073 100644 --- a/asciifarm/client/inputhandling.hy +++ b/asciifarm/client/inputhandling.hy @@ -1,18 +1,15 @@ (require [asciifarm.client.keymacros [*]]) +(import [curses]) -(defmacro eval-in-context [code] - `( - (eval `(do - (require [asciifarm.client.keymacros [*]]) - (fn [client display connection] - ~~code))) - self.client - self.display - self.connection)) +(setv prenamedkeys { ; or should this be def? + 10 "KEY_ENTER" +}) -(defmacro sendinput [message] `( - self.client.send ["input" ~message])) +(defn nameFromKey [key] + (if (in key prenamedkeys) + (get prenamedkeys key) + (str (curses.keyname key) "utf-8"))) (defclass InputHandler [] @@ -38,7 +35,7 @@ (try (eval (read-str (+ "(" commandstring ")"))) (except [e Exception] - (self.display.addMessage (repr e))))) + (self.client.log (repr e))))) (defn parseMessage [self message] (if message @@ -53,6 +50,7 @@ (defn getDocs [self] (if (in "help" self.commands) ((get self.commands "help")) "")) - (defn onKey [self key] - (if (in key self.commands) ((get self.commands key)))) + (defn onKey [self key] (do + (setv keyname (nameFromKey key)) + (if (in keyname self.commands) ((get self.commands keyname))))) ) -- cgit