Skip to content

Instantly share code, notes, and snippets.

@dstd
Created October 17, 2026 23:04
Show Gist options
  • Select an option

  • Save dstd/04d59f47893c1f9f32d70d287be31abc to your computer and use it in GitHub Desktop.

Select an option

Save dstd/04d59f47893c1f9f32d70d287be31abc to your computer and use it in GitHub Desktop.
[mitmproxy] fix of transparency on syntax-highlighted content when `console_palette_transparent: false`
from mitmproxy import ctx
from mitmproxy.tools.console import palettes
_orig_palette = palettes.Palette.palette
def _patched_palette(self, transparent: bool):
lst = []
if transparent:
highback, lowback = None, None
else:
if self.high and self.high.get("background"):
highback = self.high["background"][1]
else:
highback = self.low["background"][1]
lowback = self.low["background"][1]
for i in ["", *self._fields]:
style = i or "text"
if transparent and i == "background":
lst.append(["background", "default", "default"])
continue
v: list[str | None] = [i]
low = list(self.low[style])
if lowback and low[1] == "default":
low[1] = lowback
v.extend(low)
if self.high and style in self.high:
v.append(None)
high: list[str | None] = list(self.high[style])
if highback and high[1] == "default":
high[1] = highback
v.extend(high)
elif highback and self.low[style][1] == "default":
high = [None, low[0], highback]
v.extend(high)
lst.append(tuple(v))
return lst
class FixOpaqueContentview:
def load(self, loader):
palettes.Palette.palette = _patched_palette
ctx.log.info("Patched console palettes to honor opaque bg for unstyled content")
def done(self):
palettes.Palette.palette = _orig_palette
ctx.log.info("Restored original console palettes")
addons = [FixOpaqueContentview()]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment