Add rofi_script_actor
This commit is contained in:
parent
aea55969bb
commit
86be2a67c2
|
@ -0,0 +1,5 @@
|
||||||
|
version 1.
|
||||||
|
|
||||||
|
Environment = { symbol: string ...:... } .
|
||||||
|
Select = <rofi-select @option string @environment Environment> .
|
||||||
|
Options = <rofi-options @options [string ...]> .
|
|
@ -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()
|
|
@ -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))
|
|
@ -1,6 +1,6 @@
|
||||||
# Package
|
# Package
|
||||||
|
|
||||||
version = "20231021"
|
version = "20231026"
|
||||||
author = "Emery Hemingway"
|
author = "Emery Hemingway"
|
||||||
description = "Utilites for Syndicated Actors and Synit"
|
description = "Utilites for Syndicated Actors and Synit"
|
||||||
license = "unlicense"
|
license = "unlicense"
|
||||||
|
|
Loading…
Reference in New Issue