about summary refs log tree commit diff stats
path: root/src/local/client.nim
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2024-03-26 20:46:55 +0100
committerbptato <nincsnevem662@gmail.com>2024-03-26 20:54:55 +0100
commit0d1a11cea0fa48837f4ae1ca869e9b01e1f159f4 (patch)
treee962a0a15d1bdd7b6b13cfceea49d486081cd5a4 /src/local/client.nim
parent845445b4c4ab69cc2ffc564c7ab71eeaf8cc3c5e (diff)
downloadchawan-0d1a11cea0fa48837f4ae1ca869e9b01e1f159f4.tar.gz
config: improve input system
as described in <https://todo.sr.ht/~bptato/chawan/6>
Diffstat (limited to 'src/local/client.nim')
-rw-r--r--src/local/client.nim18
1 files changed, 10 insertions, 8 deletions
diff --git a/src/local/client.nim b/src/local/client.nim
index 72c85744..c63a18db 100644
--- a/src/local/client.nim
+++ b/src/local/client.nim
@@ -181,8 +181,13 @@ proc handlePagerEvents(client: Client) =
   if container != nil:
     client.pager.handleEvents(container)
 
-proc evalAction(client: Client, action: string, arg0: int32): EmptyPromise =
-  var ret = client.evalJS(action, "<command>")
+proc evalActionJS(client: Client; action: string): JSValue =
+  client.config.cmd.map.withValue(action, p):
+    return JS_DupValue(client.jsctx, p[])
+  return client.evalJS(action, "<command>")
+
+proc evalAction(client: Client; action: string; arg0: int32): EmptyPromise =
+  var ret = client.evalActionJS(action)
   let ctx = client.jsctx
   var p = EmptyPromise()
   p.resolve()
@@ -814,16 +819,13 @@ proc newClient*(config: Config; forkserver: ForkServer; jsctx: JSContext;
     tmpdir: config.external.tmpdir
   ))
   pager.setLoader(loader)
-  let client = Client(
-    config: config,
-    jsrt: jsrt,
-    jsctx: jsctx,
-    pager: pager
-  )
+  let client = Client(config: config, jsrt: jsrt, jsctx: jsctx, pager: pager)
   jsrt.setInterruptHandler(interruptHandler, cast[pointer](client))
   var global = JS_GetGlobalObject(jsctx)
   jsctx.registerType(Client, asglobal = true)
   setGlobal(jsctx, global, client)
+  jsctx.definePropertyE(global, "cmd", config.cmd.jsObj)
+  config.cmd.jsObj = JS_NULL
   JS_FreeValue(jsctx, global)
   client.addJSModules(jsctx)
   return client