about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2022-12-15 18:59:18 +0100
committerbptato <nincsnevem662@gmail.com>2022-12-15 18:59:18 +0100
commitf0de405c6614356928d8700e2e95d00d97ffe2f9 (patch)
tree09c20a94ad68c9cf9a53084925a52fc93279d03c
parent4cd5832ec1bfd02e8afdf5777546cadbe5eaaafb (diff)
downloadchawan-f0de405c6614356928d8700e2e95d00d97ffe2f9.tar.gz
Fix console display bugs, add container.location
-rw-r--r--src/buffer/container.nim5
-rw-r--r--src/display/client.nim7
-rw-r--r--src/render/rendertext.nim7
3 files changed, 15 insertions, 4 deletions
diff --git a/src/buffer/container.nim b/src/buffer/container.nim
index 7a3534be..85c3b9e8 100644
--- a/src/buffer/container.nim
+++ b/src/buffer/container.nim
@@ -115,6 +115,9 @@ proc newBuffer*(dispatcher: Dispatcher, config: BufferConfig,
   istream.sread(result.process)
   result.pos.setx = -1
 
+func location*(container: Container): URL {.jsfunc.} =
+  container.source.location
+
 func lineLoaded(container: Container, y: int): bool =
   return y - container.lineshift in 0..container.lines.high
 
@@ -271,7 +274,7 @@ proc setNumLines(container: Container, lines: int, finish = false) =
     container.updateCursor()
     container.triggerEvent(STATUS)
 
-proc requestLines*(container: Container, w = container.lineWindow) =
+proc requestLines*(container: Container, w = container.lineWindow): auto {.discardable.} =
   container.iface.getLines(w).then(proc(res: tuple[numLines: int, lines: seq[SimpleFlexibleLine]]) =
     container.lines.setLen(w.len)
     container.lineshift = w.a
diff --git a/src/display/client.nim b/src/display/client.nim
index 34077055..5162d4aa 100644
--- a/src/display/client.nim
+++ b/src/display/client.nim
@@ -13,6 +13,7 @@ when defined(posix):
 import std/exitprocs
 
 import bindings/quickjs
+import buffer/buffer
 import buffer/container
 import css/sheet
 import config/config
@@ -123,9 +124,9 @@ proc command0(client: Client, src: string, filename = "<command>", silence = fal
   free(ret)
 
 proc command(client: Client, src: string) =
-  restoreStdin(client.console.tty.getFileHandle())
   client.command0(src)
-  client.console.container.cursorLastLine()
+  client.console.container.requestLines().then(proc() =
+    client.console.container.cursorLastLine())
 
 proc quit(client: Client, code = 0) {.jsfunc.} =
   if client.alive:
@@ -385,6 +386,7 @@ proc newConsole(pager: Pager, tty: File): Console =
       raise newException(Defect, "Failed to open file for console pipe.")
     result.err = newFileStream(f)
     result.err.writeLine("Type (M-c) console.hide() to return to buffer mode.")
+    result.err.flush()
     result.pager = pager
     result.tty = tty
     pager.registerContainer(result.container)
@@ -448,6 +450,7 @@ proc show(console: Console) {.jsfunc.} =
   if console.pager.container != console.container:
     console.prev = console.pager.container
     console.pager.setContainer(console.container)
+    console.container.requestLines()
 
 proc hide(console: Console) {.jsfunc.} =
   if console.pager.container == console.container:
diff --git a/src/render/rendertext.nim b/src/render/rendertext.nim
index 79bdb541..1031f08d 100644
--- a/src/render/rendertext.nim
+++ b/src/render/rendertext.nim
@@ -55,6 +55,7 @@ type StreamRenderer* = object
   format: Format
   af: bool
   decoder: DecoderStream
+  newline: bool
 
 proc newStreamRenderer*(stream: Stream): StreamRenderer =
   result.format = newFormat()
@@ -73,6 +74,10 @@ proc renderStream*(grid: var FlexibleGrid, renderer: var StreamRenderer, len: in
   var buf = newSeq[Rune](len * 4)
   let n = renderer.decoder.readData(addr buf[0], buf.len * sizeof(buf[0]))
   while i < n div sizeof(buf[0]):
+    if renderer.newline:
+      # avoid newline at end of stream
+      grid.addLine()
+      renderer.newline = false
     let r = buf[i]
     if r.isAscii():
       let c = cast[char](r)
@@ -86,7 +91,7 @@ proc renderStream*(grid: var FlexibleGrid, renderer: var StreamRenderer, len: in
       case c
       of '\n':
         add_format
-        grid.addLine()
+        renderer.newline = true
       of '\r': discard
       of '\t':
         add_format