diff options
author | bptato <nincsnevem662@gmail.com> | 2022-08-18 17:09:52 +0200 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2022-08-18 17:09:52 +0200 |
commit | a78c26198e747d4de887e1f582d29f14fb59391b (patch) | |
tree | dbea97fe93618e146dd0e3901d54328e86d54fd1 /src/io/buffer.nim | |
parent | e2203257e07aada157be9d0a948273cb9d683072 (diff) | |
download | chawan-a78c26198e747d4de887e1f582d29f14fb59391b.tar.gz |
Use a separate process for file loading
Not very useful for now, since we still have to load the entire page before parsing it.
Diffstat (limited to 'src/io/buffer.nim')
-rw-r--r-- | src/io/buffer.nim | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/src/io/buffer.nim b/src/io/buffer.nim index 08feb73f..e6c290c7 100644 --- a/src/io/buffer.nim +++ b/src/io/buffer.nim @@ -14,6 +14,8 @@ import html/htmlparser import io/cell import io/lineedit import io/loader +import io/request +import io/serialize import io/term import js/regex import layout/box @@ -841,10 +843,17 @@ proc loadResources(buffer: Buffer, document: Document) = if elem.rel == "stylesheet": let url = parseUrl(elem.href, document.location.some) if url.issome: - if url.get.scheme == buffer.location.scheme: - let res = buffer.loader.getPage(url.get) - if res.s != nil and res.contenttype == "text/css": - let sheet = parseStylesheet(res.s) + let url = url.get + if url.scheme == buffer.location.scheme: + let fs = buffer.loader.getPage(newRequest(url)) + if fs.s != nil and fs.contenttype == "text/css": + var res = newStringStream() + while true: + var s: string + buffer.istream.sread(s) + if s == "": break + res.write(s) + let sheet = parseStylesheet(res) elem.sheet = sheet for child in elem.children_rev: @@ -854,8 +863,11 @@ proc load*(buffer: Buffer) = case buffer.contenttype of "text/html": if not buffer.streamclosed: - buffer.source = buffer.istream.readAll() - buffer.istream.close() + while true: + var s: string + buffer.istream.sread(s) + if s == "": break + buffer.source &= s buffer.istream = newStringStream(buffer.source) buffer.document = parseHTML5(buffer.istream) buffer.streamclosed = true |