aboutsummaryrefslogtreecommitdiffstats
path: root/src/render
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2024-02-12 17:03:35 +0100
committerbptato <nincsnevem662@gmail.com>2024-02-12 17:03:35 +0100
commit8e6783a45fba48dd8f63fe7486e4691f05220b52 (patch)
tree5aae9f9f95432609a497eea858c4a3401dac172b /src/render
parent69b1a7e7f6e0a675cd70805768162de5621e8279 (diff)
downloadchawan-8e6783a45fba48dd8f63fe7486e4691f05220b52.tar.gz
Remove CLONE BufferSource; cache document sources in tmpdir
At last all BufferSources are unified. To achieve the same effect as the previous CLONE source type, we now use the "fromcache" flag in Request. This *forces* the document to be streamed from the disk; if the file no longer exists for some reason, an error is returned (i.e. the document is not re-downloaded). For a document to be cached, it has to be the main document of the buffer (i.e. no additional resources requested with fetch()), and also not an x-htmloutput HTML file (for those, the original source is saved). The result is that toggleSource now always returns the actual source for e.g. markdown files, not the HTML-transformed version. Also, it is now possible to view the source of a document that is still being downloaded. buffer.sstream has almost been eliminated; it still exists, but only as a pseudo-buffer to interface with EncoderStream and DecoderStream. It no longer holds the entire source of a buffer at any point, and is cleared as soon as the buffer is completely loaded.
Diffstat (limited to 'src/render')
-rw-r--r--src/render/rendertext.nim11
1 files changed, 7 insertions, 4 deletions
diff --git a/src/render/rendertext.nim b/src/render/rendertext.nim
index fc258710..bbf2ec49 100644
--- a/src/render/rendertext.nim
+++ b/src/render/rendertext.nim
@@ -20,9 +20,11 @@ type StreamRenderer* = object
newline: bool
w: int
j: int # byte in line
+ rewindImpl: proc()
-proc newStreamRenderer*(stream: Stream, charsets0: openArray[Charset]):
- StreamRenderer =
+#TODO pass bool for whether we can rewind
+proc newStreamRenderer*(stream: Stream, charsets0: openArray[Charset],
+ rewindImpl: proc()): StreamRenderer =
var charsets = newSeq[Charset](charsets0.len)
for i in 0 ..< charsets.len:
charsets[i] = charsets0[charsets.high - i]
@@ -44,11 +46,12 @@ proc newStreamRenderer*(stream: Stream, charsets0: openArray[Charset]):
charsets: charsets,
ansiparser: AnsiCodeParser(
state: PARSE_DONE
- )
+ ),
+ rewindImpl: rewindImpl
)
proc rewind(renderer: var StreamRenderer) =
- renderer.stream.setPosition(0)
+ renderer.rewindImpl()
let cs = renderer.charsets.pop()
let em = if renderer.charsets.len > 0:
DECODER_ERROR_MODE_FATAL