2022-02-26 23:39:22 +00:00
|
|
|
|
|
|
|
import
|
|
|
|
std/typetraits, preserves
|
|
|
|
|
|
|
|
type
|
|
|
|
XdgOpen* {.preservesRecord: "xdg-open".} = object
|
2022-03-19 00:22:31 +00:00
|
|
|
`uris`*: seq[string]
|
2022-02-26 23:39:22 +00:00
|
|
|
|
2022-03-19 00:22:31 +00:00
|
|
|
UriRunnerConfigKind* {.pure.} = enum
|
|
|
|
`ListenOn`, `ActionHandler`
|
|
|
|
`UriRunnerConfig`*[E] {.preservesOr.} = ref object
|
|
|
|
case orKind*: UriRunnerConfigKind
|
|
|
|
of UriRunnerConfigKind.`ListenOn`:
|
|
|
|
`listenon`*: ListenOn[E]
|
2022-02-26 23:39:22 +00:00
|
|
|
|
2022-03-19 00:22:31 +00:00
|
|
|
of UriRunnerConfigKind.`ActionHandler`:
|
2022-06-25 18:53:51 +00:00
|
|
|
`actionhandler`*: ActionHandler[E]
|
2022-02-26 23:39:22 +00:00
|
|
|
|
2022-03-19 00:22:31 +00:00
|
|
|
|
|
|
|
ListenOn*[E] {.preservesRecord: "listen-on".} = ref object
|
|
|
|
`dataspace`*: Preserve[E]
|
|
|
|
|
2022-06-25 18:53:51 +00:00
|
|
|
ActionHandler*[E] {.preservesRecord: "action-handler".} = ref object
|
2022-02-26 23:39:22 +00:00
|
|
|
`pat`*: string
|
2022-06-25 18:53:51 +00:00
|
|
|
`action`*: Preserve[E]
|
|
|
|
`entity`*: Preserve[E]
|
2022-02-26 23:39:22 +00:00
|
|
|
|
2022-06-25 18:53:51 +00:00
|
|
|
proc `$`*[E](x: UriRunnerConfig[E] | ListenOn[E] | ActionHandler[E]): string =
|
2022-02-26 23:39:22 +00:00
|
|
|
`$`(toPreserve(x, E))
|
|
|
|
|
2022-06-25 18:53:51 +00:00
|
|
|
proc encode*[E](x: UriRunnerConfig[E] | ListenOn[E] | ActionHandler[E]): seq[
|
|
|
|
byte] =
|
2022-02-26 23:39:22 +00:00
|
|
|
encode(toPreserve(x, E))
|
|
|
|
|
2022-06-25 18:53:51 +00:00
|
|
|
proc `$`*(x: XdgOpen): string =
|
2022-02-26 23:39:22 +00:00
|
|
|
`$`(toPreserve(x))
|
|
|
|
|
2022-06-25 18:53:51 +00:00
|
|
|
proc encode*(x: XdgOpen): seq[byte] =
|
2022-02-26 23:39:22 +00:00
|
|
|
encode(toPreserve(x))
|