mirror of
https://github.com/mitmproxy/mitmproxy.git
synced 2024-11-28 15:50:53 +00:00
console: All palettes now explicitly set a background colour
There's a new option --palette-transparent to turn this off if you want to use your own terminal background.
This commit is contained in:
parent
1cb1ee411b
commit
f6a3bd15b3
@ -580,6 +580,11 @@ def mitmproxy():
|
||||
choices=sorted(palettes.palettes.keys()),
|
||||
help="Select color palette: " + ", ".join(palettes.palettes.keys())
|
||||
)
|
||||
parser.add_argument(
|
||||
"--palette-transparent",
|
||||
action="store_true", dest="palette_transparent", default=False,
|
||||
help="Set transparent background for palette."
|
||||
)
|
||||
parser.add_argument(
|
||||
"-e", "--eventlog",
|
||||
action="store_true", dest="eventlog",
|
||||
|
@ -132,6 +132,7 @@ class Options(object):
|
||||
"wfile",
|
||||
"nopop",
|
||||
"palette",
|
||||
"palette_transparent"
|
||||
]
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
@ -183,6 +184,7 @@ class ConsoleMaster(flow.FlowMaster):
|
||||
self.nopop = options.nopop
|
||||
self.showhost = options.showhost
|
||||
self.palette = options.palette
|
||||
self.palette_transparent = options.palette_transparent
|
||||
|
||||
self.eventlog = options.eventlog
|
||||
self.eventlist = urwid.SimpleListWalker([])
|
||||
@ -393,7 +395,7 @@ class ConsoleMaster(flow.FlowMaster):
|
||||
def set_palette(self, name):
|
||||
self.palette = name
|
||||
self.ui.register_palette(
|
||||
palettes.palettes[name].palette()
|
||||
palettes.palettes[name].palette(self.palette_transparent)
|
||||
)
|
||||
self.ui.clear()
|
||||
|
||||
|
@ -1,4 +1,3 @@
|
||||
|
||||
# Low-color themes should ONLY use the standard foreground and background
|
||||
# colours listed here:
|
||||
#
|
||||
@ -6,9 +5,9 @@
|
||||
#
|
||||
|
||||
|
||||
|
||||
class Palette:
|
||||
_fields = [
|
||||
'background',
|
||||
'title',
|
||||
|
||||
# Status bar & heading
|
||||
@ -35,15 +34,33 @@ class Palette:
|
||||
]
|
||||
high = None
|
||||
|
||||
def palette(self):
|
||||
def palette(self, transparent):
|
||||
l = []
|
||||
highback, lowback = None, None
|
||||
if not transparent:
|
||||
if self.high and self.high.get("background"):
|
||||
highback = self.high["background"][1]
|
||||
lowback = self.low["background"][1]
|
||||
|
||||
for i in self._fields:
|
||||
v = [i]
|
||||
v.extend(self.low[i])
|
||||
if self.high and i in self.high:
|
||||
v.append(None)
|
||||
v.extend(self.high[i])
|
||||
l.append(tuple(v))
|
||||
if transparent and i == "background":
|
||||
l.append(["background", "default", "default"])
|
||||
else:
|
||||
v = [i]
|
||||
low = list(self.low[i])
|
||||
if lowback and low[1] == "default":
|
||||
low[1] = lowback
|
||||
v.extend(low)
|
||||
if self.high and i in self.high:
|
||||
v.append(None)
|
||||
high = list(self.high[i])
|
||||
if highback and high[1] == "default":
|
||||
high[1] = highback
|
||||
v.extend(high)
|
||||
elif highback:
|
||||
high = [None, low[0], highback]
|
||||
v.extend(high)
|
||||
l.append(tuple(v))
|
||||
return l
|
||||
|
||||
|
||||
@ -52,6 +69,7 @@ class LowDark(Palette):
|
||||
Low-color dark background
|
||||
"""
|
||||
low = dict(
|
||||
background = ('white', 'black'),
|
||||
title = ('white,bold', 'default'),
|
||||
|
||||
# Status bar & heading
|
||||
@ -110,6 +128,7 @@ class LowLight(Palette):
|
||||
Low-color light background
|
||||
"""
|
||||
low = dict(
|
||||
background = ('black', 'white'),
|
||||
title = ('dark magenta', 'default'),
|
||||
|
||||
# Status bar & heading
|
||||
@ -158,6 +177,7 @@ class LowLight(Palette):
|
||||
|
||||
class Light(LowLight):
|
||||
high = dict(
|
||||
background = ('black', 'g100'),
|
||||
heading = ('g99', '#08f'),
|
||||
heading_key = ('#0ff,bold', '#08f'),
|
||||
heading_inactive = ('g35', 'g85'),
|
||||
@ -171,10 +191,10 @@ sol_base03 = "h234"
|
||||
sol_base02 = "h235"
|
||||
sol_base01 = "h240"
|
||||
sol_base00 = "h241"
|
||||
sol_base0 = "h244"
|
||||
sol_base1 = "h245"
|
||||
sol_base2 = "h254"
|
||||
sol_base3 = "h230"
|
||||
sol_base0 = "h244"
|
||||
sol_base1 = "h245"
|
||||
sol_base2 = "h254"
|
||||
sol_base3 = "h230"
|
||||
sol_yellow = "h136"
|
||||
sol_orange = "h166"
|
||||
sol_red = "h160"
|
||||
@ -183,8 +203,11 @@ sol_violet = "h61"
|
||||
sol_blue = "h33"
|
||||
sol_cyan = "h37"
|
||||
sol_green = "h64"
|
||||
|
||||
|
||||
class SolarizedLight(LowLight):
|
||||
high = dict(
|
||||
background = (sol_base00, sol_base3),
|
||||
title = (sol_cyan, 'default'),
|
||||
text = (sol_base00, 'default'),
|
||||
|
||||
@ -233,6 +256,7 @@ class SolarizedLight(LowLight):
|
||||
|
||||
class SolarizedDark(LowDark):
|
||||
high = dict(
|
||||
background = (sol_base2, sol_base03),
|
||||
title = (sol_blue, 'default'),
|
||||
text = (sol_base1, 'default'),
|
||||
|
||||
|
@ -1,10 +1,15 @@
|
||||
import urwid
|
||||
from . import grideditor, signals, contentview
|
||||
from . import signals
|
||||
|
||||
|
||||
class Window(urwid.Frame):
|
||||
def __init__(self, master, body, header, footer, helpctx):
|
||||
urwid.Frame.__init__(self, body, header=header, footer=footer)
|
||||
urwid.Frame.__init__(
|
||||
self,
|
||||
urwid.AttrWrap(body, "background"),
|
||||
header = urwid.AttrWrap(header, "background") if header else None,
|
||||
footer = urwid.AttrWrap(footer, "background") if footer else None
|
||||
)
|
||||
self.master = master
|
||||
self.helpctx = helpctx
|
||||
signals.focus.connect(self.sig_focus)
|
||||
|
@ -89,6 +89,7 @@ def mitmproxy(): # pragma: nocover
|
||||
proxy_config = process_proxy_options(parser, options)
|
||||
console_options = console.Options(**cmdline.get_common_options(options))
|
||||
console_options.palette = options.palette
|
||||
console_options.palette_transparent = options.palette_transparent
|
||||
console_options.eventlog = options.eventlog
|
||||
console_options.intercept = options.intercept
|
||||
|
||||
|
@ -8,4 +8,6 @@ import libmproxy.console.palettes as palettes
|
||||
class TestPalette:
|
||||
def test_helptext(self):
|
||||
for i in palettes.palettes.values():
|
||||
assert i.palette()
|
||||
assert i.palette(False)
|
||||
for i in palettes.palettes.values():
|
||||
assert i.palette(True)
|
||||
|
Loading…
Reference in New Issue
Block a user