From 638950be4940d71a18e5856919e6a48d3241ec8c Mon Sep 17 00:00:00 2001 From: Emery Hemingway Date: Mon, 13 Dec 2021 18:28:06 +0000 Subject: [PATCH] Move protocol to svui repository --- protocol.prs | 3 --- src/zua.nim | 9 ++++++--- src/zua/Tupfile | 1 - src/zua/protocol.nim | 13 ------------- tests/client.nim | 9 ++++----- tests/gemsvg.nim | 23 +++++++++++++---------- 6 files changed, 23 insertions(+), 35 deletions(-) delete mode 100644 protocol.prs delete mode 100644 src/zua/Tupfile delete mode 100644 src/zua/protocol.nim diff --git a/protocol.prs b/protocol.prs deleted file mode 100644 index 04247c1..0000000 --- a/protocol.prs +++ /dev/null @@ -1,3 +0,0 @@ -version 1. - -Pane = . diff --git a/src/zua.nim b/src/zua.nim index 3a62659..d03a95c 100644 --- a/src/zua.nim +++ b/src/zua.nim @@ -12,9 +12,12 @@ import pixie, pixie/fileformats/svg import math, sdl2, sdl2/gfx -import ./zua/protocol +import svui -type SdlError = object of CatchableError +type + Svui = svui.Svui[Ref] + SdlError = object of CatchableError + Attrs = Table[string, Assertion] template check(res: cint) = if res != 0: @@ -136,7 +139,7 @@ proc main() = connectUnix(turn, "/run/syndicate/ds", cap) do (turn: var Turn; a: Assertion) -> TurnAction: let ds = unembed a - onPublish(turn, ds, protocol.Pane ? {0: `?*`()}) do (svg: string): + onPublish(turn, ds, Svui ? {0: drop(), 1: grab()}) do (svg: string): onRetract: app.panes.del(hash svg) app.update() diff --git a/src/zua/Tupfile b/src/zua/Tupfile deleted file mode 100644 index 420bf7e..0000000 --- a/src/zua/Tupfile +++ /dev/null @@ -1 +0,0 @@ -: ../../protocol.prs |> preserves_schema_nim %f |> protocol.nim diff --git a/src/zua/protocol.nim b/src/zua/protocol.nim deleted file mode 100644 index e11b122..0000000 --- a/src/zua/protocol.nim +++ /dev/null @@ -1,13 +0,0 @@ - -import - std/typetraits, preserves - -type - Pane* {.preservesRecord: "svg".} = object - `svg`*: string - -proc `$`*(x: Pane): string = - `$`(toPreserve(x)) - -proc encode*(x: Pane): seq[byte] = - encode(toPreserve(x)) diff --git a/tests/client.nim b/tests/client.nim index 1cdab07..5ff2868 100644 --- a/tests/client.nim +++ b/tests/client.nim @@ -6,12 +6,11 @@ import preserves import syndicate, syndicate/[actors, capabilities, relay] -import ../src/zua/protocol - -proc quitHook() {.noconv.} = - quit() +import svui +type Svui = svui.Svui[Ref] proc main() = + proc quitHook() {.noconv.} = quit() setControlCHook(quitHook) waitFor runActor("client") do (turn: var Turn): @@ -31,7 +30,7 @@ proc main() = if xml.tag != "svg": stderr.writeLine arg, " not recognized as SVG" else: - discard publish(turn, ds, Pane(svg: $xml)) + discard publish(turn, ds, Svui(svg: $xml)) stderr.writeLine "done" diff --git a/tests/gemsvg.nim b/tests/gemsvg.nim index 1c2fb1a..4098cda 100644 --- a/tests/gemsvg.nim +++ b/tests/gemsvg.nim @@ -1,19 +1,19 @@ # SPDX-FileCopyrightText: ☭ 2021 Emery Hemingway # SPDX-License-Identifier: Unlicense -import std/[asyncdispatch, os, parseopt, strutils, xmltree] +import std/[asyncdispatch, os, parseopt, strutils, tables, xmltree] import preserves, preserves/xmlhooks import syndicate, syndicate/[actors, capabilities, relay] import parsegemini import gemclient import nimsvg +import svui +import eris -import ../src/zua/protocol - -proc quitHook() {.noconv.} = - quit() +type Svui = svui.Svui[Ref] proc main() = + proc quitHook() {.noconv.} = quit() setControlCHook(quitHook) waitFor runActor("client") do (turn: var Turn): @@ -44,11 +44,14 @@ proc main() = 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)) + g(fill="white"): + text(fill="black"): + for n in nodes: embed n + let + buf = render doc + bs = if buf.len < (16 shl 10): bs1k else: bs32k + capPr = toPreserve($erisCap(buf, bs), Ref) + discard publish(turn, ds, Svui(attrs: toTable {"urn": capPr}, svg: buf)) stderr.writeLine "done"