# SPDX-FileCopyrightText: ☭ 2021 Emery Hemingway # SPDX-License-Identifier: Unlicense import std/[asyncdispatch, os, parseopt, strutils, xmltree] import preserves, preserves/xmlhooks import syndicate, syndicate/[actors, capabilities, relay] import parsegemini import gemclient import nimsvg import ../src/zua/protocol proc quitHook() {.noconv.} = quit() proc main() = setControlCHook(quitHook) waitFor runActor("client") do (turn: var Turn): let cap = mint() connectUnix(turn, "/run/syndicate/ds", cap) do (turn: var Turn; a: Assertion) -> TurnAction: let ds = unembed a let client = newGeminiClient() for kind, arg, _ in getopt(): if kind == cmdArgument and arg.startsWith"gemini": var nodes: seq[Nodes] p: GeminiParser let resp = client.fetch(arg) open(p, resp.bodyStream) # TODO: append to a text block until running into verbatim text, # then push the current text and open a new block while true: p.next() case p.kind of gmiEof: break else: let n = buildSvg: t: xmltree.escape p.text nodes.add n close(p) let doc = buildSvg: svg(viewBox="0 0 600 800", `font-family` = "Gentium Plus", `font-size`="20"): text: for n in nodes: embed n let buf = render doc stdout.writeLine buf discard publish(turn, ds, Pane(svg: buf)) stderr.writeLine "done" main()