From ce9a130f37c11aa28eccfbe49c95abf95e962d6a Mon Sep 17 00:00:00 2001 From: Michael Hudson-Doyle Date: Tue, 8 Aug 2023 14:07:10 +1200 Subject: [PATCH] make initial setup of rich mode less confusing --- subiquitycore/tui.py | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/subiquitycore/tui.py b/subiquitycore/tui.py index 1671377e..f153339c 100644 --- a/subiquitycore/tui.py +++ b/subiquitycore/tui.py @@ -77,9 +77,7 @@ class TuiApplication(Application): if not opts.dry_run: open("/run/casper-no-prompt", "w").close() - # Set rich_mode to the opposite of what we want, so we can - # call toggle_rich to get the right things set up. - self.rich_mode = opts.run_on_serial + self.rich_mode = None self.urwid_loop = None self.cur_screen = None self.fg_proc = None @@ -256,21 +254,21 @@ class TuiApplication(Application): def set_rich(self, rich): if rich == self.rich_mode: return - self.toggle_rich() - - def toggle_rich(self): - if self.rich_mode: - urwid.util.set_encoding("ascii") - new_palette = PALETTE_MONO - self.rich_mode = False - else: + if rich: urwid.util.set_encoding("utf-8") new_palette = PALETTE_COLOR self.rich_mode = True + else: + urwid.util.set_encoding("ascii") + new_palette = PALETTE_MONO + self.rich_mode = False urwid.CanvasCache.clear() self.urwid_loop.screen.register_palette(new_palette) self.urwid_loop.screen.clear() + def toggle_rich(self): + self.set_rich(not self.rich_mode) + def unhandled_input(self, key): if self.opts.dry_run and key == "ctrl x": self.exit() @@ -301,7 +299,7 @@ class TuiApplication(Application): **self.extra_urwid_loop_args(), ) extend_dec_special_charmap() - self.toggle_rich() + self.set_rich(not self.opts.run_on_serial) self.urwid_loop.start() self.select_initial_screen()