Proper capture references
This commit is contained in:
parent
a959565fb5
commit
1c22d61d0f
|
@ -8,18 +8,21 @@ import ./protocol
|
|||
|
||||
bootDataspace("main") do (root: Ref; turn: var Turn):
|
||||
var
|
||||
actions: seq[tuple[regex: Regex; cmd: string; args: seq[string]]]
|
||||
actions: seq[tuple[regex: Regex; cmd: string; args: seq[Assertion]]]
|
||||
children: Deque[Process]
|
||||
|
||||
connectStdio(root, turn)
|
||||
|
||||
onPublish(turn, root, ?ActionHandler) do (pat: string; cmd: seq[string]):
|
||||
onPublish(turn, root, ?ActionHandler) do (pat: string; cmd: seq[Assertion]):
|
||||
# TODO: during
|
||||
if cmd.len < 2:
|
||||
stderr.writeLine "ignoring ", $cmd, " for ", pat
|
||||
else:
|
||||
var act = (re(pat, {reIgnoreCase, reStudy}), cmd[0], cmd[1..cmd.high],)
|
||||
actions.add act
|
||||
if cmd[0].isString:
|
||||
var act = (re(pat, {reIgnoreCase, reStudy}), cmd[0].string, cmd[1..cmd.high],)
|
||||
actions.add act
|
||||
else:
|
||||
stderr.writeLine "not a valid program specification: ", cmd[0]
|
||||
|
||||
onPublish(turn, root, ?ListenOn[Ref]) do (a: Assertion):
|
||||
let ds = unembed a
|
||||
|
@ -37,7 +40,13 @@ bootDataspace("main") do (root: Ref; turn: var Turn):
|
|||
matched = true
|
||||
var args = newSeq[string](act.args.len)
|
||||
for i, arg in act.args:
|
||||
args[i] = replace(arg, "\\1", uri)
|
||||
if arg.isString:
|
||||
args[i] = replacef(uri, act.regex, arg.string)
|
||||
elif arg.isInteger:
|
||||
if arg.int == 0:
|
||||
args[i] = uri
|
||||
else:
|
||||
args[i] = replacef(uri, act.regex, "$" & $arg.int)
|
||||
var child = startProcess(
|
||||
command = act.cmd, args = args, options = {})
|
||||
children.addLast child
|
||||
|
|
|
@ -20,7 +20,6 @@ bootDataspace("main") do (ds: Ref; turn: var Turn):
|
|||
connectUnix(turn, unixSocketPath(), mintCap()) do (turn: var Turn; a: Assertion) -> TurnAction:
|
||||
let ds = unembed a
|
||||
message(turn, ds, XdgOpen(uris: commandLineParams()))
|
||||
stop(turn, mainFacet)
|
||||
|
||||
for i in 0..7: poll(20)
|
||||
# A hack to exit
|
||||
|
|
|
@ -13,9 +13,17 @@ let ?root_ds = dataspace
|
|||
? <service-object <daemon uri_runner> ?cap> [
|
||||
$cap [
|
||||
<listen-on $root_ds>
|
||||
<action-handler "gemini://.*|file:///.*.gmi" ["/run/current-system/sw/bin/kristall" "\\1"]>
|
||||
<action-handler "http://.*|https://.*|.*html", ["/run/current-system/sw/bin/librewolf" "\\1"]>
|
||||
<action-handler "tox:.*|uri:tox:.*", ["/run/current-system/sw/bin/qtox" "\\1"]>
|
||||
<action-handler ".*\\.avi|.*\\.mkv|.*\\.mp4", ["/run/current-system/sw/bin/mpv" "\\1"]>
|
||||
|
||||
; Here the "0" argument is replaced with the whole URI asserted by xdg-open.
|
||||
<action-handler "http://.*|https://.*|.*html", ["/run/current-system/sw/bin/librewolf" 0]>
|
||||
|
||||
; An argument can be a reference to a capture.
|
||||
<action-handler "(tox:.*)|uri:(tox:.*)", ["/run/current-system/sw/bin/qtox" 1]>
|
||||
|
||||
; An argument can contain a reference to a capture using the $i notation.
|
||||
<action-handler "https://twitter.com/(.*)" ["/run/current-system/sw/bin/librewolf" "https://nitter.net/$1"]>
|
||||
|
||||
<action-handler "gemini://.*|file:///.*.gmi" ["/run/current-system/sw/bin/kristall" 0]>
|
||||
<action-handler ".*\\.avi|.*\\.mkv|.*\\.mp4|.*\\.ogg|.*\\.opus", ["/run/current-system/sw/bin/mpv" 0]>
|
||||
]
|
||||
]
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
# Package
|
||||
|
||||
version = "0.2.0"
|
||||
version = "0.3.0"
|
||||
author = "Emery"
|
||||
description = "A better xdg-open"
|
||||
license = "Unlicense"
|
||||
|
|
Loading…
Reference in New Issue