Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add browsers.osOpen #12901

Merged
merged 3 commits into from
Feb 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
- introduced new procs in `tables.nim`: `OrderedTable.pop`, `CountTable.del`,
`CountTable.pop`, `Table.pop`
- To `strtabs.nim`, added `StringTable.clear` overload that reuses the existing mode.
- Added `browsers.osOpen` const alias for the operating system specific *"open"* command.
- Added `sugar.outplace` for turning in-place algorithms like `sort` and `shuffle` into
operations that work on a copy of the data and return the mutated copy. As the existing
`sorted` does.
Expand Down
11 changes: 8 additions & 3 deletions lib/pure/browsers.nim
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ when defined(windows):
else:
import os, osproc

const osOpenCmd* =
when defined(macos) or defined(windows): "open" else: "xdg-open" ## \
## Alias for the operating system specific *"open"* command,
## ``"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.
##
Expand All @@ -29,14 +34,14 @@ proc openDefaultBrowser*(url: string) =
##
## This proc doesn't raise an exception on error, beware.
when defined(windows):
var o = newWideCString("open")
var o = newWideCString(osOpenCmd)
var u = newWideCString(url)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hm, windows is also using "open" here?

Copy link
Collaborator Author

@juancarlospaco juancarlospaco Dec 16, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is an API Call I think, not a console command. I am not a Windows expert tho.

Copy link
Collaborator Author

@juancarlospaco juancarlospaco Dec 16, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The documentation comment there confirms that IS an API Call, yep. 🙂

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it is. shellExecuteW executes a command.

discard shellExecuteW(0'i32, o, u, nil, nil, SW_SHOWNORMAL)
elif defined(macosx):
discard execShellCmd("open " & quoteShell(url))
discard execShellCmd(osOpenCmd & " " & quoteShell(url))
else:
var u = quoteShell(url)
if execShellCmd("xdg-open " & u) == 0: return
if execShellCmd(osOpenCmd & " " & u) == 0: return
for b in getEnv("BROWSER").string.split(PathSep):
try:
# we use ``startProcess`` here because we don't want to block!
Expand Down