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 ordered OS-appropriate command candidates (open, or
xdg-open and its fallbacks, with wslview / explorer.exe
first on WSL).
Spawn each candidate with stdio redirected to /dev/null so a chatty opener cannot corrupt terminal output. A candidate that fails to start or exits non-zero soon after the start passes to the next.
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 ordered OS-appropriate command candidates (`open`, or
`xdg-open` and its fallbacks, with `wslview` / `explorer.exe`
first on WSL).
4. Spawn each candidate with stdio redirected to /dev/null so a chatty
opener cannot corrupt terminal output. A candidate that fails to
start or exits non-zero soon after the start passes to the next.
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-commands target)Ordered candidate argv vectors for target on the host OS. Pure modulo
os-name and wsl?. Returns nil for unsupported platforms.
The caller tries each candidate until one starts and does not fail early.
Unix hosts try xdg-open, then gio open, kde-open and gnome-open.
On WSL, wslview and explorer.exe come first. explorer.exe gets only
URLs, because it cannot read a Linux file path.
Ordered candidate argv vectors for `target` on the host OS. Pure modulo `os-name` and `wsl?`. Returns nil for unsupported platforms. The caller tries each candidate until one starts and does not fail early. Unix hosts try `xdg-open`, then `gio open`, `kde-open` and `gnome-open`. On WSL, `wslview` and `explorer.exe` come first. `explorer.exe` gets only URLs, because it cannot read a Linux file path.
(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.
(open-local! path)Open the LOCAL file at path with the generic OS opener (Preview /
default viewer), WITHOUT the cwd confinement open! applies.
For targets vis itself produced — e.g. the inline-image temp PNGs
plt.show() writes under the system temp dir — never for arbitrary
model-provided links. Returns the same result-map shape as open!.
Never throws.
Open the LOCAL file at `path` with the generic OS opener (Preview / default viewer), WITHOUT the cwd confinement `open!` applies. For targets vis itself produced — e.g. the inline-image temp PNGs `plt.show()` writes under the system temp dir — never for arbitrary model-provided links. Returns the same result-map shape as `open!`. 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).(wsl?)True when the JVM runs inside Windows Subsystem for Linux. There the Linux
openers usually find no browser, so the Windows host must open URLs.
Indirected so tests can with-redefs it.
True when the JVM runs inside Windows Subsystem for Linux. There the Linux openers usually find no browser, so the Windows host must open URLs. Indirected so tests can `with-redefs` it.
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 |