aboutsummaryrefslogtreecommitdiffstats
path: root/libmproxy/console/common.py
diff options
context:
space:
mode:
authorAldo Cortesi <aldo@nullcube.com>2012-02-18 11:11:59 +1300
committerAldo Cortesi <aldo@nullcube.com>2012-02-18 11:11:59 +1300
commit08fdd23e234ffaa11352891b103377240bc11fbe (patch)
tree2a3756af7b984ec1fb7a2414a19dc0224fc50e89 /libmproxy/console/common.py
parentfcc874fa183971c1985578dca66e4b4e49e17f43 (diff)
downloadmitmproxy-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/console/common.py')
-rw-r--r--libmproxy/console/common.py98
1 files changed, 59 insertions, 39 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):