syndicated-open/src/protocol.nim

38 lines
970 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
2022-02-26 23:39:22 +00:00
ListenOn*[E] {.preservesRecord: "listen-on".} = ref object
`dataspace`*: Preserve[E]
ActionHandler* {.preservesRecord: "action-handler".} = object
2022-02-26 23:39:22 +00:00
`pat`*: string
`cmd`*: seq[string]
proc `$`*[E](x: UriRunnerConfig[E] | ListenOn[E]): string =
2022-02-26 23:39:22 +00:00
`$`(toPreserve(x, E))
proc encode*[E](x: UriRunnerConfig[E] | ListenOn[E]): seq[byte] =
2022-02-26 23:39:22 +00:00
encode(toPreserve(x, E))
proc `$`*(x: XdgOpen | ActionHandler): string =
2022-02-26 23:39:22 +00:00
`$`(toPreserve(x))
proc encode*(x: XdgOpen | ActionHandler): seq[byte] =
2022-02-26 23:39:22 +00:00
encode(toPreserve(x))