Shell out to the host OS opener so Vis can hand a URL or local file path off to the user's preferred external browser/viewer.
Responsibilities, in order:
Classify the candidate target into a whitelisted scheme keyword:
:http, :https, :file, :rel, or :rejected.
Resolve the target to a host-friendly form. Relative paths are
anchored at the current working directory and re-checked for
.. traversal. Returns nil when the path escapes.
Build the OS-appropriate command vector
(open / xdg-open / cmd /c start) for ProcessBuilder.
Spawn it with stdio redirected to /dev/null so a chatty opener cannot corrupt terminal output.
Pure-ish: every step except open! itself is a function of its
args plus os.name and the current working directory. open!
shells out and never throws; errors land in the returned result map.
Shell out to the host OS opener so Vis can hand a URL or local file
path off to the user's preferred external browser/viewer.
Responsibilities, in order:
1. Classify the candidate target into a whitelisted scheme keyword:
`:http`, `:https`, `:file`, `:rel`, or `:rejected`.
2. Resolve the target to a host-friendly form. Relative paths are
anchored at the current working directory and re-checked for
`..` traversal. Returns nil when the path escapes.
3. Build the OS-appropriate command vector
(`open` / `xdg-open` / `cmd /c start`) for `ProcessBuilder`.
4. Spawn it with stdio redirected to /dev/null so a chatty opener
cannot corrupt terminal output.
Pure-ish: every step except `open!` itself is a function of its
args plus `os.name` and the current working directory. `open!`
shells out and never throws; errors land in the returned result map.(classify-scheme s)Return one of :http, :https, :file, :rel, or :rejected
for s. :rel covers anything without an explicit scheme, like
src/foo.clj or ./diagram.png.
Return one of `:http`, `:https`, `:file`, `:rel`, or `:rejected` for `s`. `:rel` covers anything without an explicit scheme, like `src/foo.clj` or `./diagram.png`.
(open! s)Open s via the host OS opener. Never throws.
Returns: {:status :ok | :rejected-scheme | :path-escape | :no-opener | :spawn-failed :command argv-vec | nil :scheme keyword | nil :target resolved-target | nil :error nil | error-string}
Open `s` via the host OS opener. Never throws.
Returns:
{:status :ok | :rejected-scheme | :path-escape | :no-opener | :spawn-failed
:command argv-vec | nil
:scheme keyword | nil
:target resolved-target | nil
:error nil | error-string}(open-command target)Vec of process args for the host OS. Pure modulo os-name.
Returns nil for unsupported platforms.
The Linux branch starts with xdg-open; the caller is responsible
for falling back through the chain (gio open, kde-open,
gnome-open) when spawn fails.
Vec of process args for the host OS. Pure modulo `os-name`. Returns nil for unsupported platforms. The Linux branch starts with `xdg-open`; the caller is responsible for falling back through the chain (`gio open`, `kde-open`, `gnome-open`) when spawn fails.
(open-file-in-editor! s)Open local file target s in a GUI editor when possible, preserving
#Lline anchors for editor CLIs. Falls back to open! for missing
editors, non-local targets, rejected paths, and unsupported shapes.
Never throws.
Open local file target `s` in a GUI editor when possible, preserving `#Lline` anchors for editor CLIs. Falls back to `open!` for missing editors, non-local targets, rejected paths, and unsupported shapes. Never throws.
(os-name)Lower-cased os.name system property. Indirected so tests can
with-redefs it.
Lower-cased `os.name` system property. Indirected so tests can `with-redefs` it.
(safe-target s)Resolve s to a host-friendly opener target. Returns:
{:scheme :http|:https|:file|:rel :target "<absolute path or full URL>" :line N | nil}
or nil when the input is rejected (bad scheme, blank, .. escape).
Resolve `s` to a host-friendly opener target. Returns:
{:scheme :http|:https|:file|:rel
:target "<absolute path or full URL>"
:line N | nil}
or nil when the input is rejected (bad scheme, blank, `..` escape).cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |