about summary refs log tree commit diff stats
path: root/src/display/client.nim
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2023-01-05 00:57:57 +0100
committerbptato <nincsnevem662@gmail.com>2023-01-05 00:57:57 +0100
commitc0ccab9264ed99e75ee42197eed8af7e77e023f5 (patch)
treed70478a6dfb1e618c19ebf8079469bb52efcdaa3 /src/display/client.nim
parent0edb5d3230730990d922328822e19833d807a040 (diff)
downloadchawan-c0ccab9264ed99e75ee42197eed8af7e77e023f5.tar.gz
Add ask()
Diffstat (limited to 'src/display/client.nim')
-rw-r--r--src/display/client.nim19
1 files changed, 14 insertions, 5 deletions
diff --git a/src/display/client.nim b/src/display/client.nim
index ab12e2f8..311d8ffc 100644
--- a/src/display/client.nim
+++ b/src/display/client.nim
@@ -156,8 +156,15 @@ proc input(client: Client) =
   restoreStdin(client.console.tty.getFileHandle())
   while true:
     let c = client.console.readChar()
-    client.s &= c
-    if client.pager.lineedit.isSome:
+    if client.pager.askpromise != nil:
+      if c == 'y':
+        client.pager.fulfillAsk(true)
+        client.runJSJobs()
+      elif c == 'n':
+        client.pager.fulfillAsk(false)
+        client.runJSJobs()
+    elif client.pager.lineedit.isSome:
+      client.s &= c
       let edit = client.pager.lineedit.get
       client.line = edit
       if edit.escNext:
@@ -171,23 +178,25 @@ proc input(client: Client) =
             client.s = ""
           else:
             client.feedNext = true
-        elif not client.feedNext:
+        elif not client.feednext:
           client.evalJSFree(action, "<command>")
         if client.pager.lineedit.isNone:
           client.line = nil
         if not client.feedNext:
           client.pager.updateReadLine()
     else:
+      client.s &= c
       let action = getNormalAction(client.config, client.s)
       client.evalJSFree(action, "<command>")
       if not client.feedNext:
         client.handlePagerEvents()
         client.pager.refreshStatusMsg()
-    if not client.feedNext:
+    if not client.feednext:
       client.s = ""
       break
     else:
-      client.feedNext = false
+      client.feednext = false
+  client.s = ""
 
 proc setTimeout[T: JSValue|string](client: Client, handler: T, timeout = 0): int {.jsfunc.} =
   let id = client.timeoutid