Add browsers.openDefaultBrowser without URL, implements IETF RFC-6694 Section-3 (#13835)
This commit is contained in:
parent
bc37668c5a
commit
9599757068
2 changed files with 40 additions and 14 deletions
|
|
@ -123,6 +123,8 @@ echo f
|
||||||
retrieving the verified certificate chain of the peer we are connected to
|
retrieving the verified certificate chain of the peer we are connected to
|
||||||
through an SSL-wrapped `Socket`/`AsyncSocket`.
|
through an SSL-wrapped `Socket`/`AsyncSocket`.
|
||||||
- Added `distinctBase` overload for values: `assert 12.MyInt.distinctBase == 12`
|
- Added `distinctBase` overload for values: `assert 12.MyInt.distinctBase == 12`
|
||||||
|
- Added `browsers.openDefaultBrowser` without URL, implements IETF RFC-6694 Section-3.
|
||||||
|
|
||||||
|
|
||||||
## Library changes
|
## Library changes
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@
|
||||||
## Unstable API.
|
## Unstable API.
|
||||||
|
|
||||||
import strutils
|
import strutils
|
||||||
|
include "system/inclrtl"
|
||||||
|
|
||||||
when defined(windows):
|
when defined(windows):
|
||||||
import winlean
|
import winlean
|
||||||
|
|
@ -24,20 +25,8 @@ const osOpenCmd* =
|
||||||
## Alias for the operating system specific *"open"* command,
|
## Alias for the operating system specific *"open"* command,
|
||||||
## ``"open"`` on MacOS and Windows, ``"xdg-open"`` on Linux, BSD, etc.
|
## ``"open"`` on MacOS and Windows, ``"xdg-open"`` on Linux, BSD, etc.
|
||||||
|
|
||||||
proc openDefaultBrowser*(url: string) =
|
|
||||||
## Opens `url` with the user's default browser. This does not block.
|
template openDefaultBrowserImpl(url: string) =
|
||||||
## The URL must not be empty string.
|
|
||||||
##
|
|
||||||
## Under Windows, ``ShellExecute`` is used. Under Mac OS X the ``open``
|
|
||||||
## command is used. Under Unix, it is checked if ``xdg-open`` exists and
|
|
||||||
## used if it does. Otherwise the environment variable ``BROWSER`` is
|
|
||||||
## used to determine the default browser to use.
|
|
||||||
##
|
|
||||||
## This proc doesn't raise an exception on error, beware.
|
|
||||||
##
|
|
||||||
## .. code-block:: nim
|
|
||||||
## block: openDefaultBrowser("https://nim-lang.org")
|
|
||||||
doAssert url.len > 0, "URL must not be empty string"
|
|
||||||
when defined(windows):
|
when defined(windows):
|
||||||
var o = newWideCString(osOpenCmd)
|
var o = newWideCString(osOpenCmd)
|
||||||
var u = newWideCString(url)
|
var u = newWideCString(url)
|
||||||
|
|
@ -54,3 +43,38 @@ proc openDefaultBrowser*(url: string) =
|
||||||
return
|
return
|
||||||
except OSError:
|
except OSError:
|
||||||
discard
|
discard
|
||||||
|
|
||||||
|
proc openDefaultBrowser*(url: string) =
|
||||||
|
## Opens `url` with the user's default browser. This does not block.
|
||||||
|
## The URL must not be empty string, to open on a blank page see `openDefaultBrowser()`.
|
||||||
|
##
|
||||||
|
## Under Windows, ``ShellExecute`` is used. Under Mac OS X the ``open``
|
||||||
|
## command is used. Under Unix, it is checked if ``xdg-open`` exists and
|
||||||
|
## used if it does. Otherwise the environment variable ``BROWSER`` is
|
||||||
|
## used to determine the default browser to use.
|
||||||
|
##
|
||||||
|
## This proc doesn't raise an exception on error, beware.
|
||||||
|
##
|
||||||
|
## .. code-block:: nim
|
||||||
|
## block: openDefaultBrowser("https://nim-lang.org")
|
||||||
|
doAssert url.len > 0, "URL must not be empty string"
|
||||||
|
openDefaultBrowserImpl(url)
|
||||||
|
|
||||||
|
proc openDefaultBrowser*() {.since: (1, 1).} =
|
||||||
|
## Opens the user's default browser without any `url` (blank page). This does not block.
|
||||||
|
## Implements IETF RFC-6694 Section 3, "about:blank" must be reserved for a blank page.
|
||||||
|
##
|
||||||
|
## Under Windows, ``ShellExecute`` is used. Under Mac OS X the ``open``
|
||||||
|
## command is used. Under Unix, it is checked if ``xdg-open`` exists and
|
||||||
|
## used if it does. Otherwise the environment variable ``BROWSER`` is
|
||||||
|
## used to determine the default browser to use.
|
||||||
|
##
|
||||||
|
## This proc doesn't raise an exception on error, beware.
|
||||||
|
##
|
||||||
|
## **See also:**
|
||||||
|
##
|
||||||
|
## * https://tools.ietf.org/html/rfc6694#section-3
|
||||||
|
##
|
||||||
|
## .. code-block:: nim
|
||||||
|
## block: openDefaultBrowser()
|
||||||
|
openDefaultBrowserImpl("http:about:blank") # See IETF RFC-6694 Section 3.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue