diff --git a/toot/debugger.py b/toot/debugger.py deleted file mode 100644 index ba4aee9..0000000 --- a/toot/debugger.py +++ /dev/null @@ -1,12 +0,0 @@ -from os import getenv - -def initialize_debugger(): - import multiprocessing - - if multiprocessing.current_process().pid > 1: - import debugpy - - debugpy.listen(("0.0.0.0", 9000)) - print("VSCode Debugger is ready to be attached on port 9000, press F5", flush=True) - debugpy.wait_for_client() - print("VSCode Debugger is now attached", flush=True) diff --git a/toot/tui/overlays.py b/toot/tui/overlays.py index b91d30f..606cc5e 100644 --- a/toot/tui/overlays.py +++ b/toot/tui/overlays.py @@ -206,17 +206,32 @@ class Help(urwid.Padding): class Account(urwid.ListBox): """Shows account data and provides various actions""" def __init__(self, account, relationship): - actions = list(self.generate_contents(account, relationship)) + self.last_action = None + self.account = account + self.relationship = relationship + self.setup_listbox() + + def setup_listbox(self): + actions = list(self.generate_contents(self.account, self.relationship, self.last_action)) walker = urwid.SimpleListWalker(actions) super().__init__(walker) - def generate_contents(self, account, relationship): - if relationship['requested']: - yield urwid.Text(("light grey", "< Follow request is pending >")) + def generate_contents(self, account, relationship=None, last_action=None): + if self.last_action and not self.last_action.startswith("Confirm"): + yield Button(f"Confirm {self.last_action}", on_press=take_action, user_data=self) + yield Button("Cancel", on_press=cancel_action, user_data=self) else: - yield Button("Unfollow" if relationship['following'] else "Follow") - yield Button("Unmute" if relationship['muting'] else "Mute") - yield Button("Unblock" if relationship['blocking'] else "Block") + if relationship['requested']: + yield urwid.Text(("light grey", "< Follow request is pending >")) + else: + yield Button("Unfollow" if relationship['following'] else "Follow", + on_press=confirm_action, user_data=self) + + yield Button("Unmute" if relationship['muting'] else "Mute", + on_press=confirm_action, user_data=self) + yield Button("Unblock" if relationship['blocking'] else "Block", + on_press=confirm_action, user_data=self) + yield urwid.Divider("─") yield urwid.Divider() yield urwid.Text([('green', f"@{account['acct']}"), f" {account['display_name']}"]) @@ -265,6 +280,36 @@ class Account(urwid.ListBox): yield link("", account["url"]) +def take_action(button: Button, self: Account): + action = button.get_label() + + if action == "Confirm Follow": + pass + elif action == "Confirm Unfollow": + pass + elif action == "Confirm Mute": + pass + elif action == "Confirm Unmute": + pass + elif action == "Confirm Block": + pass + elif action == "Confirm Unblock": + pass + + self.last_action = None + self.setup_listbox() + + +def confirm_action(button: Button, self: Account): + self.last_action = button.get_label() + self.setup_listbox() + + +def cancel_action(button: Button, self: Account): + self.last_action = None + self.setup_listbox() + + def link(text, url): attr_map = {"link": "link_focused"} text = SelectableText([text, ("link", url)])