-
-
Notifications
You must be signed in to change notification settings - Fork 257
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
[WIP] Add support for viewing a message in the web browser #698
Changes from all commits
621c1e6
2201e67
4b080fa
fa82f8a
7c0c9fc
584c94e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
import signal | ||
import sys | ||
import time | ||
import webbrowser | ||
from collections import OrderedDict | ||
from functools import partial | ||
from platform import platform | ||
|
@@ -14,8 +15,9 @@ | |
|
||
from zulipterminal.api_types import Composition, Message | ||
from zulipterminal.config.themes import ThemeSpec | ||
from zulipterminal.helper import asynch | ||
from zulipterminal.helper import MACOS, WSL, asynch, suppress_output | ||
from zulipterminal.model import Model | ||
from zulipterminal.server_url import near_message_url | ||
from zulipterminal.ui import Screen, View | ||
from zulipterminal.ui_tools.utils import create_msg_box_list | ||
from zulipterminal.ui_tools.views import ( | ||
|
@@ -364,6 +366,17 @@ def narrow_to_all_mentions(self) -> None: | |
# (nothing currently requires narrowing around a message id) | ||
self._narrow_to(anchor=None, mentioned=True) | ||
|
||
def view_in_browser(self, message: Message) -> None: | ||
# Truncate extra '/' from the server url. | ||
self.url = near_message_url(self.model.server_url[:-1], message) | ||
Comment on lines
+370
to
+371
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's good to use the pre-existing code here, though using |
||
if (not MACOS and not WSL and not os.environ.get('DISPLAY') | ||
and os.environ.get('TERM')): | ||
Comment on lines
+372
to
+373
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Our platform code relies on only one of the platforms being set; we definitely want to improve that handling (see #791), but we should probably be able to rely on the 'other' option being set for now, ie In the more general sense, the webbrowser module can run terminal browsers, so it would be interesting to see how DISPLAY-less systems handle that. Another aspect is whether graphical non-X11 systems set DISPLAY meaningfully? Did you mean to capitalize the commit title? |
||
# Don't try to open web browser if running without a GUI | ||
return | ||
with suppress_output(): | ||
# Suppress anything on stdout or stderr when opening the browser | ||
webbrowser.open(self.url) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we need the |
||
|
||
def deregister_client(self) -> None: | ||
queue_id = self.model.queue_id | ||
self.client.deregister(queue_id, 1.0) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1551,6 +1551,8 @@ def keypress(self, size: urwid_Size, key: str) -> Optional[str]: | |
self.model.controller.show_msg_info(self.message, | ||
self.message_links, | ||
self.time_mentions) | ||
elif is_command_key('VIEW_IN_BROWSER', key): | ||
self.model.controller.view_in_browser(self.message['id']) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If this fails (exception, unsupported environment, etc), could we let the user know? |
||
return key | ||
|
||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change breaks the other use of this method - but no tests break?