From 855b2a15267d18098f785bab08ef3a90b0db7dc6 Mon Sep 17 00:00:00 2001 From: Daniel Schwarz Date: Tue, 14 Mar 2023 19:14:58 -0400 Subject: [PATCH] "toot list" console command added --- toot/commands.py | 8 +++++++- toot/console.py | 9 +++++++++ toot/output.py | 11 +++++++++++ toot/tui/scroll.py | 4 ++-- 4 files changed, 29 insertions(+), 3 deletions(-) diff --git a/toot/commands.py b/toot/commands.py index e105a8d..1e45dc4 100644 --- a/toot/commands.py +++ b/toot/commands.py @@ -1,3 +1,4 @@ + import sys import platform @@ -8,7 +9,7 @@ from toot.auth import login_interactive, login_browser_interactive, create_app_i from toot.exceptions import ApiError, ConsoleError from toot.output import (print_out, print_instance, print_account, print_acct_list, print_search_results, print_timeline, print_notifications, - print_tag_list) + print_tag_list, print_list_list) from toot.tui.utils import parse_datetime from toot.utils import args_get_instance, delete_tmp_status_file, editor_input, multiline_input, EOF_KEY @@ -423,6 +424,11 @@ def tags_followed(app, user, args): print_tag_list(response) +def lists(app, user, args): + response = api.get_lists(app, user) + print_list_list(response) + + def mute(app, user, args): account = find_account(app, user, args.account) api.mute(app, user, account['id']) diff --git a/toot/console.py b/toot/console.py index 0a3acb5..bd26148 100644 --- a/toot/console.py +++ b/toot/console.py @@ -724,6 +724,14 @@ TAG_COMMANDS = [ ), ] +LIST_COMMANDS = [ + Command( + name="lists", + description="List all user lists", + arguments=[], + require_auth=True, + ), +] COMMAND_GROUPS = [ ("Authentication", AUTH_COMMANDS), ("TUI", TUI_COMMANDS), @@ -732,6 +740,7 @@ COMMAND_GROUPS = [ ("Status", STATUS_COMMANDS), ("Accounts", ACCOUNTS_COMMANDS), ("Hashtags", TAG_COMMANDS), + ("Lists", LIST_COMMANDS), ] COMMANDS = list(chain(*[commands for _, commands in COMMAND_GROUPS])) diff --git a/toot/output.py b/toot/output.py index 5be6a92..ba8c54e 100644 --- a/toot/output.py +++ b/toot/output.py @@ -210,6 +210,17 @@ def print_tag_list(tags): print_out("You're not following any hashtags.") +def print_list_list(lists): + if lists: + for list_item in lists: + replies_policy = list_item['replies_policy'] if list_item['replies_policy'] else '' + print_out(f"Name: \"{list_item['title']}\"\t" + + f"ID: {list_item['id']}\t" + + f"Replies policy: {replies_policy}") + else: + print_out("You have no lists defined.") + + def print_search_results(results): accounts = results['accounts'] hashtags = results['hashtags'] diff --git a/toot/tui/scroll.py b/toot/tui/scroll.py index fa2c3bb..7626e84 100644 --- a/toot/tui/scroll.py +++ b/toot/tui/scroll.py @@ -1,7 +1,7 @@ # scroll.py # # Copied from the stig project by rndusr@github -# https://github.com/rndusr/stig +# https://github.com/rndusr/sti # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -423,4 +423,4 @@ class ScrollBar(urwid.WidgetDecoration): ow.set_scrollpos(pos + 1) return True - return False \ No newline at end of file + return False