-
Notifications
You must be signed in to change notification settings - Fork 161
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 user available functions to open a URL in a web browser #4272
Comments
Also jupyterviz has this functionality, since I asked @nathancarter to add it and he kindle agreed. Probably francy also has it. I think that both used similar code as the one @fingolfin describes in dot.gi. |
Suggestion: A starting point would be to have OpenURLInBrowser look at the help viewers. Typically, the preferred help viewer would also be the preferred browser for other purposes, and there's already some sometimes-nontrivial code to e.g. bring up a URL in Safari and go to a given anchor. Of course, one needs to pick out a help viewer that can handle urls (or pdfs, if the passed url appears to be a pdf). It would be good to be able to flag a help viewer as for help only (and unsuitable for use by this function). |
It's best to defer opening a file to the operating system, which will use the user's settings for the given file type. The relevant code is just these 7 lines: if ARCH_IS_MAC_OS_X() then
Exec( "open ", filename );
elif ARCH_IS_WINDOWS() then
Exec( "start ", filename );
elif ARCH_IS_UNIX() then
Exec( "xdg-open ", filename );
fi; Note that since writing them, I now realize that there should probably be another entry in there for WSL, which should use the |
I agree with this general aim. Should wrap the filenames in ', but that's a minor issue. Note that we are going to start distributing xdg-open with our cygwin install, so you won't need the ARCH_IS_WINDOWS() branch. I've found the best thing to use in WSL is the slightly crazy looking: Exec(Concatenation("explorer.exe "$(wslpath -a -w "",Filename(dir, "/output/index.html"), "")"")); And GAP now has an ARCH_IS_WSL() ( #4249 ) |
@nathancarter that sounds nice in theory, but is not in practice, at least on macOS, as (BTW, we could probably "fix" this on macOS by querying for the name of the user's default browser, see e.g. here and then using the Moreover, some users (e.g. me) genuinely prefer to use different browsers for different things (admittedly this is a niche audience). |
I do not know if this https://apple.stackexchange.com/a/194873 may help. Though I do not know how to recover default's browser from @fingolfin 's comment... |
@pedritomelenas, GAP does something pretty similar to the method in the post you link if you set the default help browser to "safari" or similar. (But "browser" uses open.) To be a little clearer about the problem: the open command supports anchors for remote URLs starting with http: or https:, but it does not support for local URLs starting with file: (such as the ones GAP typically uses for help). Btw, a similar problem holds for opening URLs from the API. |
@pedritomelenas I gave a link with AppleScript code to recover the default browser, though? Based on that, here is a complete AppleScript snippet which opens a given URL with anchor in the user's default browser, with the anchor being honored; one could adapt that for use in GAP (replacing the current, much shorter AppleScript snippet, which however does not handle anchors right):
|
So @fingolfin, you mean something like this for macos
It works on my mac. However, it opens a window prompting for the browser. I was not able to make it work for pdfs though; it asks for Preview.App and then shows an error. |
Well, I tried a more simpler approach based on https://apple.stackexchange.com/a/194873, and found that
just works on macOS 10.15.7 (Catalina) for examples with html, png, pdf, and even with html#anchor. Just try I changed the default browser to chrome, and it worked. |
I was able to make this work for local files, but not for https. This seems to work for https urls.
and
in combination with wsl-open works for all files and urls. |
We already go through a lot of effort to set
HELP_VIEWER_INFO.browser
to a function like this for HTML; but I know that the very least, the numericalsgps package by @pedritomelenas and friends needs such functionality, see https://github.com/gap-packages/numericalsgps/blob/231329432a3e6e651cfc8e719271ccb23ae973a7/gap/dot.gi#L62-L68 -- but I also think other uses might exist.So, let's expose it through a dedicated function, say
OpenURLInBrowser(url)
. Shouldn't be too hard (most work is a writing a reference manual entry for it)One could do the same for PDFs, too, I guess...
The text was updated successfully, but these errors were encountered: