diff options
author | bptato <nincsnevem662@gmail.com> | 2022-12-13 17:03:17 +0100 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2022-12-13 17:03:17 +0100 |
commit | 4b482418c22ea31729ca94583ffd2a6aa167d811 (patch) | |
tree | 9c456555f1b3cfd45d90f28d61d7369ab96e1c5d /src/buffer | |
parent | 672ab553c4a2b10a703ea40e049eda52db149a93 (diff) | |
download | chawan-4b482418c22ea31729ca94583ffd2a6aa167d811.tar.gz |
Fix stream error handling confusion, title display
Also probably other fixes.
Diffstat (limited to 'src/buffer')
-rw-r--r-- | src/buffer/buffer.nim | 25 | ||||
-rw-r--r-- | src/buffer/container.nim | 7 |
2 files changed, 22 insertions, 10 deletions
diff --git a/src/buffer/buffer.nim b/src/buffer/buffer.nim index b692e253..11492834 100644 --- a/src/buffer/buffer.nim +++ b/src/buffer/buffer.nim @@ -47,7 +47,8 @@ type BufferCommand* = enum LOAD, RENDER, WINDOW_CHANGE, FIND_ANCHOR, READ_SUCCESS, READ_CANCELED, CLICK, FIND_NEXT_LINK, FIND_PREV_LINK, FIND_NEXT_MATCH, FIND_PREV_MATCH, - GET_SOURCE, GET_LINES, UPDATE_HOVER, PASS_FD, CONNECT, GOTO_ANCHOR, CANCEL + GET_SOURCE, GET_LINES, UPDATE_HOVER, PASS_FD, CONNECT, GOTO_ANCHOR, CANCEL, + GET_TITLE BufferMatch* = object success*: bool @@ -233,7 +234,7 @@ macro proxy(fun: typed) = proxy0(`fun`) proxy1(`fun`) -func getTitle(node: StyledNode): string = +func getTitleAttr(node: StyledNode): string = if node == nil: return "" if node.t == STYLED_ELEMENT and node.node != nil: @@ -476,7 +477,7 @@ proc updateHover*(buffer: Buffer, cursorx, cursory: int): UpdateHoverResult {.pr result.repaint = true var upd = false - let title = thisnode.getTitle() + let title = thisnode.getTitleAttr() if title != "": upd = true buffer.hovertext = title @@ -606,8 +607,9 @@ proc load*(buffer: Buffer): tuple[atend: bool, lines, bytes: int] {.proxy.} = try: buffer.sstream.setPosition(op + buffer.available) let n = buffer.istream.readData(addr s[0], buffer.readbufsize) + assert n != 0 s.setLen(n) - result = (n == 0, buffer.lines.len, bytes) + result = (false, buffer.lines.len, n) buffer.sstream.setPosition(op) if buffer.readbufsize < BufferSize: buffer.readbufsize = min(BufferSize, buffer.readbufsize * 2) @@ -617,8 +619,9 @@ proc load*(buffer: Buffer): tuple[atend: bool, lines, bytes: int] {.proxy.} = bytes = buffer.available else: buffer.do_reshape() - if result.atend: - buffer.finishLoad() + except EOFError: + result = (true, buffer.lines.len, 0) + buffer.finishLoad() except ErrorAgain, ErrorWouldBlock: buffer.timeout = buffer.lasttimeout if buffer.readbufsize == 1: @@ -630,6 +633,10 @@ proc load*(buffer: Buffer): tuple[atend: bool, lines, bytes: int] {.proxy.} = buffer.readbufsize = buffer.readbufsize div 2 result = (false, buffer.lines.len, bytes) +proc getTitle*(buffer: Buffer): string {.proxy.} = + if buffer.document != nil: + return buffer.document.title + proc render*(buffer: Buffer): int {.proxy.} = buffer.do_reshape() return buffer.lines.len @@ -1081,9 +1088,9 @@ proc runBuffer(buffer: Buffer, rfd: int) = try: buffer.readCommand() except IOError: - #eprint "ERROR IN BUFFER", buffer.location - #eprint "MESSAGE:", getCurrentExceptionMsg() - #eprint getStackTrace(getCurrentException()) + #eprint "ERROR IN BUFFER", $buffer.location & "\nMESSAGE:", + # getCurrentExceptionMsg() & "\n", + # getStackTrace(getCurrentException()) break loop else: assert false diff --git a/src/buffer/container.nim b/src/buffer/container.nim index 67c45aa2..5c579c27 100644 --- a/src/buffer/container.nim +++ b/src/buffer/container.nim @@ -627,7 +627,12 @@ proc onload(container: Container, res: tuple[atend: bool, lines, bytes: int]) = discard container.iface.load().then(proc(res: tuple[atend: bool, lines, bytes: int]) = container.onload(res)) else: - container.iface.render().then(proc(lines: int): auto = + container.iface.getTitle().then(proc(title: string): auto = + if title != "": + container.title = title + container.triggerEvent(STATUS) + return container.iface.render() + ).then(proc(lines: int): auto = container.setNumLines(lines, true) container.needslines = true container.triggerEvent(LOADED) |