diff options
author | Shadab Zafar <dufferzafar0@gmail.com> | 2016-07-21 15:43:58 +0530 |
---|---|---|
committer | Shadab Zafar <dufferzafar0@gmail.com> | 2016-07-23 10:41:57 +0530 |
commit | 426a62299ceae9f9228e376acc4a153835578cba (patch) | |
tree | fde8cc86911abe2744712f4ab77f41739f6ad200 | |
parent | 6135ec11968c855640543e847aeb1d7313f950a8 (diff) | |
download | mitmproxy-426a62299ceae9f9228e376acc4a153835578cba.tar.gz mitmproxy-426a62299ceae9f9228e376acc4a153835578cba.tar.bz2 mitmproxy-426a62299ceae9f9228e376acc4a153835578cba.zip |
Focus nearest matching flow if current flow is unmarked
-rw-r--r-- | mitmproxy/console/master.py | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/mitmproxy/console/master.py b/mitmproxy/console/master.py index 7570d2f7..cef4f855 100644 --- a/mitmproxy/console/master.py +++ b/mitmproxy/console/master.py @@ -123,22 +123,43 @@ class ConsoleState(flow.State): self.set_focus(self.focus) return ret + def get_nearest_matching_flow(self, flow, filt): + fidx = self.view.index(flow) + dist = 1 + + fprev = fnext = True + while fprev or fnext: + fprev, _ = self.get_from_pos(fidx - dist) + fnext, _ = self.get_from_pos(fidx + dist) + + if fprev and fprev.match(filt): + return fprev + elif fnext and fnext.match(filt): + return fnext + + dist += 1 + + return None + def enable_marked_filter(self): marked_flows = [f for f in self.flows if f.marked] if not marked_flows: return + marked_filter = "~%s" % FMarked.code + # Save Focus last_focus, _ = self.get_focus() + nearest_marked = self.get_nearest_matching_flow(last_focus, marked_filter) self.last_filter = self.limit_txt - self.set_limit("~%s" % FMarked.code) + self.set_limit(marked_filter) # Set Focus if last_focus.marked: self.set_focus_flow(last_focus) else: - self.set_focus(0) + self.set_focus_flow(nearest_marked) self.mark_filter = True |