diff options
-rw-r--r-- | libmproxy/cmdline.py | 2 | ||||
-rw-r--r-- | libmproxy/console/__init__.py | 22 | ||||
-rw-r--r-- | libmproxy/console/help.py | 22 | ||||
-rw-r--r-- | libmproxy/console/options.py | 13 | ||||
-rw-r--r-- | libmproxy/console/palettepicker.py | 59 | ||||
-rw-r--r-- | libmproxy/console/palettes.py | 1 | ||||
-rw-r--r-- | libmproxy/console/select.py | 15 |
7 files changed, 120 insertions, 14 deletions
diff --git a/libmproxy/cmdline.py b/libmproxy/cmdline.py index 28aa3ea6..51ecea15 100644 --- a/libmproxy/cmdline.py +++ b/libmproxy/cmdline.py @@ -575,7 +575,7 @@ def mitmproxy(): ) common_options(parser) parser.add_argument( - "--palette", type=str, default="dark", + "--palette", type=str, default=palettes.DEFAULT, action="store", dest="palette", choices=sorted(palettes.palettes.keys()), help="Select color palette: " + ", ".join(palettes.palettes.keys()) diff --git a/libmproxy/console/__init__.py b/libmproxy/console/__init__.py index 2421aa6b..1fdf503a 100644 --- a/libmproxy/console/__init__.py +++ b/libmproxy/console/__init__.py @@ -16,7 +16,7 @@ import weakref from .. import controller, flow, script from . import flowlist, flowview, help, window, signals, options -from . import grideditor, palettes, contentview, statusbar +from . import grideditor, palettes, contentview, statusbar, palettepicker EVENTLOG_SIZE = 500 @@ -157,7 +157,6 @@ class ConsoleMaster(flow.FlowMaster): self.setheaders.add(*i) self.flow_list_walker = None - self.set_palette(options.palette) r = self.set_intercept(options.intercept) if r: @@ -183,6 +182,7 @@ class ConsoleMaster(flow.FlowMaster): self.rheaders = options.rheaders self.nopop = options.nopop self.showhost = options.showhost + self.palette = options.palette self.eventlog = options.eventlog self.eventlist = urwid.SimpleListWalker([]) @@ -391,7 +391,11 @@ class ConsoleMaster(flow.FlowMaster): os.unlink(name) def set_palette(self, name): - self.palette = palettes.palettes[name] + self.palette = name + self.ui.register_palette( + palettes.palettes[name].palette() + ) + self.ui.clear() def ticker(self, *userdata): changed = self.tick(self.masterq, timeout=0) @@ -403,7 +407,7 @@ class ConsoleMaster(flow.FlowMaster): def run(self): self.ui = urwid.raw_display.Screen() self.ui.set_terminal_properties(256) - self.ui.register_palette(self.palette.palette()) + self.set_palette(self.palette) self.flow_list_walker = flowlist.FlowListWalker(self, self.state) self.loop = urwid.MainLoop( urwid.SolidFill("x"), @@ -475,6 +479,16 @@ class ConsoleMaster(flow.FlowMaster): options.help_context, ) + def view_palette_picker(self): + signals.push_view_state.send(self) + self.loop.widget = window.Window( + self, + palettepicker.PalettePicker(self), + None, + statusbar.StatusBar(self, palettepicker.footer), + palettepicker.help_context, + ) + def view_grideditor(self, ge): signals.push_view_state.send(self) self.loop.widget = window.Window( diff --git a/libmproxy/console/help.py b/libmproxy/console/help.py index 0da29907..44195798 100644 --- a/libmproxy/console/help.py +++ b/libmproxy/console/help.py @@ -103,3 +103,25 @@ class HelpView(urwid.ListBox): elif key == "?": key = None return urwid.ListBox.keypress(self, size, key) + + +class PalettePicker(urwid.WidgetWrap): + def __init__(self, master): + self.master = master + self.lb = select.Select( + [ + select.Heading("Low"), + select.Option( + "One Two", + "O", + ), + ] + ) + title = urwid.Text("Palettes") + title = urwid.Padding(title, align="left", width=("relative", 100)) + title = urwid.AttrWrap(title, "heading") + self._w = urwid.Frame( + self.lb, + header = title + ) + diff --git a/libmproxy/console/options.py b/libmproxy/console/options.py index 27e01468..23774dc3 100644 --- a/libmproxy/console/options.py +++ b/libmproxy/console/options.py @@ -58,6 +58,12 @@ class Options(urwid.WidgetWrap): self.default_displaymode ), select.Option( + "Palette", + "P", + lambda: False, + self.palette + ), + select.Option( "Show Host", "w", lambda: master.showhost, @@ -117,9 +123,9 @@ class Options(urwid.WidgetWrap): ), ] ) - title = urwid.Text("select.Options") + title = urwid.Text("Options") title = urwid.Padding(title, align="left", width=("relative", 100)) - title = urwid.AttrWrap(title, "select.Heading") + title = urwid.AttrWrap(title, "heading") self._w = urwid.Frame( self.lb, header = title @@ -259,3 +265,6 @@ class Options(urwid.WidgetWrap): text = self.master.stickycookie_txt, callback = self.master.set_stickycookie ) + + def palette(self): + self.master.view_palette_picker() diff --git a/libmproxy/console/palettepicker.py b/libmproxy/console/palettepicker.py new file mode 100644 index 00000000..0062d9ae --- /dev/null +++ b/libmproxy/console/palettepicker.py @@ -0,0 +1,59 @@ +import urwid + +from . import select, common, palettes + +footer = [ + ('heading_key', "enter/space"), ":select", +] + +def _mkhelp(): + text = [] + keys = [ + ("enter/space", "select"), + ] + text.extend(common.format_keyvals(keys, key="key", val="text", indent=4)) + return text +help_context = _mkhelp() + + +class PalettePicker(urwid.WidgetWrap): + def __init__(self, master): + self.master = master + low, high = [], [] + for k, v in palettes.palettes.items(): + if v.high: + high.append(k) + else: + low.append(k) + high.sort() + low.sort() + + options = [ + select.Heading("High Colour") + ] + + def mkopt(name): + return select.Option( + i, + None, + None, + lambda: self.select(name) + ) + + for i in high: + options.append(mkopt(i)) + options.append(select.Heading("Low Colour")) + for i in low: + options.append(mkopt(i)) + + self.lb = select.Select(options) + title = urwid.Text("Palettes") + title = urwid.Padding(title, align="left", width=("relative", 100)) + title = urwid.AttrWrap(title, "heading") + self._w = urwid.Frame( + self.lb, + header = title + ) + + def select(self, name): + self.master.set_palette(name) diff --git a/libmproxy/console/palettes.py b/libmproxy/console/palettes.py index 3e6ce21f..a6ad3f45 100644 --- a/libmproxy/console/palettes.py +++ b/libmproxy/console/palettes.py @@ -279,6 +279,7 @@ class SolarizedDark(LowDark): ) +DEFAULT = "dark" palettes = { "lowlight": LowLight(), "lowdark": LowDark(), diff --git a/libmproxy/console/select.py b/libmproxy/console/select.py index 411fc179..61ee50e4 100644 --- a/libmproxy/console/select.py +++ b/libmproxy/console/select.py @@ -15,12 +15,13 @@ class _OptionWidget(urwid.WidgetWrap): keyattr = "option_selected_key" elif active: textattr = "option_active" - text = common.highlight_key( - text, - shortcut, - textattr = textattr, - keyattr = keyattr - ) + if shortcut: + text = common.highlight_key( + text, + shortcut, + textattr = textattr, + keyattr = keyattr + ) opt = urwid.Text(text, align="left") opt = urwid.AttrWrap(opt, textattr) opt = urwid.Padding(opt, align = "center", width = 40) @@ -89,7 +90,7 @@ class Select(urwid.ListBox): self.options = options self.keymap = {} for i in options: - if hasattr(i, "shortcut"): + if hasattr(i, "shortcut") and i.shortcut: if i.shortcut in self.keymap: raise ValueError("Duplicate shortcut key: %s"%i.shortcut) self.keymap[i.shortcut] = i |