Skip to content

Commit

Permalink
Add open in browser to URL menu
Browse files Browse the repository at this point in the history
  • Loading branch information
spyder-griffith committed Aug 10, 2022
1 parent 5fa5852 commit f893134
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 8 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from setuptools import setup

NAME = "spydertop"
VERSION = "0.4.3"
VERSION = "0.4.4"

REQUIRES = ["asciimatics", "click", "spyderbat-api", "pyyaml", "pyperclip"]

Expand Down
5 changes: 5 additions & 0 deletions spydertop/screens/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -626,15 +626,20 @@ def on_change():
def button_callback():
date.value = source_time_local
time.value = source_time_local.time()
warning_label.text = (
"Warning: the create time may not have complete data"
)
on_change()

create_time_button = Button(
"Use Nano Agent Create Time: "
+ re.sub(COLOR_REGEX, "", pretty_datetime(source_time_local)),
button_callback,
)
warning_label = Label("")
self.layout.add_widget(Padding(), 1)
self.layout.add_widget(create_time_button, 1)
self.layout.add_widget(warning_label, 1)

last_seen_time = self.cache.get("source", {}).get(
"last_stored_chunk_end_time", None
Expand Down
5 changes: 3 additions & 2 deletions spydertop/screens/help.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def __init__(self, screen: Screen, model: AppModel) -> None:
FuncLabel(
lambda: add_palette(
"""\
${{{label},1}}spydertop 0.4.3 - (C) 2022 Spyderbat
${{{label},1}}spydertop 0.4.4 - (C) 2022 Spyderbat
${{{label},1}}Styled after htop.\
""",
model,
Expand Down Expand Up @@ -88,7 +88,8 @@ def __init__(self, screen: Screen, model: AppModel) -> None:
${{{label},1}} PgUp/Dn:${{{background}}} jump one page up/down
${{{label},1}} Enter:${{{background}}} chow full record details
${{{label},1}}Tab/S-Tab:${{{background}}} move to the next/previous tab
${{{label},1}} u:${{{background}}} copy a link to the console for the record
${{{label},1}} u:${{{background}}} open a link to the console for the record
${{{label},1}} U:${{{background}}} copy a link to the console for the record
${{{label},1}} H:${{{background}}} show/hide threads
${{{label},1}} K:${{{background}}} show/hide kernel threads
${{{label},1}} I:${{{background}}} toggle sorting direction
Expand Down
20 changes: 15 additions & 5 deletions spydertop/screens/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from typing import Any, Dict, List, Optional, Tuple
import urllib
import pyperclip
import webbrowser

from asciimatics.screen import Screen
from asciimatics.widgets import (
Expand Down Expand Up @@ -375,7 +376,8 @@ def process_event(self, event):
" ": self._play,
"C": self._show_setup,
"S": self._show_setup,
"u": self._show_url,
"u": lambda: self._show_url(True),
"U": lambda: self._show_url(False),
"H": lambda: self._config("hide_threads"),
"K": lambda: self._config("hide_kthreads"),
"I": lambda: self._config("sort_ascending"),
Expand Down Expand Up @@ -800,7 +802,7 @@ def set_filter(value):
)
)

def _show_url(self):
def _show_url(self, open_in_browser: bool = False):
"""Show a url menu with full width"""
self._model.log_api(API_LOG_TYPES["navigation"], {"menu": "url"})

Expand All @@ -826,16 +828,24 @@ def _show_url(self):
url = f"https://app.spyderbat.com/app/org/{self._model.config.org}\
/source/{self._model.config.machine}/spyder-console?ids={urllib.parse.quote(row[0][0])}"

# try to open the url in the browser and copy it to the clipboard
browser_label = "URL not opened in browser"
if open_in_browser:
try:
webbrowser.open(url)
browser_label = "URL Opened in browser"
except Exception: # pylint: disable=broad-except
browser_label = "Failed to open URL in browser"
try:
pyperclip.copy(url)
label = "URL copied to the clipboard."
label = "URL copied to the clipboard"
except Exception: # pylint: disable=broad-except
label = "Could not copy URL to the clipboard."
label = "Could not copy URL to the clipboard"

self._scene.add_effect(
NotificationModal(
self.screen,
text=f" {label} \n {url} ",
text=f" {browser_label} \n {label} \n {url} ",
parent=self,
frames=None,
max_width=self.screen.width - 2,
Expand Down

0 comments on commit f893134

Please sign in to comment.