paradoxxxzero / butterfly

A web terminal based on websocket and tornado
http://paradoxxxzero.github.io/2014/02/28/butterfly.html
Other
2.89k stars 314 forks source link

A 'b url' command or similar to open a URL in the browser the terminal is accessed through. #184

Open GrahamDumpleton opened 5 years ago

GrahamDumpleton commented 5 years ago

Is it technically possible to implement a b url command that could communicate over the web socket back to the browser that the terminal is accessed using, and have the browser side code open the supplied URL in a new window/tab of the browser?

If this was available, then one could create a fake script xdg-open and put it in the PATH which actually called b url. That way Python applications that use webbrowser.open(), including the b open command, or any other applications that tries to use a similar approach to open a URL in a browser, would be able to work where the terminal session is actually running on a remote system to the browser.

If you think this is technically possibly and can provide pointers of how it could be integrated, then I can have a go at adding support for it. Thanks.

GrahamDumpleton commented 5 years ago

My guess at what is needed is to add to butterfly/escapes.py an escape of:

@contextmanager
def url():
    sys.stdout.write('\x1bP;URL|')
    yield
    sys.stdout.write('\x1bP')
    sys.stdout.flush()

and then in function:

and one for URL, which runs window.open(url, '_blank'); or similar.

Can then code up butterfly/bin/url.py to use that.

GrahamDumpleton commented 5 years ago

The problem with this is how to do it so as to avoid popup blocker. :-(