diff options
author | Aldo Cortesi <aldo@nullcube.com> | 2012-02-18 11:11:59 +1300 |
---|---|---|
committer | Aldo Cortesi <aldo@nullcube.com> | 2012-02-18 11:11:59 +1300 |
commit | 08fdd23e234ffaa11352891b103377240bc11fbe (patch) | |
tree | 2a3756af7b984ec1fb7a2414a19dc0224fc50e89 /libmproxy | |
parent | fcc874fa183971c1985578dca66e4b4e49e17f43 (diff) | |
download | mitmproxy-08fdd23e234ffaa11352891b103377240bc11fbe.tar.gz mitmproxy-08fdd23e234ffaa11352891b103377240bc11fbe.tar.bz2 mitmproxy-08fdd23e234ffaa11352891b103377240bc11fbe.zip |
Refactor the way we display flows.
Use columns to make spacing nicer, and to ensure that long URLs don't bugger up
formatting when they spill into the next line.
Diffstat (limited to 'libmproxy')
-rw-r--r-- | libmproxy/console/common.py | 98 | ||||
-rw-r--r-- | libmproxy/console/connlist.py | 3 | ||||
-rw-r--r-- | libmproxy/console/connview.py | 4 |
3 files changed, 62 insertions, 43 deletions
diff --git a/libmproxy/console/common.py b/libmproxy/console/common.py index 28cf20cb..2d7209bc 100644 --- a/libmproxy/console/common.py +++ b/libmproxy/console/common.py @@ -70,60 +70,80 @@ def shortcuts(k): return k +def fcol(s, attr): + s = str(s) + return ( + "fixed", + len(s), + urwid.Text( + [ + (attr, s) + ] + ) + ) + + def format_flow(f, focus, extended=False, padding=2): - txt = [] + pile = [] + + req = [] if extended: - txt.append(("highlight", utils.format_timestamp(f.request.timestamp))) - txt.append(" ") + req.append( + fcol( + utils.format_timestamp(f.request.timestamp), + "highlight" + ) + ) + else: + req.append(fcol(">>" if focus else " ", "focus")) if f.request.is_replay(): - txt.append(("method", "[replay]")) - txt.extend([ - ("ack", "!") if f.intercepting and not f.request.acked else " ", - ("method", f.request.method), - " ", - ( - "text" if (f.response or f.error) else "title", - f.request.get_url(), - ), - ]) - if f.response or f.error or f.request.is_replay(): - tsr = f.response or f.error - if extended and tsr: - ts = ("highlight", utils.format_timestamp(tsr.timestamp) + " ") - else: - ts = " " + req.append(fcol("[replay]", "method")) + req.append(fcol(f.request.method, "method")) - txt.append("\n") - txt.append(("text", ts)) - txt.append(" "*(padding+2)) + preamble = sum(i[1] for i in req) + len(req) -1 + req.append( + urwid.Text([ + ( + "text" if (f.response or f.error) else "title", + f.request.get_url(), + ) + ]) + ) + + pile.append(urwid.Columns(req, dividechars=1)) + + resp = [] + resp.append( + ("fixed", preamble, urwid.Text("")) + ) + + if f.response or f.error: + resp.append(fcol("<-", "method")) if f.response: - txt.append( - ("ack", "!") if f.intercepting and not f.response.acked else " " - ) - txt.append("<- ") if f.response.is_replay(): - txt.append(("method", "[replay] ")) + resp.append("[replay]", "method") if f.response.code in [200, 304]: - txt.append(("goodcode", str(f.response.code))) + resp.append(fcol(f.response.code, "goodcode")) else: - txt.append(("error", str(f.response.code))) + resp.append(fcol(f.response.code, "error")) t = f.response.headers["content-type"] if t: t = t[0].split(";")[0] - txt.append(("text", " %s"%t)) + resp.append(fcol(t, "text")) if f.response.content: - txt.append(", %s"%utils.pretty_size(len(f.response.content))) + resp.append(fcol(utils.pretty_size(len(f.response.content)), "text")) elif f.error: - txt.append( - ("error", f.error.msg) + resp.append( + urwid.Text([ + ( + "error", + f.error.msg + ) + ]) ) - - if focus: - txt.insert(0, ("focus", ">>" + " "*(padding-2))) - else: - txt.insert(0, " "*padding) - return txt + pile.append(urwid.Columns(resp, dividechars=1)) + return urwid.Pile(pile) def int_version(v): diff --git a/libmproxy/console/connlist.py b/libmproxy/console/connlist.py index a06f3e65..4e8bfebd 100644 --- a/libmproxy/console/connlist.py +++ b/libmproxy/console/connlist.py @@ -79,7 +79,6 @@ class BodyPile(urwid.Pile): return self.focus_item.keypress( tsize, key ) - class ConnectionItem(common.WWrap): def __init__(self, master, state, flow, focus): self.master, self.state, self.flow = master, state, flow @@ -88,7 +87,7 @@ class ConnectionItem(common.WWrap): common.WWrap.__init__(self, w) def get_text(self): - return urwid.Text(common.format_flow(self.flow, self.focus)) + return common.format_flow(self.flow, self.focus) def selectable(self): return True diff --git a/libmproxy/console/connview.py b/libmproxy/console/connview.py index 80750f99..c9667ed2 100644 --- a/libmproxy/console/connview.py +++ b/libmproxy/console/connview.py @@ -45,11 +45,11 @@ VIEW_CUTOFF = 1024*100 class ConnectionViewHeader(common.WWrap): def __init__(self, master, f): self.master, self.flow = master, f - self.w = urwid.Text(common.format_flow(f, False, extended=True, padding=0)) + self.w = common.format_flow(f, False, extended=True, padding=0) def refresh_connection(self, f): if f == self.flow: - self.w = urwid.Text(common.format_flow(f, False, extended=True, padding=0)) + self.w = common.format_flow(f, False, extended=True, padding=0) class CallbackCache: |