aboutsummaryrefslogtreecommitdiffstats
path: root/libmproxy
diff options
context:
space:
mode:
authorAldo Cortesi <aldo@nullcube.com>2012-02-11 18:23:07 +1300
committerAldo Cortesi <aldo@nullcube.com>2012-02-11 18:23:07 +1300
commitf25156a6377b89ea34899fb61a94694361a7e511 (patch)
treebae33713d3a53048c26c9909d0b0e87448ac906e /libmproxy
parent3e70fa8d581c845323b9bbe2ec75cf2c8df7a49f (diff)
downloadmitmproxy-f25156a6377b89ea34899fb61a94694361a7e511.tar.gz
mitmproxy-f25156a6377b89ea34899fb61a94694361a7e511.tar.bz2
mitmproxy-f25156a6377b89ea34899fb61a94694361a7e511.zip
Better formatting for headers, help and other key-value displays.
We now use proper Columns, rather than laying it out manually.
Diffstat (limited to 'libmproxy')
-rw-r--r--libmproxy/console/common.py34
-rw-r--r--libmproxy/console/connview.py35
-rw-r--r--libmproxy/console/help.py32
-rw-r--r--libmproxy/console/kveditor.py3
4 files changed, 50 insertions, 54 deletions
diff --git a/libmproxy/console/common.py b/libmproxy/console/common.py
index 658c94b1..28cf20cb 100644
--- a/libmproxy/console/common.py
+++ b/libmproxy/console/common.py
@@ -27,7 +27,8 @@ def highlight_key(s, k):
return l
-def format_keyvals(lst, key="key", val="text", space=5, indent=0):
+KEY_MAX = 30
+def format_keyvals(lst, key="key", val="text", indent=0):
"""
Format a list of (key, value) tuples.
@@ -37,24 +38,25 @@ def format_keyvals(lst, key="key", val="text", space=5, indent=0):
"""
ret = []
if lst:
- pad = max(len(i[0]) for i in lst if i and i[0]) + space
+ maxk = min(max(len(i[0]) for i in lst if i and i[0]), KEY_MAX)
for i, kv in enumerate(lst):
if kv is None:
- ret.extend("")
- elif kv[0] is None:
- ret.append(" "*(pad + indent*2))
- ret.extend(kv[1])
+ ret.append(Text(""))
else:
- ret.extend(
- [
- " "*indent,
- (key, kv[0]),
- " "*(pad-len(kv[0])),
- (val, kv[1]),
- ]
+ ret.append(
+ urwid.Columns(
+ [
+ ("fixed", indent, urwid.Text("")),
+ (
+ "fixed",
+ maxk,
+ urwid.Text([(key, kv[0] or "")])
+ ),
+ urwid.Text([(val, kv[1])])
+ ],
+ dividechars = 2
+ )
)
- if i < len(lst) - 1:
- ret.append("\n")
return ret
@@ -124,8 +126,6 @@ def format_flow(f, focus, extended=False, padding=2):
return txt
-
-
def int_version(v):
SIG = 3
v = urwid.__version__.split("-")[0].split(".")
diff --git a/libmproxy/console/connview.py b/libmproxy/console/connview.py
index 3274a4c9..80750f99 100644
--- a/libmproxy/console/connview.py
+++ b/libmproxy/console/connview.py
@@ -149,26 +149,23 @@ class ConnectionView(common.WWrap):
vals.append(utils.cleanBin(
"\n".join(parts[3+parts[2:].index(""):])
))
- kv = common.format_keyvals(
+ r = [
+ urwid.Text(("highlight", "Form data:\n")),
+ ]
+ r.extend(common.format_keyvals(
zip(keys, vals),
key = "header",
val = "text"
- )
- return [
- urwid.Text(("highlight", "Form data:\n")),
- urwid.Text(kv)
- ]
+ ))
+ return r
def _view_conn_urlencoded(self, lines):
- return [
- urwid.Text(
- common.format_keyvals(
- [(k+":", v) for (k, v) in lines],
- key = "header",
- val = "text"
- )
- )
- ]
+ return common.format_keyvals(
+ [(k+":", v) for (k, v) in lines],
+ key = "header",
+ val = "text"
+ )
+
def _find_pretty_view(self, content, hdrItems):
ctype = None
@@ -189,19 +186,15 @@ class ConnectionView(common.WWrap):
elif ctype and "multipart/form-data" in ctype:
boundary = ctype.split('boundary=')
if len(boundary) > 1:
- return "FOrm data", self._view_conn_formdata(content, boundary[1].split(';')[0])
+ return "Form data", self._view_conn_formdata(content, boundary[1].split(';')[0])
return "", self._view_conn_raw(content)
def _cached_conn_text(self, e, content, hdrItems, viewmode):
- hdr = []
- hdr.extend(
- common.format_keyvals(
+ txt = common.format_keyvals(
[(h+":", v) for (h, v) in hdrItems],
key = "header",
val = "text"
)
- )
- txt = [urwid.Text(hdr)]
if content:
msg = ""
if viewmode == common.VIEW_BODY_HEX:
diff --git a/libmproxy/console/help.py b/libmproxy/console/help.py
index 22b42475..367857b8 100644
--- a/libmproxy/console/help.py
+++ b/libmproxy/console/help.py
@@ -23,10 +23,10 @@ class HelpView(urwid.ListBox):
def helptext(self):
text = []
- text.append(("head", "Keys for this view:\n"))
+ text.append(urwid.Text([("head", "Keys for this view:\n")]))
text.extend(self.help_context)
- text.append(("head", "\n\nMovement:\n"))
+ text.append(urwid.Text([("head", "\n\nMovement:\n")]))
keys = [
("j, k", "up, down"),
("h, l", "left, right (in some contexts)"),
@@ -36,7 +36,7 @@ class HelpView(urwid.ListBox):
]
text.extend(common.format_keyvals(keys, key="key", val="text", indent=4))
- text.append(("head", "\n\nGlobal keys:\n"))
+ text.append(urwid.Text([("head", "\n\nGlobal keys:\n")]))
keys = [
("c", "client replay"),
("i", "set interception pattern"),
@@ -68,7 +68,7 @@ class HelpView(urwid.ListBox):
]
text.extend(common.format_keyvals(keys, key="key", val="text", indent=4))
- text.append(("head", "\n\nFilter expressions:\n"))
+ text.append(urwid.Text([("head", "\n\nFilter expressions:\n")]))
f = []
for i in filt.filt_unary:
f.append(
@@ -93,16 +93,18 @@ class HelpView(urwid.ListBox):
)
text.extend(common.format_keyvals(f, key="key", val="text", indent=4))
- text.extend(
- [
- "\n",
- ("text", " Regexes are Python-style.\n"),
- ("text", " Regexes can be specified as quoted strings.\n"),
- ("text", " Header matching (~h, ~hq, ~hs) is against a string of the form \"name: value\".\n"),
- ("text", " Expressions with no operators are regex matches against URL.\n"),
- ("text", " Default binary operator is &.\n"),
- ("head", "\n Examples:\n"),
- ]
+ text.append(
+ urwid.Text(
+ [
+ "\n",
+ ("text", " Regexes are Python-style.\n"),
+ ("text", " Regexes can be specified as quoted strings.\n"),
+ ("text", " Header matching (~h, ~hq, ~hs) is against a string of the form \"name: value\".\n"),
+ ("text", " Expressions with no operators are regex matches against URL.\n"),
+ ("text", " Default binary operator is &.\n"),
+ ("head", "\n Examples:\n"),
+ ]
+ )
)
examples = [
("google\.com", "Url containing \"google.com"),
@@ -110,5 +112,5 @@ class HelpView(urwid.ListBox):
("!(~q & ~t \"text/html\")", "Anything but requests with a text/html content type."),
]
text.extend(common.format_keyvals(examples, key="key", val="text", indent=4))
- return [urwid.Text(text)]
+ return text
diff --git a/libmproxy/console/kveditor.py b/libmproxy/console/kveditor.py
index 7b1aeb6a..2997cf7f 100644
--- a/libmproxy/console/kveditor.py
+++ b/libmproxy/console/kveditor.py
@@ -87,10 +87,11 @@ class KVItem(common.WWrap):
return True
+KEY_MAX = 30
class KVWalker(urwid.ListWalker):
def __init__(self, lst, editor):
self.lst, self.editor = lst, editor
- self.maxk = max(len(v[0]) for v in lst) if lst else 20
+ self.maxk = min(max(len(v[0]) for v in lst), KEY_MAX) if lst else 20
if self.maxk < 20:
self.maxk = 20
self.focus = 0