From e41c84335dc16df2334d737e1c4234c5b29ff603 Mon Sep 17 00:00:00 2001 From: Alexis Hildebrandt Date: Sat, 30 Jun 2012 07:37:38 +0200 Subject: Add --palette option to select color palette --- libmproxy/cmdline.py | 7 +++++++ libmproxy/console/__init__.py | 7 ++++--- libmproxy/console/palettes.py | 19 +++++++++++-------- 3 files changed, 22 insertions(+), 11 deletions(-) diff --git a/libmproxy/cmdline.py b/libmproxy/cmdline.py index 822bebec..93d99779 100644 --- a/libmproxy/cmdline.py +++ b/libmproxy/cmdline.py @@ -15,6 +15,7 @@ import proxy import optparse, re, filt +from console import palettes class ParseReplaceException(Exception): pass @@ -115,6 +116,7 @@ def get_common_options(options): wfile = options.wfile, verbosity = options.verbose, nopop = options.nopop, + palette = options.palette, ) @@ -216,6 +218,11 @@ def common_options(parser): action="store_true", dest="upstream_cert", help="Connect to upstream server to look up certificate details." ) + parser.add_option( + "--palette", type="str", default="dark", + action="store", dest="palette", + help="Select color palette: " + ", ".join(palettes.palettes.keys()) + ) group = optparse.OptionGroup(parser, "Client Replay") group.add_option( diff --git a/libmproxy/console/__init__.py b/libmproxy/console/__init__.py index 2e28b6cf..2fef5beb 100644 --- a/libmproxy/console/__init__.py +++ b/libmproxy/console/__init__.py @@ -335,6 +335,7 @@ class Options(object): "verbosity", "wfile", "nopop", + "palette", ] def __init__(self, **kwargs): for k, v in kwargs.items(): @@ -358,7 +359,7 @@ class ConsoleMaster(flow.FlowMaster): self.replacehooks.add(*i) self.flow_list_walker = None - self.set_palette() + self.set_palette(options.palette) r = self.set_intercept(options.intercept) if r: @@ -504,8 +505,8 @@ class ConsoleMaster(flow.FlowMaster): self.ui.start() os.unlink(name) - def set_palette(self): - self.palette = palettes.dark + def set_palette(self, name): + self.palette = palettes.palettes[name] def run(self): self.currentflow = None diff --git a/libmproxy/console/palettes.py b/libmproxy/console/palettes.py index 39d49dd4..6e0ef7fe 100644 --- a/libmproxy/console/palettes.py +++ b/libmproxy/console/palettes.py @@ -13,9 +13,10 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +palettes = { # Default palette for dark background -dark = [ + 'dark': [ # name, foreground, background, mono, foreground_high, background_high # For details on the meaning of the elements refer to # http://excess.org/urwid/reference.html#Screen-register_palette @@ -61,10 +62,10 @@ dark = [ ('focusfield_error', 'dark red', 'light gray'), ('field_error', 'dark red', 'black'), ('editfield', 'black', 'light cyan'), -] + ], # Palette for light background -light = [ + 'light': [ ('body', 'black', 'dark cyan'), ('foot', 'dark gray', 'default'), ('title', 'white,bold', 'light blue',), @@ -106,13 +107,13 @@ light = [ ('focusfield_error', 'dark red', 'light gray'), ('field_error', 'dark red', 'black'), ('editfield', 'black', 'light cyan'), -] + ], # Palettes for terminals that use the Solarized precision colors # (http://ethanschoonover.com/solarized#the-values) # For dark backgrounds -solarized_dark = [ + 'solarized_dark': [ ('body', 'dark cyan', 'default'), ('foot', 'dark gray', 'default'), ('title', 'white,bold', 'default',), @@ -155,10 +156,10 @@ solarized_dark = [ ('focusfield_error', 'dark red', 'light gray'), ('field_error', 'dark red', 'black'), ('editfield', 'black', 'light gray'), -] + ], # For light backgrounds -solarized_light = [ + 'solarized_light': [ ('body', 'dark cyan', 'default'), ('foot', 'dark gray', 'default'), ('title', 'white,bold', 'light cyan',), @@ -201,4 +202,6 @@ solarized_light = [ ('focusfield_error', 'dark red', 'light gray'), ('field_error', 'dark red', 'black'), ('editfield', 'white', 'light cyan'), -] + ], + +} -- cgit v1.2.3