Add rofi_script_actor

This commit is contained in:
Emery Hemingway 2023-10-26 17:20:26 +01:00
parent aea55969bb
commit 86be2a67c2
4 changed files with 66 additions and 1 deletions

5
rofi.prs Normal file
View File

@ -0,0 +1,5 @@
version 1.
Environment = { symbol: string ...:... } .
Select = <rofi-select @option string @environment Environment> .
Options = <rofi-options @options [string ...]> .

42
src/rofi_script_actor.nim Normal file
View File

@ -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()

18
src/schema/rofi.nim Normal file
View File

@ -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))

View File

@ -1,6 +1,6 @@
# Package
version = "20231021"
version = "20231026"
author = "Emery Hemingway"
description = "Utilites for Syndicated Actors and Synit"
license = "unlicense"