mitmproxy.console: Complete port to view.

This commit is contained in:
Aldo Cortesi 2016-10-30 16:15:33 +13:00
parent 6b6c44551a
commit 62ead34a94
3 changed files with 29 additions and 47 deletions

View File

@ -463,35 +463,25 @@ class FlowView(tabs.Tabs):
) )
signals.flow_change.send(self, flow = self.flow) signals.flow_change.send(self, flow = self.flow)
def _view_nextprev_flow(self, np, flow): def view_flow(self, flow):
try: signals.pop_view_state.send(self)
idx = self.view.index(flow) self.master.view_flow(flow, self.tab_offset)
except IndexError:
return
new_idx = idx def _view_nextprev_flow(self, idx, flow):
if np == "next": if not self.view.inbounds(idx):
new_idx += 1
else:
new_idx -= 1
if not self.view.inbounds(new_idx):
signals.status_message.send(message="No more flows") signals.status_message.send(message="No more flows")
return return
signals.pop_view_state.send(self) self.view_flow(self.view[idx])
self.master.view_flow(self.view[new_idx], self.tab_offset)
def view_next_flow(self, flow): def view_next_flow(self, flow):
return self._view_nextprev_flow("next", flow) return self._view_nextprev_flow(self.view.index(flow) + 1, flow)
def view_prev_flow(self, flow): def view_prev_flow(self, flow):
return self._view_nextprev_flow("prev", flow) return self._view_nextprev_flow(self.view.index(flow) - 1, flow)
def change_this_display_mode(self, t): def change_this_display_mode(self, t):
self.state.add_flow_setting( name = contentviews.get_by_shortcut(t).name
self.flow, self.view.settings[self.flow][(self.tab_offset, "prettyview")] = name
(self.tab_offset, "prettyview"),
contentviews.get_by_shortcut(t).name
)
signals.flow_change.send(self, flow = self.flow) signals.flow_change.send(self, flow = self.flow)
def keypress(self, size, key): def keypress(self, size, key):
@ -520,20 +510,18 @@ class FlowView(tabs.Tabs):
self.master.accept_all() self.master.accept_all()
signals.flow_change.send(self, flow = self.flow) signals.flow_change.send(self, flow = self.flow)
elif key == "d": elif key == "d":
if self.state.flow_count() == 1: if self.flow.killable:
self.flow.kill(self.master)
self.view.remove(self.flow)
if not self.view.focus.flow:
self.master.view_flowlist() self.master.view_flowlist()
elif self.state.view.index(self.flow) == len(self.state.view) - 1:
self.view_prev_flow(self.flow)
else: else:
self.view_next_flow(self.flow) self.view_flow(self.view.focus.flow)
f = self.flow
if f.killable:
f.kill(self.master)
self.state.delete_flow(f)
elif key == "D": elif key == "D":
f = self.master.state.duplicate_flow(self.flow) cp = self.flow.copy()
signals.pop_view_state.send(self) self.master.view.add(cp)
self.master.view_flow(f) self.master.view.focus.flow = cp
self.view_flow(cp)
signals.status_message.send(message="Duplicated.") signals.status_message.send(message="Duplicated.")
elif key == "p": elif key == "p":
self.view_prev_flow(self.flow) self.view_prev_flow(self.flow)
@ -545,7 +533,7 @@ class FlowView(tabs.Tabs):
signals.flow_change.send(self, flow = self.flow) signals.flow_change.send(self, flow = self.flow)
elif key == "V": elif key == "V":
if self.flow.modified(): if self.flow.modified():
self.state.revert(self.flow) self.flow.revert()
signals.flow_change.send(self, flow = self.flow) signals.flow_change.send(self, flow = self.flow)
signals.status_message.send(message="Reverted.") signals.status_message.send(message="Reverted.")
else: else:
@ -607,14 +595,9 @@ class FlowView(tabs.Tabs):
else: else:
common.ask_save_body("s", self.flow) common.ask_save_body("s", self.flow)
elif key == "f": elif key == "f":
signals.status_message.send(message="Loading all body data...") self.view.settings[self.flow][(self.tab_offset, "fullcontents")] = True
self.state.add_flow_setting(
self.flow,
(self.tab_offset, "fullcontents"),
True
)
signals.flow_change.send(self, flow = self.flow) signals.flow_change.send(self, flow = self.flow)
signals.status_message.send(message="") signals.status_message.send(message="Loading all body data...")
elif key == "m": elif key == "m":
p = list(contentviews.view_prompts) p = list(contentviews.view_prompts)
p.insert(0, ("Clear", "C")) p.insert(0, ("Clear", "C"))

View File

@ -172,10 +172,8 @@ class Options(urwid.WidgetWrap):
showhost = False, showhost = False,
stickyauth = None, stickyauth = None,
stickycookie = None, stickycookie = None,
default_contentview = "auto",
) )
self.master.state.default_body_view = contentviews.get("Auto")
signals.update_settings.send(self) signals.update_settings.send(self)
signals.status_message.send( signals.status_message.send(
message = "All select.Options cleared", message = "All select.Options cleared",

View File

@ -16,13 +16,14 @@ class Highlight(urwid.AttrMap):
class Searchable(urwid.ListBox): class Searchable(urwid.ListBox):
def __init__(self, state, contents): def __init__(self, view, contents):
self.walker = urwid.SimpleFocusListWalker(contents) self.walker = urwid.SimpleFocusListWalker(contents)
urwid.ListBox.__init__(self, self.walker) urwid.ListBox.__init__(self, self.walker)
self.state = state self.view = view
self.search_offset = 0 self.search_offset = 0
self.current_highlight = None self.current_highlight = None
self.search_term = None self.search_term = None
self.last_search = None
def keypress(self, size, key): def keypress(self, size, key):
if key == "/": if key == "/":
@ -45,7 +46,7 @@ class Searchable(urwid.ListBox):
return super().keypress(size, key) return super().keypress(size, key)
def set_search(self, text): def set_search(self, text):
self.state.last_search = text self.last_search = text
self.search_term = text or None self.search_term = text or None
self.find_next(False) self.find_next(False)
@ -69,8 +70,8 @@ class Searchable(urwid.ListBox):
def find_next(self, backwards): def find_next(self, backwards):
if not self.search_term: if not self.search_term:
if self.state.last_search: if self.last_search:
self.search_term = self.state.last_search self.search_term = self.last_search
else: else:
self.set_highlight(None) self.set_highlight(None)
return return