Add initial swaybar_status_actor utility

This commit is contained in:
Emery Hemingway 2022-10-13 23:22:55 -05:00
parent 96d3bbb500
commit 535fb93df3
3 changed files with 53 additions and 3 deletions

View File

@ -89,7 +89,7 @@ bootDataspace("main") do (dataspace: Ref; turn: var Turn):
## Examples
- [simpleChatProtocol](tests/chat.nim)
- [src/syndicate/unix](./src/syndicate/unix)
- [erisresolver](https://codeberg.org/eris/nim-eris_utils#erisresolver) - dynamic configuration
- [xdg_open_ng](https://git.syndicate-lang.org/ehmry/xdg_open_ng) - messaging, UNIX sockets, dynamic configuration, [Syndicate server](https://synit.org/book/operation/system-bus.html) interaction.

View File

@ -0,0 +1,50 @@
# SPDX-FileCopyrightText: ☭ 2022 Emery Hemingway
# SPDX-License-Identifier: Unlicense
## See the swaybar-protocol(7) manpage.
import std/[asyncdispatch, json, os, strutils]
import preserves, preserves/jsonhooks
import syndicate, syndicate/capabilities
proc unixSocketPath: string =
let args = commandLineParams()
case args.len
of 1: result = args[0]
of 0:
result = getEnv("SYNDICATE_SOCK")
if result == "":
result = getEnv("XDG_RUNTIME_DIR", "/run/user/1000") / "dataspace"
else: quit "must pass Syndicate socket location as the only argument"
proc mintCap: SturdyRef =
var key: array[16, byte]
mint(key, "syndicate")
type SwaybarStatus {.preservesRecord: "swaybar-status".} = object
elem: JsonNode
bootDataspace("main") do (root: Ref; turn: var Turn):
let header = %* { "version": 1 }
stdout.write(header, "\x0a")
stdout.flushFile()
stdout.write("[")
connectUnix(turn, unixSocketPath(), mintCap()) do (turn: var Turn; ds: Ref):
var lineElements = initSet[Ref]()
proc sendLine(turn: var Turn) =
var line: JsonNode
if fromPreserve(line, lineElements):
stdout.writeLine(line, ",")
stdout.flushFile()
else:
stderr.writeLine "could not convert ", lineElements
during(turn, ds, ?SwaybarStatus) do (a: Assertion):
lineElements.incl a
sendLine(turn)
do:
lineElements.excl a
sendLine(turn)
runForever()

View File

@ -1,6 +1,6 @@
# Package
version = "20220904"
version = "20221013"
author = "Emery Hemingway"
description = "Syndicated actors for conversational concurrency"
license = "Unlicense"
@ -9,4 +9,4 @@ srcDir = "src"
# Dependencies
requires "nim >= 1.4.8", "nimSHA2 >= 0.1.1", "preserves >= 20220709"
requires "nim >= 1.4.8", "nimSHA2 >= 0.1.1", "preserves >= 20221013"