From 8c3cec1aef408d6f2e027703f36537a9aafec268 Mon Sep 17 00:00:00 2001 From: Daniel Schwarz Date: Fri, 23 Jun 2023 18:16:14 -0400 Subject: [PATCH] --no-color now works for tui mode --- toot/tui/app.py | 12 +++++++++--- toot/tui/constants.py | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 3 deletions(-) diff --git a/toot/tui/app.py b/toot/tui/app.py index 73e5b35..d713548 100644 --- a/toot/tui/app.py +++ b/toot/tui/app.py @@ -8,7 +8,7 @@ from toot.console import get_default_visibility from toot.exceptions import ApiError from .compose import StatusComposer -from .constants import PALETTE +from .constants import PALETTE, MONO_PALETTE from .entities import Status from .overlays import ExceptionStackTrace, GotoMenu, Help, StatusSource, StatusLinks, StatusZoom from .overlays import StatusDeleteConfirmation, Account @@ -78,9 +78,10 @@ class TUI(urwid.Frame): """Factory method, sets up TUI and an event loop.""" tui = cls(app, user, args) + loop = urwid.MainLoop( tui, - palette=PALETTE, + palette=MONO_PALETTE if args.no_color else PALETTE, event_loop=urwid.AsyncioEventLoop(), unhandled_input=tui.unhandled_input, ) @@ -98,6 +99,12 @@ class TUI(urwid.Frame): self.executor = ThreadPoolExecutor(max_workers=1) self.timeline_generator = api.home_timeline_generator(app, user, limit=40) + self.screen = urwid.raw_display.Screen() + + if args.no_color: + self.screen.set_terminal_properties(1) + self.screen.reset_default_terminal_palette() + # Show intro screen while toots are being loaded self.body = self.build_intro() self.header = Header(app, user) @@ -111,7 +118,6 @@ class TUI(urwid.Frame): self.overlay = None self.exception = None self.can_translate = False - self.screen = urwid.raw_display.Screen() self.account = None super().__init__(self.body, header=self.header, footer=self.footer) diff --git a/toot/tui/constants.py b/toot/tui/constants.py index e866e34..cd4f508 100644 --- a/toot/tui/constants.py +++ b/toot/tui/constants.py @@ -40,6 +40,47 @@ PALETTE = [ ('white_bold', 'white,bold', '') ] +MONO_PALETTE = [ + # Components + ('button', 'white', 'black'), + ('button_focused', 'black', 'white'), + ('columns_divider', 'white', 'black'), + ('content_warning', 'white', 'black'), + ('editbox', 'white', 'black'), + ('editbox_focused', 'black', 'white'), + ('footer_message', 'white', 'black'), + ('footer_message_error', 'white,bold', 'black'), + ('footer_status', 'black', 'white'), + ('footer_status_bold', 'black,bold', 'white'), + ('header', 'black', 'white'), + ('header_bold', 'black,bold', 'white'), + ('intro_bigtext', 'white', 'black'), + ('intro_smalltext', 'white', 'black'), + ('poll_bar', 'black', 'white'), + + # Functional + ('hashtag', 'white,bold', 'black'), + ('followed_hashtag', 'white,bold', 'black'), + ('link', ',italics', 'black'), + ('link_focused', ',bold,italics', 'black'), + + # Colors + ('bold', ',bold', 'black'), + ('blue', 'white', 'black'), + ('blue_bold', 'white, bold', 'black'), + ('blue_selected', 'white, bold', 'black'), + ('cyan', 'white', 'black'), + ('cyan_bold', 'white,bold', 'black'), + ('gray', 'white', 'black'), + ('green', 'white', 'black'), + ('green_selected', 'black', 'white'), + ('yellow', 'white', 'black'), + ('yellow_bold', 'white,bold', 'black'), + ('red', 'white', 'black'), + ('warning', 'white,bold', 'black'), + ('white_bold', 'white,bold', 'black') +] + VISIBILITY_OPTIONS = [ ("public", "Public", "Post to public timelines"), ("unlisted", "Unlisted", "Do not post to public timelines"),