about summary refs log tree commit diff stats
path: root/src/display/client.nim
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2023-05-09 12:34:58 +0200
committerbptato <nincsnevem662@gmail.com>2023-05-09 12:34:58 +0200
commit87f9bd656b2a8a8d4ebd029ba6a78f1dc93558eb (patch)
treec3b7e4f3500512baef2064986cfdf5701c988e29 /src/display/client.nim
parente0a8b27068ac8fc61a243bae685c23a14976f619 (diff)
downloadchawan-87f9bd656b2a8a8d4ebd029ba6a78f1dc93558eb.tar.gz
Improve debugging, reduce crashes
Loader no longer dies when not everything is read from the stream.
Diffstat (limited to 'src/display/client.nim')
-rw-r--r--src/display/client.nim24
1 files changed, 23 insertions, 1 deletions
diff --git a/src/display/client.nim b/src/display/client.nim
index 59557f36..cd2c9f5d 100644
--- a/src/display/client.nim
+++ b/src/display/client.nim
@@ -330,10 +330,19 @@ proc handleRead(client: Client, fd: int) =
     if s.len > prefix.len:
       client.console.err.write(s)
     client.console.err.flush()
+  elif fd in client.loader.connecting:
+    client.loader.onConnected(fd)
+    client.runJSJobs()
+  elif fd in client.loader.ongoing:
+    #TODO something with readablestream?
+    discard
   else:
     let container = client.fdmap[fd]
     client.pager.handleEvent(container)
 
+proc flushConsole*(client: Client) {.jsfunc.} =
+  client.handleRead(client.dispatcher.forkserver.estream.fd)
+
 proc handleError(client: Client, fd: int) =
   if client.console.tty != nil and fd == client.console.tty.getFileHandle():
     #TODO do something here...
@@ -343,6 +352,12 @@ proc handleError(client: Client, fd: int) =
     #TODO do something here...
     stderr.write("Fork server crashed :(\n")
     quit(1)
+  elif fd in client.loader.connecting:
+    #TODO handle error?
+    discard
+  elif fd in client.loader.ongoing:
+    #TODO something with readablestream?
+    discard
   else:
     if fd in client.fdmap:
       let container = client.fdmap[fd]
@@ -392,8 +407,15 @@ proc inputLoop(client: Client) =
     client.pager.showAlerts()
     client.pager.draw()
 
+func hasSelectFds(client: Client): bool =
+  return client.timeouts.len > 0 or
+    client.intervals.len > 0 or
+    client.pager.numload > 0 or
+    client.loader.connecting.len > 0 or
+    client.loader.ongoing.len > 0
+
 proc headlessLoop(client: Client) =
-  while client.timeouts.len + client.intervals.len != 0 or client.pager.numload > 0:
+  while client.hasSelectFds():
     let events = client.selector.select(-1)
     for event in events:
       if Read in event.events:
/a> 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276