From 7e04ad55c6fd8c3ff651c502dd5af1f1dfa886f1 Mon Sep 17 00:00:00 2001 From: Ivan Habunek Date: Sat, 31 Aug 2019 14:50:31 +0200 Subject: [PATCH] Add links to help overlay --- toot/tui/constants.py | 1 + toot/tui/overlays.py | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/toot/tui/constants.py b/toot/tui/constants.py index 02d4548..10e08cd 100644 --- a/toot/tui/constants.py +++ b/toot/tui/constants.py @@ -18,6 +18,7 @@ PALETTE = [ # Functional ('hashtag', 'light cyan,bold', ''), ('link', ',italics', ''), + ('link_focused', ',italics', 'dark magenta'), # Colors ('bold', ',bold', ''), diff --git a/toot/tui/overlays.py b/toot/tui/overlays.py index 9c3fb86..625f533 100644 --- a/toot/tui/overlays.py +++ b/toot/tui/overlays.py @@ -1,11 +1,12 @@ import json import traceback import urwid +import webbrowser from toot import __version__ from .utils import highlight_keys -from .widgets import Button, EditBox +from .widgets import Button, EditBox, SelectableText class StatusSource(urwid.ListBox): @@ -80,10 +81,15 @@ class Help(urwid.Padding): super().__init__(listbox, left=1, right=1) def generate_contents(self): - def h(text): return highlight_keys(text, "cyan") + def link(text, url): + attr_map = {"link": "link_focused"} + text = SelectableText([text, ("link", url)]) + urwid.connect_signal(text, "click", lambda t: webbrowser.open(url)) + return urwid.AttrMap(text, "", attr_map) + yield urwid.Text(("yellow_bold", "toot {}".format(__version__))) yield urwid.Divider() yield urwid.Text(("bold", "General usage")) @@ -111,3 +117,8 @@ class Help(urwid.Padding): yield urwid.Text(h(" [T] - Show status thread (replies)")) yield urwid.Text(h(" [U] - Show the status data in JSON as received from the server")) yield urwid.Text(h(" [V] - Open status in default browser")) + yield urwid.Divider() + yield urwid.Text(("bold", "Links")) + yield urwid.Divider() + yield link("Documentation: ", "https://toot.readthedocs.io/") + yield link("Project home: ", "https://github.com/ihabunek/toot/")