Merge pull request #1757 from mwhudson/persist-rich-mode
persist rich mode across updates
This commit is contained in:
commit
bdde2c142f
|
@ -15,6 +15,7 @@
|
||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
import inspect
|
import inspect
|
||||||
|
import json
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import signal
|
import signal
|
||||||
|
@ -77,9 +78,7 @@ class TuiApplication(Application):
|
||||||
if not opts.dry_run:
|
if not opts.dry_run:
|
||||||
open("/run/casper-no-prompt", "w").close()
|
open("/run/casper-no-prompt", "w").close()
|
||||||
|
|
||||||
# Set rich_mode to the opposite of what we want, so we can
|
self.rich_mode = None
|
||||||
# call toggle_rich to get the right things set up.
|
|
||||||
self.rich_mode = opts.run_on_serial
|
|
||||||
self.urwid_loop = None
|
self.urwid_loop = None
|
||||||
self.cur_screen = None
|
self.cur_screen = None
|
||||||
self.fg_proc = None
|
self.fg_proc = None
|
||||||
|
@ -256,21 +255,23 @@ class TuiApplication(Application):
|
||||||
def set_rich(self, rich):
|
def set_rich(self, rich):
|
||||||
if rich == self.rich_mode:
|
if rich == self.rich_mode:
|
||||||
return
|
return
|
||||||
self.toggle_rich()
|
if rich:
|
||||||
|
|
||||||
def toggle_rich(self):
|
|
||||||
if self.rich_mode:
|
|
||||||
urwid.util.set_encoding("ascii")
|
|
||||||
new_palette = PALETTE_MONO
|
|
||||||
self.rich_mode = False
|
|
||||||
else:
|
|
||||||
urwid.util.set_encoding("utf-8")
|
urwid.util.set_encoding("utf-8")
|
||||||
new_palette = PALETTE_COLOR
|
new_palette = PALETTE_COLOR
|
||||||
self.rich_mode = True
|
self.rich_mode = True
|
||||||
|
else:
|
||||||
|
urwid.util.set_encoding("ascii")
|
||||||
|
new_palette = PALETTE_MONO
|
||||||
|
self.rich_mode = False
|
||||||
|
with open(self.state_path("rich-mode"), "w") as fp:
|
||||||
|
json.dump(self.rich_mode, fp)
|
||||||
urwid.CanvasCache.clear()
|
urwid.CanvasCache.clear()
|
||||||
self.urwid_loop.screen.register_palette(new_palette)
|
self.urwid_loop.screen.register_palette(new_palette)
|
||||||
self.urwid_loop.screen.clear()
|
self.urwid_loop.screen.clear()
|
||||||
|
|
||||||
|
def toggle_rich(self):
|
||||||
|
self.set_rich(not self.rich_mode)
|
||||||
|
|
||||||
def unhandled_input(self, key):
|
def unhandled_input(self, key):
|
||||||
if self.opts.dry_run and key == "ctrl x":
|
if self.opts.dry_run and key == "ctrl x":
|
||||||
self.exit()
|
self.exit()
|
||||||
|
@ -301,7 +302,14 @@ class TuiApplication(Application):
|
||||||
**self.extra_urwid_loop_args(),
|
**self.extra_urwid_loop_args(),
|
||||||
)
|
)
|
||||||
extend_dec_special_charmap()
|
extend_dec_special_charmap()
|
||||||
self.toggle_rich()
|
try:
|
||||||
|
fp = open(self.state_path("rich-mode"))
|
||||||
|
except FileNotFoundError:
|
||||||
|
initial_rich_mode = not self.opts.run_on_serial
|
||||||
|
else:
|
||||||
|
with fp:
|
||||||
|
initial_rich_mode = json.load(fp)
|
||||||
|
self.set_rich(initial_rich_mode)
|
||||||
self.urwid_loop.start()
|
self.urwid_loop.start()
|
||||||
self.select_initial_screen()
|
self.select_initial_screen()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue