only allow downgrading color/ascii experience on serial
and collapse ascii/color choice to a single 'rich' toggle
This commit is contained in:
parent
8628cbb0b8
commit
0d267b320e
|
@ -178,7 +178,10 @@ GLOBAL_KEYS = (
|
|||
(_('F1'), _('open help menu')),
|
||||
(_('Control-Z, F2'), _('switch to shell')),
|
||||
(_('Control-L, F3'), _('redraw screen')),
|
||||
(_('Control-T, F4'), _('toggle color on and off')),
|
||||
)
|
||||
|
||||
SERIAL_GLOBAL_HELP_KEYS = (
|
||||
(_('Control-T, F4'), _('toggle rich mode (colour, unicode) on and off')),
|
||||
)
|
||||
|
||||
DRY_RUN_KEYS = (
|
||||
|
@ -194,7 +197,10 @@ class GlobalKeyStretchy(Stretchy):
|
|||
|
||||
def __init__(self, app):
|
||||
rows = []
|
||||
for key, text in GLOBAL_KEYS:
|
||||
keys = GLOBAL_KEYS
|
||||
if app.opts.run_on_serial:
|
||||
keys += SERIAL_GLOBAL_HELP_KEYS
|
||||
for key, text in keys:
|
||||
rows.append(TableRow([Text(_(key)), Text(_(text))]))
|
||||
if app.opts.dry_run:
|
||||
dro = _('(dry-run only)')
|
||||
|
@ -243,12 +249,9 @@ class HelpMenu(WidgetWrap):
|
|||
_("Keyboard shortcuts"), on_press=self._shortcuts)
|
||||
drop_to_shell = menu_item(
|
||||
_("Enter shell"), on_press=self._debug_shell)
|
||||
color = menu_item(
|
||||
_("Toggle color on/off"), on_press=self._toggle_color)
|
||||
buttons = {
|
||||
about,
|
||||
close,
|
||||
color,
|
||||
drop_to_shell,
|
||||
keys,
|
||||
}
|
||||
|
@ -256,6 +259,10 @@ class HelpMenu(WidgetWrap):
|
|||
ssh_help = menu_item(
|
||||
_("Help on SSH access"), on_press=self._ssh_help)
|
||||
buttons.add(ssh_help)
|
||||
if self.parent.app.opts.run_on_serial:
|
||||
rich = menu_item(
|
||||
_("Toggle rich mode"), on_press=self._toggle_rich)
|
||||
buttons.add(rich)
|
||||
local_title, local_doc = parent.app.ui.body.local_help()
|
||||
if local_title is not None:
|
||||
local = menu_item(
|
||||
|
@ -290,10 +297,11 @@ class HelpMenu(WidgetWrap):
|
|||
if self.parent.ssh_password is not None:
|
||||
entries.append(ssh_help)
|
||||
|
||||
entries.extend([
|
||||
hline,
|
||||
color,
|
||||
])
|
||||
if self.parent.app.opts.run_on_serial:
|
||||
entries.extend([
|
||||
hline,
|
||||
rich,
|
||||
])
|
||||
|
||||
rows = [
|
||||
Columns([
|
||||
|
@ -404,8 +412,8 @@ class HelpMenu(WidgetWrap):
|
|||
def _debug_shell(self, sender):
|
||||
self.parent.app.debug_shell()
|
||||
|
||||
def _toggle_color(self, sender):
|
||||
self.parent.app.toggle_color()
|
||||
def _toggle_rich(self, sender):
|
||||
self.parent.app.toggle_rich()
|
||||
|
||||
def _show_errors(self, sender):
|
||||
self._show_overlay(ErrorReportListStretchy(self.parent.app))
|
||||
|
|
|
@ -112,7 +112,7 @@ urwid_8_names = (
|
|||
)
|
||||
|
||||
|
||||
def make_palette(colors, styles, ascii):
|
||||
def make_palette(colors, styles):
|
||||
"""Return a palette to be passed to MainLoop.
|
||||
|
||||
colors is a list of exactly 8 tuples (name, (r, g, b))
|
||||
|
@ -133,16 +133,6 @@ def make_palette(colors, styles, ascii):
|
|||
urwid_palette = []
|
||||
for name, fg, bg in styles:
|
||||
urwid_fg, urwid_bg = urwid_name[fg], urwid_name[bg]
|
||||
if ascii:
|
||||
# 24bit grey on colored background looks good
|
||||
# but in 16 colors it's unreadable
|
||||
# hence add more contrast
|
||||
if urwid_bg != 'black':
|
||||
urwid_fg = 'black'
|
||||
# Only frame_button doesn't match above rule
|
||||
# fix it to be brown-on-black black-on-brown
|
||||
if name == 'frame_button focus':
|
||||
urwid_fg, urwid_bg = 'brown', 'black'
|
||||
urwid_palette.append((name, urwid_fg, urwid_bg))
|
||||
|
||||
return urwid_palette
|
||||
|
@ -348,8 +338,10 @@ class Application:
|
|||
if not opts.dry_run:
|
||||
open('/run/casper-no-prompt', 'w').close()
|
||||
|
||||
self.is_color = False
|
||||
self.color_palette = make_palette(self.COLORS, self.STYLES, opts.ascii)
|
||||
# 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.color_palette = make_palette(self.COLORS, self.STYLES)
|
||||
|
||||
self.is_linux_tty = is_linux_tty()
|
||||
|
||||
|
@ -557,13 +549,16 @@ class Application:
|
|||
|
||||
self.aio_loop.call_later(0.06, _run_script)
|
||||
|
||||
def toggle_color(self):
|
||||
if self.is_color:
|
||||
def toggle_rich(self):
|
||||
if self.rich_mode:
|
||||
urwid.util.set_encoding('ascii')
|
||||
new_palette = self.STYLES_MONO
|
||||
self.is_color = False
|
||||
self.rich_mode = False
|
||||
else:
|
||||
urwid.util.set_encoding('utf-8')
|
||||
new_palette = self.color_palette
|
||||
self.is_color = True
|
||||
self.rich_mode = True
|
||||
urwid.CanvasCache.clear()
|
||||
self.urwid_loop.screen.register_palette(new_palette)
|
||||
self.urwid_loop.screen.clear()
|
||||
|
||||
|
@ -572,8 +567,8 @@ class Application:
|
|||
self.exit()
|
||||
elif key == 'f3':
|
||||
self.urwid_loop.screen.clear()
|
||||
elif key in ['ctrl t', 'f4']:
|
||||
self.toggle_color()
|
||||
elif self.opts.run_on_serial and key in ['ctrl t', 'f4']:
|
||||
self.toggle_rich()
|
||||
|
||||
def start_controllers(self):
|
||||
log.debug("starting controllers")
|
||||
|
@ -655,12 +650,9 @@ class Application:
|
|||
unhandled_input=self.unhandled_input,
|
||||
event_loop=AsyncioEventLoop(loop=self.aio_loop))
|
||||
|
||||
if self.opts.ascii:
|
||||
urwid.util.set_encoding('ascii')
|
||||
|
||||
extend_dec_special_charmap()
|
||||
|
||||
self.toggle_color()
|
||||
self.toggle_rich()
|
||||
|
||||
self.base_model = self.make_model()
|
||||
try:
|
||||
|
|
Loading…
Reference in New Issue