summaryrefslogtreecommitdiff
path: root/asciifarm/client/inputhandling.hy
diff options
context:
space:
mode:
authortroido <troido@hotmail.com>2018-01-03 01:17:45 +0100
committertroido <troido@hotmail.com>2018-01-03 01:17:45 +0100
commit5da66af8dbce7cc5c08d142591907e8474a5bbda (patch)
tree5038b0f2f2940e32aaa42897a4bb41e9c2922021 /asciifarm/client/inputhandling.hy
parentf3affd98f361e391b32b52e060fda7c53feef574 (diff)
inputhanding now handles keyname lookup. enter is now also named
Diffstat (limited to 'asciifarm/client/inputhandling.hy')
-rw-r--r--asciifarm/client/inputhandling.hy26
1 files changed, 12 insertions, 14 deletions
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)))))
)