From 1c22d61d0f90078335f2f78765cffa640644f994 Mon Sep 17 00:00:00 2001 From: Emery Hemingway Date: Fri, 15 Apr 2022 18:04:37 -0500 Subject: [PATCH] Proper capture references --- src/uri_runner.nim | 19 ++++++++++++++----- src/xdg_open.nim | 1 - uri_runner.pr | 16 ++++++++++++---- xdg_open_ng.nimble | 2 +- 4 files changed, 27 insertions(+), 11 deletions(-) diff --git a/src/uri_runner.nim b/src/uri_runner.nim index 15ecd06..e4d16f8 100644 --- a/src/uri_runner.nim +++ b/src/uri_runner.nim @@ -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 diff --git a/src/xdg_open.nim b/src/xdg_open.nim index ed30d8f..fd0fef9 100644 --- a/src/xdg_open.nim +++ b/src/xdg_open.nim @@ -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 diff --git a/uri_runner.pr b/uri_runner.pr index 7bfbc8b..35837c1 100644 --- a/uri_runner.pr +++ b/uri_runner.pr @@ -13,9 +13,17 @@ let ?root_ds = dataspace ? ?cap> [ $cap [ - - - - + + ; Here the "0" argument is replaced with the whole URI asserted by xdg-open. + + + ; An argument can be a reference to a capture. + + + ; An argument can contain a reference to a capture using the $i notation. + + + + ] ] diff --git a/xdg_open_ng.nimble b/xdg_open_ng.nimble index 6a2f6ae..ae4b6b6 100644 --- a/xdg_open_ng.nimble +++ b/xdg_open_ng.nimble @@ -1,6 +1,6 @@ # Package -version = "0.2.0" +version = "0.3.0" author = "Emery" description = "A better xdg-open" license = "Unlicense"