From 86be2a67c27a99af573299eb60618e18e5abdea9 Mon Sep 17 00:00:00 2001 From: Emery Hemingway Date: Thu, 26 Oct 2023 17:20:26 +0100 Subject: [PATCH] Add rofi_script_actor --- rofi.prs | 5 +++++ src/rofi_script_actor.nim | 42 +++++++++++++++++++++++++++++++++++++++ src/schema/rofi.nim | 18 +++++++++++++++++ syndicate_utils.nimble | 2 +- 4 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 rofi.prs create mode 100644 src/rofi_script_actor.nim create mode 100644 src/schema/rofi.nim diff --git a/rofi.prs b/rofi.prs new file mode 100644 index 0000000..aa46f85 --- /dev/null +++ b/rofi.prs @@ -0,0 +1,5 @@ +version 1. + +Environment = { symbol: string ...:... } . +Select = . +Options = . diff --git a/src/rofi_script_actor.nim b/src/rofi_script_actor.nim new file mode 100644 index 0000000..4918374 --- /dev/null +++ b/src/rofi_script_actor.nim @@ -0,0 +1,42 @@ +# SPDX-FileCopyrightText: ☭ 2022 Emery Hemingway +# SPDX-License-Identifier: Unlicense + +## See the rofi-script(5) manpage for documentation. + +import std/[asyncdispatch, cmdline, envvars, strutils, tables] +import preserves, syndicate, syndicate/relays +import ./schema/rofi + +proc main = + let + route = envRoute() + rofiPid = getEnv("ROFI_OUTSIDE") + if rofiPid == "": + quit("run this program in rofi") + + runActor("rofi_script_actor") do (turn: var Turn; root: Cap): + let rootFacet = turn.facet + resolve(turn, root, route) do (turn: var Turn; ds: Cap): + case paramCount() + of 0: + let pat = ?Options + onPublish(turn, ds, pat) do (options: seq[string]): + stdout.writeLine options.join("\n") + quit() + + of 1: + var select = Select(option: commandLineParams()[0]) + for (key, val) in envPairs(): + if key.startsWith "ROFI_": + select.environment[Symbol key] = val + message(turn, ds, select) + # TODO: sync not implemented correctly + # sync(turn, ds, stopActor) + callSoon do (): + waitFor sleepAsync(1) + quit() + + else: + quit("rofi passed an unexpected number of arguments") + +main() diff --git a/src/schema/rofi.nim b/src/schema/rofi.nim new file mode 100644 index 0000000..d9ef867 --- /dev/null +++ b/src/schema/rofi.nim @@ -0,0 +1,18 @@ + +import + preserves, std/tables + +type + Environment* = Table[Symbol, string] + Select* {.preservesRecord: "rofi-select".} = object + `option`*: string + `environment`*: Environment + + Options* {.preservesRecord: "rofi-options".} = object + `options`*: seq[string] + +proc `$`*(x: Environment | Select | Options): string = + `$`(toPreserve(x)) + +proc encode*(x: Environment | Select | Options): seq[byte] = + encode(toPreserve(x)) diff --git a/syndicate_utils.nimble b/syndicate_utils.nimble index 9ae12ae..1b9197e 100644 --- a/syndicate_utils.nimble +++ b/syndicate_utils.nimble @@ -1,6 +1,6 @@ # Package -version = "20231021" +version = "20231026" author = "Emery Hemingway" description = "Utilites for Syndicated Actors and Synit" license = "unlicense"