about summary refs log tree commit diff stats
path: root/src/display
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2022-11-27 00:30:53 +0100
committerbptato <nincsnevem662@gmail.com>2022-11-27 00:31:56 +0100
commite7f157c792f53cb084e8694ee608f00727432a3d (patch)
treef4b640619327b5e15578cc156028102955437e36 /src/display
parenta58d2eff7f68bf98ee3b1ba1b59de6d80743f97e (diff)
downloadchawan-e7f157c792f53cb084e8694ee608f00727432a3d.tar.gz
Also, implement proper async
Well, not really proper, but better than nothing? Maybe not.
Diffstat (limited to 'src/display')
-rw-r--r--src/display/client.nim6
-rw-r--r--src/display/pager.nim24
2 files changed, 19 insertions, 11 deletions
diff --git a/src/display/client.nim b/src/display/client.nim
index 36761d56..24ea8183 100644
--- a/src/display/client.nim
+++ b/src/display/client.nim
@@ -243,8 +243,7 @@ proc acceptBuffers(client: Client) =
     if pid in client.pager.procmap:
       let container = client.pager.procmap[pid]
       client.pager.procmap.del(pid)
-      container.istream = stream
-      container.ostream = stream
+      container.setStream(stream)
       let fd = stream.source.getFd()
       client.fdmap[int(fd)] = container
       client.selector.registerHandle(fd, {Read}, nil)
@@ -314,7 +313,8 @@ proc writeFile(client: Client, path: string, content: string) {.jsfunc.} =
 
 proc newConsole(pager: Pager, tty: File): Console =
   new(result)
-  if tty != nil:
+  result.tty = tty
+  if tty != nil and false:
     var pipefd: array[0..1, cint]
     if pipe(pipefd) == -1:
       raise newException(Defect, "Failed to open console pipe.")
diff --git a/src/display/pager.nim b/src/display/pager.nim
index 119b5002..7bd50e6f 100644
--- a/src/display/pager.nim
+++ b/src/display/pager.nim
@@ -8,7 +8,6 @@ import unicode
 when defined(posix):
   import posix
 
-import buffer/buffer
 import buffer/cell
 import buffer/container
 import config/config
@@ -428,7 +427,7 @@ proc gotoURL*(pager: Pager, request: Request, prevurl = none(URL), ctype = none(
     pager.addContainer(container)
   else:
     pager.container.redirect = some(request.url)
-    pager.container.gotoAnchor(request.url.anchor)
+    pager.container.findAnchor(request.url.anchor)
 
 # When the user has passed a partial URL as an argument, they might've meant
 # either:
@@ -580,12 +579,7 @@ proc click(pager: Pager) {.jsfunc.} =
 proc authorize*(pager: Pager) =
   pager.setLineEdit(readLine("Username: ", pager.attrs.width, term = pager.term), USERNAME)
 
-proc handleEvent*(pager: Pager, container: Container): bool =
-  var event: ContainerEvent
-  try:
-    event = container.handleEvent()
-  except IOError:
-    return false
+proc handleEvent0*(pager: Pager, container: Container, event: ContainerEvent): bool =
   case event.t
   of FAIL:
     pager.deleteContainer(container)
@@ -637,5 +631,19 @@ proc handleEvent*(pager: Pager, container: Container): bool =
   of NO_EVENT: discard
   return true
 
+proc handleEvent*(pager: Pager, container: Container): bool =
+  var event: ContainerEvent
+  try:
+    event = container.handleEvent()
+  except IOError:
+    return false
+  if not pager.handleEvent0(container, event):
+    return false
+  while container.events.len > 0:
+    let event = container.events.pop()
+    if not pager.handleEvent0(container, event):
+      return false
+  return true
+
 proc addPagerModule*(ctx: JSContext) =
   ctx.registerType(Pager)