about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2022-11-09 15:20:23 +0100
committerbptato <nincsnevem662@gmail.com>2022-11-09 15:20:23 +0100
commitb00b6a1e1cc6d74bb0b76218ddb4dcf37bef7ac7 (patch)
treeeaf79bfa25a9058a67886064f036c0dced368e15
parent6bf64b2fbe744b8538780318d4b563bf0390c3ee (diff)
downloadchawan-b00b6a1e1cc6d74bb0b76218ddb4dcf37bef7ac7.tar.gz
Kill individual buffers' loader processes on exit
-rw-r--r--src/display/client.nim12
-rw-r--r--src/display/pager.nim15
2 files changed, 20 insertions, 7 deletions
diff --git a/src/display/client.nim b/src/display/client.nim
index ddbccc21..24f65f06 100644
--- a/src/display/client.nim
+++ b/src/display/client.nim
@@ -80,7 +80,6 @@ proc readPipe(client: Client, ctype: string) =
     buffer.setupBuffer()
   else:
     buffer.load()
-    buffer.drawBuffer()
 
 proc doRequest(client: Client, req: Request): Response {.jsfunc.} =
   client.loader.doRequest(req)
@@ -157,6 +156,9 @@ proc quit(client: Client, code = 0) {.jsfunc.} =
     print(EL())
   when defined(posix):
     assert kill(client.loader.process, cint(SIGTERM)) == 0
+    for buffer in client.pager.buffers:
+      if buffer.loader != nil:
+        assert kill(buffer.loader.process, cint(SIGTERM)) == 0
   quit(code)
 
 proc feedNext(client: Client) {.jsfunc.} =
@@ -309,12 +311,8 @@ proc launchClient*(client: Client, pages: seq[string], ctype: string, dump: bool
   else:
     for msg in client.pager.status:
       eprint msg
-    while client.pager.nextBuffer():
-      discard
-    if client.pager.container != nil:
-      client.pager.container.buffer.drawBuffer()
-    while client.pager.prevBuffer():
-      client.pager.container.buffer.drawBuffer()
+    for buffer in client.pager.buffers:
+      buffer.drawBuffer()
     stdout.close()
   client.quit()
 
diff --git a/src/display/pager.nim b/src/display/pager.nim
index 61407e60..c7e994b7 100644
--- a/src/display/pager.nim
+++ b/src/display/pager.nim
@@ -37,6 +37,21 @@ type
     switched*: bool
     tty: File
 
+iterator containers*(pager: Pager): Container =
+  if pager.container != nil:
+    var c = pager.container
+    while c.parent != nil: c = c.parent
+    var stack: seq[Container]
+    stack.add(c)
+    while stack.len > 0:
+      yield stack.pop()
+      for i in countdown(c.children.high, 0):
+        stack.add(c.children[i])
+
+iterator buffers*(pager: Pager): Buffer =
+  for container in pager.containers:
+    yield container.buffer
+
 proc setContainer*(pager: Pager, c: Container) =
   pager.container = c
   pager.switched = true