diff options
author | bptato <nincsnevem662@gmail.com> | 2025-02-18 19:35:05 +0100 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2025-02-18 19:41:40 +0100 |
commit | a1154392ac6d012302031fbbda574d2da059c745 (patch) | |
tree | ef47d1bb8e41dd0760cab75a825d858e1a7beb74 /src/local | |
parent | 4f785b483c92ef9755258e49de4a40a14ae4faf6 (diff) | |
download | chawan-a1154392ac6d012302031fbbda574d2da059c745.tar.gz |
Add mark-links feature
ref. https://todo.sr.ht/~bptato/chawan/43
Diffstat (limited to 'src/local')
-rw-r--r-- | src/local/container.nim | 24 | ||||
-rw-r--r-- | src/local/pager.nim | 5 |
2 files changed, 22 insertions, 7 deletions
diff --git a/src/local/container.nim b/src/local/container.nim index a6670498..d52d4159 100644 --- a/src/local/container.nim +++ b/src/local/container.nim @@ -1736,25 +1736,37 @@ proc setCloneStream*(container: Container; stream: BufStream) = # Maybe we have to resume loading. Let's try. container.startLoad() -proc onreadline(container: Container; w: Slice[int]; - handle: (proc(line: SimpleFlexibleLine)); res: GetLinesResult) = +proc onReadLine(container: Container; w: Slice[int]; + handle: (proc(line: SimpleFlexibleLine)); res: GetLinesResult): + EmptyPromise = for line in res.lines: handle(line) if res.numLines > w.b + 1: var w = w w.a += 24 w.b += 24 - container.iface.getLines(w).then(proc(res: GetLinesResult) = - container.onreadline(w, handle, res)) + return container.iface.getLines(w).then(proc(res: GetLinesResult): + EmptyPromise = + return container.onReadLine(w, handle, res) + ) else: container.numLines = res.numLines + return newResolvedPromise() # Synchronously read all lines in the buffer. proc readLines*(container: Container; handle: proc(line: SimpleFlexibleLine)) = # load succeded let w = 0 .. 23 - container.iface.getLines(w).then(proc(res: GetLinesResult) = - container.onreadline(w, handle, res)) + container.iface.getLines(w).then(proc(res: GetLinesResult): EmptyPromise = + return container.onReadLine(w, handle, res) + ).then(proc() = + if container.config.markLinks: + container.iface.getLinks.then(proc(res: seq[string]) = + handle(SimpleFlexibleLine()) + for i, link in res.mypairs: + handle(SimpleFlexibleLine(str: "[" & $(i + 1) & "] " & link)) + ) + ) while container.iface.hasPromises: # fulfill all promises container.handleCommand() diff --git a/src/local/pager.nim b/src/local/pager.nim index 0315eebf..0da33a65 100644 --- a/src/local/pager.nim +++ b/src/local/pager.nim @@ -1753,7 +1753,8 @@ proc applySiteconf(pager: Pager; url: URL; charsetOverride: Charset; charsetOverride: charsetOverride, protocol: pager.config.protocol, metaRefresh: pager.config.buffer.metaRefresh, - cookieMode: pager.config.buffer.cookie + cookieMode: pager.config.buffer.cookie, + markLinks: pager.config.buffer.markLinks ) loaderConfig = LoaderClientConfig( originURL: url, @@ -1823,6 +1824,8 @@ proc applySiteconf(pager: Pager; url: URL; charsetOverride: Charset; result.metaRefresh = sc.metaRefresh.get if sc.history.isSome: result.history = sc.history.get + if sc.markLinks.isSome: + result.markLinks = sc.markLinks.get loaderConfig.filter.allowschemes .add(pager.config.external.urimethodmap.imageProtos) if result.images: |