Revamp palette specification

- Split low-color and high-color specifications in palettes.
- Split off light, dark, lowlight and lowdark palettes. Lowlight and lowdark
will be the low-color base for most subsequent palettes.
- Add a small script that makes test pattern requests to pathod.
This commit is contained in:
Aldo Cortesi 2015-03-19 18:05:30 +13:00
parent b77e511fca
commit 1d5fcc6e0e
4 changed files with 270 additions and 189 deletions

View File

@ -765,7 +765,7 @@ class ConsoleMaster(flow.FlowMaster):
def run(self): def run(self):
self.ui = urwid.raw_display.Screen() self.ui = urwid.raw_display.Screen()
self.ui.set_terminal_properties(256) self.ui.set_terminal_properties(256)
self.ui.register_palette(self.palette) self.ui.register_palette(self.palette.palette())
self.flow_list_walker = flowlist.FlowListWalker(self, self.state) self.flow_list_walker = flowlist.FlowListWalker(self, self.state)
self.view = None self.view = None
self.statusbar = None self.statusbar = None

View File

@ -1,192 +1,253 @@
# Low-color themes should ONLY use the standard foreground and background
# colours listed here:
#
# http://urwid.org/manual/displayattributes.html
#
class Palette:
_fields = [
'body', 'foot', 'title', 'editline',
# Status bar & heading
'heading', 'heading_key', 'heading_inactive',
# Help
'key', 'head', 'text',
# List and Connections
'method', 'focus',
'code_200', 'code_300', 'code_400', 'code_500', 'code_other',
'error',
'header', 'highlight', 'intercept', 'replay', 'ack',
# Hex view
'offset',
# Grid Editor
'focusfield', 'focusfield_error', 'field_error', 'editfield',
]
high = None
def palette(self):
l = []
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))
return l
class LowDark(Palette):
"""
Low-color dark background
"""
low = dict(
body = ('black', 'dark cyan'),
foot = ('light gray', 'default'),
title = ('white,bold', 'default'),
editline = ('white', 'default'),
# Status bar & heading
heading = ('light gray', 'dark blue'),
heading_key = ('light cyan', 'dark blue'),
heading_inactive = ('white', 'dark gray'),
# Help
key = ('light cyan', 'default'),
head = ('white,bold', 'default'),
text = ('light gray', 'default'),
# List and Connections
method = ('dark cyan', 'default'),
focus = ('yellow', 'default'),
code_200 = ('dark green', 'default'),
code_300 = ('light blue', 'default'),
code_400 = ('light red', 'default'),
code_500 = ('light red', 'default'),
code_other = ('dark red', 'default'),
error = ('light red', 'default'),
header = ('dark cyan', 'default'),
highlight = ('white,bold', 'default'),
intercept = ('brown', 'default'),
replay = ('light green', 'default'),
ack = ('light red', 'default'),
# Hex view
offset = ('dark cyan', 'default'),
# Grid Editor
focusfield = ('black', 'light gray'),
focusfield_error = ('dark red', 'light gray'),
field_error = ('dark red', 'default'),
editfield = ('white', 'default'),
)
class Dark(LowDark):
high = dict(
heading_inactive = ('g58', 'g11'),
intercept = ('#f60', 'default'),
)
class LowLight(Palette):
"""
Low-color light background
"""
low = dict(
body = ('black', 'dark cyan'),
foot = ('dark gray', 'default'),
title = ('dark magenta,bold', 'light blue'),
editline = ('white', 'default'),
# Status bar & heading
heading = ('light gray', 'dark blue'),
heading_key = ('light cyan', 'black'),
heading_inactive = ('black', 'light gray'),
# Help
key = ('dark blue,bold', 'default'),
head = ('black,bold', 'default'),
text = ('dark gray', 'default'),
# List and Connections
method = ('dark cyan', 'default'),
focus = ('black', 'default'),
code_200 = ('dark green', 'default'),
code_300 = ('light blue', 'default'),
code_400 = ('dark red', 'default'),
code_500 = ('dark red', 'default'),
code_other = ('light red', 'default'),
error = ('light red', 'default'),
header = ('dark blue', 'default'),
highlight = ('black,bold', 'default'),
intercept = ('brown', 'default'),
replay = ('dark green', 'default'),
ack = ('dark red', 'default'),
# Hex view
offset = ('dark blue', 'default'),
# Grid Editor
focusfield = ('black', 'light gray'),
focusfield_error = ('dark red', 'light gray'),
field_error = ('dark red', 'black'),
editfield = ('black', 'default'),
)
class Light(LowLight):
pass
palettes = { palettes = {
"lowlight": LowLight(),
"lowdark": LowDark(),
"light": Light(),
"dark": Dark(),
# Default palette for dark background # # For dark backgrounds
'dark': [ # 'solarized_dark': [
# name, foreground, background, mono, foreground_high, background_high # ('body', 'dark cyan', 'default'),
# For details on the meaning of the elements refer to # ('foot', 'dark gray', 'default'),
# http://excess.org/urwid/reference.html#Screen-register_palette # ('title', 'white,bold', 'default',),
# ('editline', 'white', 'default',),
('body', 'black', 'dark cyan'), #
('foot', 'light gray', 'default'), # # Status bar & heading
('title', 'white,bold', 'default',), # ('heading', 'light gray', 'light cyan',),
('editline', 'white', 'default',), # ('heading_key', 'dark blue', 'white',),
# ('heading_inactive', 'light cyan', 'light gray',),
# Status bar & heading #
('heading', 'light gray', 'dark blue', None, 'g85', 'dark blue'), # # Help
('heading_key', 'light cyan', 'dark blue', None, 'light cyan', 'dark blue'), # ('key', 'dark blue', 'default',),
('heading_inactive', 'white', 'dark gray', None, 'g58', 'g11'), # ('head', 'white,underline', 'default'),
# ('text', 'light cyan', 'default'),
# Help #
('key', 'light cyan', 'default'), # # List and Connections
('head', 'white,bold', 'default'), # ('method', 'dark cyan', 'default'),
('text', 'light gray', 'default'), # ('focus', 'white', 'default'),
#
# List and Connections # ('code_200', 'dark green', 'default'),
('method', 'dark cyan', 'default'), # ('code_300', 'light blue', 'default'),
('focus', 'yellow', 'default'), # ('code_400', 'dark red', 'default',),
# ('code_500', 'dark red', 'default'),
('code_200', 'light green', 'default'), # ('code_other', 'light red', 'default'),
('code_300', 'light blue', 'default'), #
('code_400', 'light red', 'default', None, '#f60', 'default'), # ('error', 'light red', 'default'),
('code_500', 'light red', 'default'), #
('code_other', 'dark red', 'default'), # ('header', 'yellow', 'default'),
# ('highlight', 'white', 'default'),
('error', 'light red', 'default'), # ('intercept', 'brown', 'default',),
# ('replay', 'dark green', 'default',),
('header', 'dark cyan', 'default'), # ('ack', 'dark red', 'default'),
('highlight', 'white,bold', 'default'), #
('intercept', 'brown', 'default', None, '#f60', 'default'), # # Hex view
('replay', 'light green', 'default', None, '#0f0', 'default'), # ('offset', 'yellow', 'default'),
('ack', 'light red', 'default'), # ('text', 'light cyan', 'default'),
#
# Hex view # # Grid Editor
('offset', 'dark cyan', 'default'), # ('focusfield', 'white', 'light cyan'),
# ('focusfield_error', 'dark red', 'light gray'),
# Grid Editor # ('field_error', 'dark red', 'black'),
('focusfield', 'black', 'light gray'), # ('editfield', 'black', 'light gray'),
('focusfield_error', 'dark red', 'light gray'), # ],
('field_error', 'dark red', 'black'), #
('editfield', 'black', 'light cyan'), # # For light backgrounds
], # 'solarized_light': [
# ('body', 'dark cyan', 'default'),
# Palette for light background # ('foot', 'dark gray', 'default'),
'light': [ # ('title', 'white,bold', 'light cyan',),
('body', 'black', 'dark cyan'), # ('editline', 'white', 'default',),
('foot', 'dark gray', 'default'), #
('title', 'white,bold', 'light blue',), # # Status bar & heading
('editline', 'white', 'default',), # ('heading', 'light cyan', 'light gray',),
# ('heading_key', 'dark blue', 'white',),
# Status bar & heading # ('heading_inactive', 'white', 'light gray',),
('heading', 'white', 'light gray', None, 'g85', 'dark blue'), #
('heading_key', 'dark blue', 'light gray', None, 'light cyan', 'dark blue'), # # Help
('heading_inactive', 'light gray', 'dark gray', None, 'dark gray', 'dark blue'), # ('key', 'dark blue', 'default',),
# ('head', 'black,underline', 'default'),
# Help # ('text', 'light cyan', 'default'),
('key', 'dark blue,bold', 'default'), #
('head', 'black,bold', 'default'), # # List and Connections
('text', 'dark gray', 'default'), # ('method', 'dark cyan', 'default'),
# ('focus', 'black', 'default'),
# List and Connections #
('method', 'dark cyan', 'default'), # ('code_200', 'dark green', 'default'),
('focus', 'black', 'default'), # ('code_300', 'light blue', 'default'),
# ('code_400', 'dark red', 'default',),
('code_200', 'dark green', 'default'), # ('code_500', 'dark red', 'default'),
('code_300', 'light blue', 'default'), # ('code_other', 'light red', 'default'),
('code_400', 'dark red', 'default', None, '#f60', 'default'), #
('code_500', 'dark red', 'default'), # ('error', 'light red', 'default'),
('code_other', 'light red', 'default'), #
# ('header', 'light cyan', 'default'),
('error', 'light red', 'default'), # ('highlight', 'black,bold', 'default'),
# ('intercept', 'brown', 'default',),
('header', 'dark blue', 'default'), # ('replay', 'dark green', 'default',),
('highlight', 'black,bold', 'default'), # ('ack', 'dark red', 'default'),
('intercept', 'brown', 'default', None, '#f60', 'default'), #
('replay', 'dark green', 'default', None, '#0f0', 'default'), # # Hex view
('ack', 'dark red', 'default'), # ('offset', 'light cyan', 'default'),
# ('text', 'yellow', 'default'),
# Hex view #
('offset', 'dark blue', 'default'), # # Grid Editor
# ('focusfield', 'black', 'light gray'),
# Grid Editor # ('focusfield_error', 'dark red', 'light gray'),
('focusfield', 'black', 'light gray'), # ('field_error', 'dark red', 'black'),
('focusfield_error', 'dark red', 'light gray'), # ('editfield', 'white', 'light cyan'),
('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': [
('body', 'dark cyan', 'default'),
('foot', 'dark gray', 'default'),
('title', 'white,bold', 'default',),
('editline', 'white', 'default',),
# Status bar & heading
('heading', 'light gray', 'light cyan',),
('heading_key', 'dark blue', 'white',),
('heading_inactive', 'light cyan', 'light gray',),
# Help
('key', 'dark blue', 'default',),
('head', 'white,underline', 'default'),
('text', 'light cyan', 'default'),
# List and Connections
('method', 'dark cyan', 'default'),
('focus', 'white', 'default'),
('code_200', 'dark green', 'default'),
('code_300', 'light blue', 'default'),
('code_400', 'dark red', 'default',),
('code_500', 'dark red', 'default'),
('code_other', 'light red', 'default'),
('error', 'light red', 'default'),
('header', 'yellow', 'default'),
('highlight', 'white', 'default'),
('intercept', 'brown', 'default',),
('replay', 'dark green', 'default',),
('ack', 'dark red', 'default'),
# Hex view
('offset', 'yellow', 'default'),
('text', 'light cyan', 'default'),
# Grid Editor
('focusfield', 'white', 'light cyan'),
('focusfield_error', 'dark red', 'light gray'),
('field_error', 'dark red', 'black'),
('editfield', 'black', 'light gray'),
],
# For light backgrounds
'solarized_light': [
('body', 'dark cyan', 'default'),
('foot', 'dark gray', 'default'),
('title', 'white,bold', 'light cyan',),
('editline', 'white', 'default',),
# Status bar & heading
('heading', 'light cyan', 'light gray',),
('heading_key', 'dark blue', 'white',),
('heading_inactive', 'white', 'light gray',),
# Help
('key', 'dark blue', 'default',),
('head', 'black,underline', 'default'),
('text', 'light cyan', 'default'),
# List and Connections
('method', 'dark cyan', 'default'),
('focus', 'black', 'default'),
('code_200', 'dark green', 'default'),
('code_300', 'light blue', 'default'),
('code_400', 'dark red', 'default',),
('code_500', 'dark red', 'default'),
('code_other', 'light red', 'default'),
('error', 'light red', 'default'),
('header', 'light cyan', 'default'),
('highlight', 'black,bold', 'default'),
('intercept', 'brown', 'default',),
('replay', 'dark green', 'default',),
('ack', 'dark red', 'default'),
# Hex view
('offset', 'light cyan', 'default'),
('text', 'yellow', 'default'),
# Grid Editor
('focusfield', 'black', 'light gray'),
('focusfield_error', 'dark red', 'light gray'),
('field_error', 'dark red', 'black'),
('editfield', 'white', 'light cyan'),
],
} }

View File

@ -0,0 +1,11 @@
import os
from nose.plugins.skip import SkipTest
if os.name == "nt":
raise SkipTest("Skipped on Windows.")
import libmproxy.console.palettes as palettes
class TestPalette:
def test_helptext(self):
for i in palettes.palettes.values():
assert i.palette()

9
test/tools/testpatt Executable file
View File

@ -0,0 +1,9 @@
#!/bin/bash
# Generate a test pattern with pathoc
PATHOD=http://localhost:9999
pathoc localhost:8080 "get:'$PATHOD/p/200:p0,1'"
pathoc localhost:8080 "get:'$PATHOD/p/300:p0,1'"
pathoc localhost:8080 "get:'$PATHOD/p/400:p0,1'"
pathoc localhost:8080 "get:'$PATHOD/p/500:p0,1'"
pathoc localhost:8080 "get:'$PATHOD/p/600:p0,1'"