diff options
author | Jim Shaver <dcypherd@gmail.com> | 2015-05-31 01:21:44 -0400 |
---|---|---|
committer | Jim Shaver <dcypherd@gmail.com> | 2015-05-31 01:21:44 -0400 |
commit | b51363b3ca43f6572acb673186e6ae78a1f48434 (patch) | |
tree | a7488b32871c142141a813dc6ff2ede172672c31 /libmproxy/console/tabs.py | |
parent | 4fe2c069cca07aadf983f54e18dac4de492d5d69 (diff) | |
parent | 06fba18106a8f759ec6f08453e86772a170c653b (diff) | |
download | mitmproxy-b51363b3ca43f6572acb673186e6ae78a1f48434.tar.gz mitmproxy-b51363b3ca43f6572acb673186e6ae78a1f48434.tar.bz2 mitmproxy-b51363b3ca43f6572acb673186e6ae78a1f48434.zip |
Merge remote-tracking branch 'upstream/master' into print-bracket-fix
Conflicts:
examples/har_extractor.py
examples/nonblocking.py
examples/read_dumpfile
libmproxy/web/app.py
Diffstat (limited to 'libmproxy/console/tabs.py')
-rw-r--r-- | libmproxy/console/tabs.py | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/libmproxy/console/tabs.py b/libmproxy/console/tabs.py new file mode 100644 index 00000000..953f6b12 --- /dev/null +++ b/libmproxy/console/tabs.py @@ -0,0 +1,39 @@ +import urwid + + +class Tabs(urwid.WidgetWrap): + def __init__(self, tabs, tab_offset=0): + urwid.WidgetWrap.__init__(self, "") + self.tab_offset = tab_offset + self.tabs = tabs + self.show() + + def _tab(self, content, attr): + p = urwid.Text(content, align="center") + p = urwid.Padding(p, align="center", width=("relative", 100)) + p = urwid.AttrWrap(p, attr) + return p + + def keypress(self, size, key): + if key in ["tab", "l"]: + self.tab_offset = (self.tab_offset + 1) % (len(self.tabs)) + self.show() + elif key == "h": + self.tab_offset = (self.tab_offset - 1) % (len(self.tabs)) + self.show() + return self._w.keypress(size, key) + + def show(self): + headers = [] + for i in range(len(self.tabs)): + txt = self.tabs[i][0]() + if i == self.tab_offset: + headers.append(self._tab(txt, "heading")) + else: + headers.append(self._tab(txt, "heading_inactive")) + headers = urwid.Columns(headers, dividechars=1) + self._w = urwid.Frame( + body = self.tabs[self.tab_offset][1](), + header = headers + ) + self._w.set_focus("body") |