Liking cljdoc? Tell your friends :D

com.blockether.vis.internal.external-opener

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.

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.
raw docstring

classify-schemeclj

(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`.
sourceraw docstring

open!clj

(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}
sourceraw docstring

open-commandsclj

(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.
sourceraw docstring

open-file-in-editor!clj

(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.
sourceraw docstring

open-local!clj

(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.
sourceraw docstring

os-nameclj

(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.
sourceraw docstring

safe-targetclj

(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).
sourceraw docstring

wsl?clj

(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.
sourceraw docstring

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
←Move to previous article
→Move to next article
Ctrl+/Jump to the search field
× close