diff options
author | bptato <nincsnevem662@gmail.com> | 2024-04-25 01:06:43 +0200 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2024-04-25 01:20:58 +0200 |
commit | 14b871eb7eaf329b67b71385597f114f8782318a (patch) | |
tree | ac7b4655124b4579ad27d56116d9a2dee63cd31e /src/server/buffer.nim | |
parent | 62944ac7abc6e37475739a1667ed5a0240fedf66 (diff) | |
download | chawan-14b871eb7eaf329b67b71385597f114f8782318a.tar.gz |
Initial image support
* png: add missing filters, various decoder fixes * term: fix kitty response interpretation, add support for kitty image detection * buffer, pager: initial image display support Emphasis on "initial"; it only "works" with kitty output and PNG input. Also, it's excruciatingly slow, and repaints images way too often. Left undocumented intentionally it for now, until it actually becomes useful. In the meantime, adventurous users can find out themselves why: [[siteconf]] url = "https://.*" images = true
Diffstat (limited to 'src/server/buffer.nim')
-rw-r--r-- | src/server/buffer.nim | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/src/server/buffer.nim b/src/server/buffer.nim index 10d1cce0..56ad946f 100644 --- a/src/server/buffer.nim +++ b/src/server/buffer.nim @@ -26,6 +26,7 @@ import html/enums import html/env import html/event import html/formdata as formdata_impl +import img/bitmap import io/bufreader import io/bufstream import io/bufwriter @@ -91,6 +92,7 @@ type ishtml: bool firstBufferRead: bool lines: FlexibleGrid + images: seq[PosBitmap] request: Request # source request attrs: WindowAttributes window: Window @@ -648,7 +650,9 @@ proc findNextMatch*(buffer: Buffer; regex: Regex; cursorx, cursory: int; break inc y -proc gotoAnchor*(buffer: Buffer): Opt[tuple[x, y: int]] {.proxy.} = +type GotoAnchorResult* = Opt[tuple[x, y: int]] + +proc gotoAnchor*(buffer: Buffer): GotoAnchorResult {.proxy.} = if buffer.document == nil: return err() let anchor = buffer.document.findAnchor(buffer.url.anchor) @@ -673,7 +677,8 @@ proc do_reshape(buffer: Buffer) = buffer.prevStyled = nil let styledRoot = buffer.document.applyStylesheets(uastyle, buffer.userstyle, buffer.prevStyled) - buffer.lines.renderDocument(buffer.bgcolor, styledRoot, addr buffer.attrs) + buffer.lines.renderDocument(buffer.bgcolor, styledRoot, addr buffer.attrs, + buffer.images) buffer.prevStyled = styledRoot proc processData0(buffer: Buffer; data: openArray[char]): bool = @@ -1718,11 +1723,11 @@ proc readCanceled*(buffer: Buffer): bool {.proxy.} = proc findAnchor*(buffer: Buffer; anchor: string): bool {.proxy.} = return buffer.document != nil and buffer.document.findAnchor(anchor) != nil -type GetLinesResult* = tuple[ - numLines: int, - lines: seq[SimpleFlexibleLine], +type GetLinesResult* = tuple + numLines: int + lines: seq[SimpleFlexibleLine] bgcolor: CellColor -] + images: seq[PosBitmap] proc getLines*(buffer: Buffer; w: Slice[int]): GetLinesResult {.proxy.} = var w = w @@ -1736,6 +1741,11 @@ proc getLines*(buffer: Buffer; w: Slice[int]): GetLinesResult {.proxy.} = result.lines.add(line) result.numLines = buffer.lines.len result.bgcolor = buffer.bgcolor + if buffer.config.images: + for image in buffer.images: + if image.y <= w.b and + image.y + int(image.bmp.height) div buffer.attrs.ppl >= w.a: + result.images.add(image) proc markURL*(buffer: Buffer; schemes: seq[string]) {.proxy.} = if buffer.document == nil or buffer.document.body == nil: |