syndicated-open/src/protocol.nim

40 lines
1021 B
Nim
Raw Normal View History

2022-02-26 23:39:22 +00:00
import
std/typetraits, preserves
type
XdgOpen* {.preservesRecord: "xdg-open".} = object
`uris`*: seq[string]
2022-02-26 23:39:22 +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
of UriRunnerConfigKind.`ActionHandler`:
`actionhandler`*: ActionHandler[E]
2022-02-26 23:39:22 +00:00
ListenOn*[E] {.preservesRecord: "listen-on".} = ref object
`dataspace`*: Preserve[E]
ActionHandler*[E] {.preservesRecord: "action-handler".} = ref object
2022-02-26 23:39:22 +00:00
`pat`*: string
`action`*: Preserve[E]
`entity`*: Preserve[E]
2022-02-26 23:39:22 +00:00
proc `$`*[E](x: UriRunnerConfig[E] | ListenOn[E] | ActionHandler[E]): string =
2022-02-26 23:39:22 +00:00
`$`(toPreserve(x, E))
proc encode*[E](x: UriRunnerConfig[E] | ListenOn[E] | ActionHandler[E]): seq[
byte] =
2022-02-26 23:39:22 +00:00
encode(toPreserve(x, E))
proc `$`*(x: XdgOpen): string =
2022-02-26 23:39:22 +00:00
`$`(toPreserve(x))
proc encode*(x: XdgOpen): seq[byte] =
2022-02-26 23:39:22 +00:00
encode(toPreserve(x))