We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Crash when clearing event log
##### Steps to reproduce the problem:

1. Press `E` 
2. Press `z`
```
...
  File "/home/ujjwal/Github/mitmproxy/venv/lib/python3.5/site-packages/urwid/raw_display.py", line 393, in <lambda>
    event_loop, callback, self.get_available_raw_input())
  File "/home/ujjwal/Github/mitmproxy/venv/lib/python3.5/site-packages/urwid/raw_display.py", line 493, in parse_input
    callback(processed, processed_codes)
  File "/home/ujjwal/Github/mitmproxy/venv/lib/python3.5/site-packages/urwid/main_loop.py", line 403, in _update
    self.process_input(keys)
  File "/home/ujjwal/Github/mitmproxy/venv/lib/python3.5/site-packages/urwid/main_loop.py", line 503, in process_input
    k = self._topmost_widget.keypress(self.screen_size, k)
  File "/home/ujjwal/Github/mitmproxy/mitmproxy/tools/console/window.py", line 226, in keypress
    k = fs.keypress(size, k)
  File "/home/ujjwal/Github/mitmproxy/mitmproxy/tools/console/eventlog.py", line 26, in keypress
    self.master.clear_events()
AttributeError: 'ConsoleMaster' object has no attribute 'clear_events'
```


##### Any other comments? What have you tried so far?
Caused by:
https://github.com/mitmproxy/mitmproxy/commit/0f4d94b31c02171c1cc39bf90426b61e5c2a05e1
##### System information
Mitmproxy version: 3.0.0 (2.0.0dev0564-0x0d7b718) 
Python version: 3.5.2
Platform: Linux-4.9.0-040900-generic-x86_64-with-elementary-0.4.1-loki
SSL version: OpenSSL 1.0.2g  1 Mar 2016
Linux distro: "elementary" 0.4.1 loki


<!--
    Cut and paste the output of "mitmproxy --version".

    If you're using an older version if mitmproxy, please specify the version
    and OS.
-->

Crash when using mouse in mitmproxy
##### Steps to reproduce the problem:

1.Open mitmproxy
2.Click on any flow for flow details
3.
```
...
  File "/home/ujjwal/Github/mitmproxy/mitmproxy/tools/console/window.py", line 206, in mouse_event
    k = super().mouse_event(*args, **kwargs)
  File "/home/ujjwal/Github/mitmproxy/venv/lib/python3.5/site-packages/urwid/container.py", line 1169, in mouse_event
    event, button, col, row-htrim, focus )
  File "/home/ujjwal/Github/mitmproxy/venv/lib/python3.5/site-packages/urwid/listbox.py", line 1566, in mouse_event
    focus)
  File "/home/ujjwal/Github/mitmproxy/mitmproxy/tools/console/flowlist.py", line 72, in mouse_event
    self.master.view_flow(self.flow)
AttributeError: 'ConsoleMaster' object has no attribute 'view_flow'
```



##### System information
Mitmproxy version: 3.0.0 (2.0.0dev0424-0x81d68aa) 
Python version: 3.5.2
Platform: Linux-4.9.0-040900-generic-x86_64-with-elementary-0.4-loki
SSL version: OpenSSL 1.0.2g  1 Mar 2016
Linux distro: "elementary" 0.4 loki


<!--
    Cut and paste the output of "mitmproxy --version".

    If you're using an older version if mitmproxy, please specify the version
    and OS.
-->


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `mitmproxy/tools/console/flowlist.py`
Content:
```
1 import urwid
2 
3 from mitmproxy.tools.console import common
4 import mitmproxy.tools.console.master # noqa
5 
6 
7 def _mkhelp():
8     text = []
9     keys = [
10         ("A", "accept all intercepted flows"),
11         ("a", "accept this intercepted flow"),
12         ("b", "save request/response body"),
13         ("C", "export flow to clipboard"),
14         ("d", "delete flow"),
15         ("D", "duplicate flow"),
16         ("e", "toggle eventlog"),
17         ("E", "export flow to file"),
18         ("f", "filter view"),
19         ("F", "toggle follow flow list"),
20         ("L", "load saved flows"),
21         ("m", "toggle flow mark"),
22         ("M", "toggle marked flow view"),
23         ("n", "create a new request"),
24         ("o", "set flow order"),
25         ("r", "replay request"),
26         ("S", "server replay request/s"),
27         ("U", "unmark all marked flows"),
28         ("v", "reverse flow order"),
29         ("V", "revert changes to request"),
30         ("w", "save flows "),
31         ("W", "stream flows to file"),
32         ("X", "kill and delete flow, even if it's mid-intercept"),
33         ("z", "clear flow list or eventlog"),
34         ("Z", "clear unmarked flows"),
35         ("tab", "tab between eventlog and flow list"),
36         ("enter", "view flow"),
37         ("|", "run script on this flow"),
38     ]
39     text.extend(common.format_keyvals(keys, key="key", val="text", indent=4))
40     return text
41 
42 
43 help_context = _mkhelp()
44 
45 footer = [
46     ('heading_key', "?"), ":help ",
47 ]
48 
49 
50 class FlowItem(urwid.WidgetWrap):
51 
52     def __init__(self, master, flow):
53         self.master, self.flow = master, flow
54         w = self.get_text()
55         urwid.WidgetWrap.__init__(self, w)
56 
57     def get_text(self):
58         cols, _ = self.master.ui.get_cols_rows()
59         return common.format_flow(
60             self.flow,
61             self.flow is self.master.view.focus.flow,
62             hostheader=self.master.options.showhost,
63             max_url_len=cols,
64         )
65 
66     def selectable(self):
67         return True
68 
69     def mouse_event(self, size, event, button, col, row, focus):
70         if event == "mouse press" and button == 1:
71             if self.flow.request:
72                 self.master.view_flow(self.flow)
73                 return True
74 
75     def keypress(self, xxx_todo_changeme, key):
76         return key
77 
78 
79 class FlowListWalker(urwid.ListWalker):
80 
81     def __init__(self, master):
82         self.master = master
83 
84     def view_changed(self):
85         self._modified()
86 
87     def get_focus(self):
88         if not self.master.view.focus.flow:
89             return None, 0
90         f = FlowItem(self.master, self.master.view.focus.flow)
91         return f, self.master.view.focus.index
92 
93     def set_focus(self, index):
94         if self.master.view.inbounds(index):
95             self.master.view.focus.index = index
96 
97     def get_next(self, pos):
98         pos = pos + 1
99         if not self.master.view.inbounds(pos):
100             return None, None
101         f = FlowItem(self.master, self.master.view[pos])
102         return f, pos
103 
104     def get_prev(self, pos):
105         pos = pos - 1
106         if not self.master.view.inbounds(pos):
107             return None, None
108         f = FlowItem(self.master, self.master.view[pos])
109         return f, pos
110 
111 
112 class FlowListBox(urwid.ListBox):
113     keyctx = "flowlist"
114 
115     def __init__(
116         self, master: "mitmproxy.tools.console.master.ConsoleMaster"
117     ) -> None:
118         self.master = master  # type: "mitmproxy.tools.console.master.ConsoleMaster"
119         super().__init__(FlowListWalker(master))
120 
121     def keypress(self, size, key):
122         if key == "m_start":
123             self.master.commands.call("view.go 0")
124         elif key == "m_end":
125             self.master.commands.call("view.go -1")
126         return urwid.ListBox.keypress(self, size, key)
127 
128     def view_changed(self):
129         self.body.view_changed()
130
```

Path: `mitmproxy/tools/console/eventlog.py`
Content:
```
1 import urwid
2 from mitmproxy.tools.console import signals
3 
4 EVENTLOG_SIZE = 10000
5 
6 
7 class LogBufferWalker(urwid.SimpleListWalker):
8     pass
9 
10 
11 class EventLog(urwid.ListBox):
12     keyctx = "eventlog"
13 
14     def __init__(self, master):
15         self.walker = LogBufferWalker([])
16         self.master = master
17         urwid.ListBox.__init__(self, self.walker)
18         signals.sig_add_log.connect(self.sig_add_log)
19 
20     def set_focus(self, index):
21         if 0 <= index < len(self.walker):
22             super().set_focus(index)
23 
24     def keypress(self, size, key):
25         if key == "z":
26             self.master.clear_events()
27             key = None
28         elif key == "m_end":
29             self.set_focus(len(self.walker) - 1)
30         elif key == "m_start":
31             self.set_focus(0)
32         return urwid.ListBox.keypress(self, size, key)
33 
34     def sig_add_log(self, sender, e, level):
35         txt = "%s: %s" % (level, str(e))
36         if level in ("error", "warn"):
37             e = urwid.Text((level, txt))
38         else:
39             e = urwid.Text(txt)
40         self.walker.append(e)
41         if len(self.walker) > EVENTLOG_SIZE:
42             self.walker.pop(0)
43         if self.master.options.console_focus_follow:
44             self.walker.set_focus(len(self.walker) - 1)
45 
46     def clear_events(self):
47         self.walker[:] = []
48
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/mitmproxy/tools/console/eventlog.py b/mitmproxy/tools/console/eventlog.py
--- a/mitmproxy/tools/console/eventlog.py
+++ b/mitmproxy/tools/console/eventlog.py
@@ -23,7 +23,7 @@
 
     def keypress(self, size, key):
         if key == "z":
-            self.master.clear_events()
+            self.clear_events()
             key = None
         elif key == "m_end":
             self.set_focus(len(self.walker) - 1)
diff --git a/mitmproxy/tools/console/flowlist.py b/mitmproxy/tools/console/flowlist.py
--- a/mitmproxy/tools/console/flowlist.py
+++ b/mitmproxy/tools/console/flowlist.py
@@ -69,7 +69,7 @@
     def mouse_event(self, size, event, button, col, row, focus):
         if event == "mouse press" and button == 1:
             if self.flow.request:
-                self.master.view_flow(self.flow)
+                self.master.commands.call("console.view.flow @focus")
                 return True
 
     def keypress(self, xxx_todo_changeme, key):

{"golden_diff": "diff --git a/mitmproxy/tools/console/eventlog.py b/mitmproxy/tools/console/eventlog.py\n--- a/mitmproxy/tools/console/eventlog.py\n+++ b/mitmproxy/tools/console/eventlog.py\n@@ -23,7 +23,7 @@\n \n     def keypress(self, size, key):\n         if key == \"z\":\n-            self.master.clear_events()\n+            self.clear_events()\n             key = None\n         elif key == \"m_end\":\n             self.set_focus(len(self.walker) - 1)\ndiff --git a/mitmproxy/tools/console/flowlist.py b/mitmproxy/tools/console/flowlist.py\n--- a/mitmproxy/tools/console/flowlist.py\n+++ b/mitmproxy/tools/console/flowlist.py\n@@ -69,7 +69,7 @@\n     def mouse_event(self, size, event, button, col, row, focus):\n         if event == \"mouse press\" and button == 1:\n             if self.flow.request:\n-                self.master.view_flow(self.flow)\n+                self.master.commands.call(\"console.view.flow @focus\")\n                 return True\n \n     def keypress(self, xxx_todo_changeme, key):\n", "issue": "Crash when clearing event log\n##### Steps to reproduce the problem:\r\n\r\n1. Press `E` \r\n2. Press `z`\r\n```\r\n...\r\n  File \"/home/ujjwal/Github/mitmproxy/venv/lib/python3.5/site-packages/urwid/raw_display.py\", line 393, in <lambda>\r\n    event_loop, callback, self.get_available_raw_input())\r\n  File \"/home/ujjwal/Github/mitmproxy/venv/lib/python3.5/site-packages/urwid/raw_display.py\", line 493, in parse_input\r\n    callback(processed, processed_codes)\r\n  File \"/home/ujjwal/Github/mitmproxy/venv/lib/python3.5/site-packages/urwid/main_loop.py\", line 403, in _update\r\n    self.process_input(keys)\r\n  File \"/home/ujjwal/Github/mitmproxy/venv/lib/python3.5/site-packages/urwid/main_loop.py\", line 503, in process_input\r\n    k = self._topmost_widget.keypress(self.screen_size, k)\r\n  File \"/home/ujjwal/Github/mitmproxy/mitmproxy/tools/console/window.py\", line 226, in keypress\r\n    k = fs.keypress(size, k)\r\n  File \"/home/ujjwal/Github/mitmproxy/mitmproxy/tools/console/eventlog.py\", line 26, in keypress\r\n    self.master.clear_events()\r\nAttributeError: 'ConsoleMaster' object has no attribute 'clear_events'\r\n```\r\n\r\n\r\n##### Any other comments? What have you tried so far?\r\nCaused by:\r\nhttps://github.com/mitmproxy/mitmproxy/commit/0f4d94b31c02171c1cc39bf90426b61e5c2a05e1\r\n##### System information\r\nMitmproxy version: 3.0.0 (2.0.0dev0564-0x0d7b718) \r\nPython version: 3.5.2\r\nPlatform: Linux-4.9.0-040900-generic-x86_64-with-elementary-0.4.1-loki\r\nSSL version: OpenSSL 1.0.2g  1 Mar 2016\r\nLinux distro: \"elementary\" 0.4.1 loki\r\n\r\n\r\n<!--\r\n    Cut and paste the output of \"mitmproxy --version\".\r\n\r\n    If you're using an older version if mitmproxy, please specify the version\r\n    and OS.\r\n-->\r\n\nCrash when using mouse in mitmproxy\n##### Steps to reproduce the problem:\r\n\r\n1.Open mitmproxy\r\n2.Click on any flow for flow details\r\n3.\r\n```\r\n...\r\n  File \"/home/ujjwal/Github/mitmproxy/mitmproxy/tools/console/window.py\", line 206, in mouse_event\r\n    k = super().mouse_event(*args, **kwargs)\r\n  File \"/home/ujjwal/Github/mitmproxy/venv/lib/python3.5/site-packages/urwid/container.py\", line 1169, in mouse_event\r\n    event, button, col, row-htrim, focus )\r\n  File \"/home/ujjwal/Github/mitmproxy/venv/lib/python3.5/site-packages/urwid/listbox.py\", line 1566, in mouse_event\r\n    focus)\r\n  File \"/home/ujjwal/Github/mitmproxy/mitmproxy/tools/console/flowlist.py\", line 72, in mouse_event\r\n    self.master.view_flow(self.flow)\r\nAttributeError: 'ConsoleMaster' object has no attribute 'view_flow'\r\n```\r\n\r\n\r\n\r\n##### System information\r\nMitmproxy version: 3.0.0 (2.0.0dev0424-0x81d68aa) \r\nPython version: 3.5.2\r\nPlatform: Linux-4.9.0-040900-generic-x86_64-with-elementary-0.4-loki\r\nSSL version: OpenSSL 1.0.2g  1 Mar 2016\r\nLinux distro: \"elementary\" 0.4 loki\r\n\r\n\r\n<!--\r\n    Cut and paste the output of \"mitmproxy --version\".\r\n\r\n    If you're using an older version if mitmproxy, please specify the version\r\n    and OS.\r\n-->\r\n\n", "before_files": [{"content": "import urwid\n\nfrom mitmproxy.tools.console import common\nimport mitmproxy.tools.console.master # noqa\n\n\ndef _mkhelp():\n    text = []\n    keys = [\n        (\"A\", \"accept all intercepted flows\"),\n        (\"a\", \"accept this intercepted flow\"),\n        (\"b\", \"save request/response body\"),\n        (\"C\", \"export flow to clipboard\"),\n        (\"d\", \"delete flow\"),\n        (\"D\", \"duplicate flow\"),\n        (\"e\", \"toggle eventlog\"),\n        (\"E\", \"export flow to file\"),\n        (\"f\", \"filter view\"),\n        (\"F\", \"toggle follow flow list\"),\n        (\"L\", \"load saved flows\"),\n        (\"m\", \"toggle flow mark\"),\n        (\"M\", \"toggle marked flow view\"),\n        (\"n\", \"create a new request\"),\n        (\"o\", \"set flow order\"),\n        (\"r\", \"replay request\"),\n        (\"S\", \"server replay request/s\"),\n        (\"U\", \"unmark all marked flows\"),\n        (\"v\", \"reverse flow order\"),\n        (\"V\", \"revert changes to request\"),\n        (\"w\", \"save flows \"),\n        (\"W\", \"stream flows to file\"),\n        (\"X\", \"kill and delete flow, even if it's mid-intercept\"),\n        (\"z\", \"clear flow list or eventlog\"),\n        (\"Z\", \"clear unmarked flows\"),\n        (\"tab\", \"tab between eventlog and flow list\"),\n        (\"enter\", \"view flow\"),\n        (\"|\", \"run script on this flow\"),\n    ]\n    text.extend(common.format_keyvals(keys, key=\"key\", val=\"text\", indent=4))\n    return text\n\n\nhelp_context = _mkhelp()\n\nfooter = [\n    ('heading_key', \"?\"), \":help \",\n]\n\n\nclass FlowItem(urwid.WidgetWrap):\n\n    def __init__(self, master, flow):\n        self.master, self.flow = master, flow\n        w = self.get_text()\n        urwid.WidgetWrap.__init__(self, w)\n\n    def get_text(self):\n        cols, _ = self.master.ui.get_cols_rows()\n        return common.format_flow(\n            self.flow,\n            self.flow is self.master.view.focus.flow,\n            hostheader=self.master.options.showhost,\n            max_url_len=cols,\n        )\n\n    def selectable(self):\n        return True\n\n    def mouse_event(self, size, event, button, col, row, focus):\n        if event == \"mouse press\" and button == 1:\n            if self.flow.request:\n                self.master.view_flow(self.flow)\n                return True\n\n    def keypress(self, xxx_todo_changeme, key):\n        return key\n\n\nclass FlowListWalker(urwid.ListWalker):\n\n    def __init__(self, master):\n        self.master = master\n\n    def view_changed(self):\n        self._modified()\n\n    def get_focus(self):\n        if not self.master.view.focus.flow:\n            return None, 0\n        f = FlowItem(self.master, self.master.view.focus.flow)\n        return f, self.master.view.focus.index\n\n    def set_focus(self, index):\n        if self.master.view.inbounds(index):\n            self.master.view.focus.index = index\n\n    def get_next(self, pos):\n        pos = pos + 1\n        if not self.master.view.inbounds(pos):\n            return None, None\n        f = FlowItem(self.master, self.master.view[pos])\n        return f, pos\n\n    def get_prev(self, pos):\n        pos = pos - 1\n        if not self.master.view.inbounds(pos):\n            return None, None\n        f = FlowItem(self.master, self.master.view[pos])\n        return f, pos\n\n\nclass FlowListBox(urwid.ListBox):\n    keyctx = \"flowlist\"\n\n    def __init__(\n        self, master: \"mitmproxy.tools.console.master.ConsoleMaster\"\n    ) -> None:\n        self.master = master  # type: \"mitmproxy.tools.console.master.ConsoleMaster\"\n        super().__init__(FlowListWalker(master))\n\n    def keypress(self, size, key):\n        if key == \"m_start\":\n            self.master.commands.call(\"view.go 0\")\n        elif key == \"m_end\":\n            self.master.commands.call(\"view.go -1\")\n        return urwid.ListBox.keypress(self, size, key)\n\n    def view_changed(self):\n        self.body.view_changed()\n", "path": "mitmproxy/tools/console/flowlist.py"}, {"content": "import urwid\nfrom mitmproxy.tools.console import signals\n\nEVENTLOG_SIZE = 10000\n\n\nclass LogBufferWalker(urwid.SimpleListWalker):\n    pass\n\n\nclass EventLog(urwid.ListBox):\n    keyctx = \"eventlog\"\n\n    def __init__(self, master):\n        self.walker = LogBufferWalker([])\n        self.master = master\n        urwid.ListBox.__init__(self, self.walker)\n        signals.sig_add_log.connect(self.sig_add_log)\n\n    def set_focus(self, index):\n        if 0 <= index < len(self.walker):\n            super().set_focus(index)\n\n    def keypress(self, size, key):\n        if key == \"z\":\n            self.master.clear_events()\n            key = None\n        elif key == \"m_end\":\n            self.set_focus(len(self.walker) - 1)\n        elif key == \"m_start\":\n            self.set_focus(0)\n        return urwid.ListBox.keypress(self, size, key)\n\n    def sig_add_log(self, sender, e, level):\n        txt = \"%s: %s\" % (level, str(e))\n        if level in (\"error\", \"warn\"):\n            e = urwid.Text((level, txt))\n        else:\n            e = urwid.Text(txt)\n        self.walker.append(e)\n        if len(self.walker) > EVENTLOG_SIZE:\n            self.walker.pop(0)\n        if self.master.options.console_focus_follow:\n            self.walker.set_focus(len(self.walker) - 1)\n\n    def clear_events(self):\n        self.walker[:] = []\n", "path": "mitmproxy/tools/console/eventlog.py"}], "after_files": [{"content": "import urwid\n\nfrom mitmproxy.tools.console import common\nimport mitmproxy.tools.console.master # noqa\n\n\ndef _mkhelp():\n    text = []\n    keys = [\n        (\"A\", \"accept all intercepted flows\"),\n        (\"a\", \"accept this intercepted flow\"),\n        (\"b\", \"save request/response body\"),\n        (\"C\", \"export flow to clipboard\"),\n        (\"d\", \"delete flow\"),\n        (\"D\", \"duplicate flow\"),\n        (\"e\", \"toggle eventlog\"),\n        (\"E\", \"export flow to file\"),\n        (\"f\", \"filter view\"),\n        (\"F\", \"toggle follow flow list\"),\n        (\"L\", \"load saved flows\"),\n        (\"m\", \"toggle flow mark\"),\n        (\"M\", \"toggle marked flow view\"),\n        (\"n\", \"create a new request\"),\n        (\"o\", \"set flow order\"),\n        (\"r\", \"replay request\"),\n        (\"S\", \"server replay request/s\"),\n        (\"U\", \"unmark all marked flows\"),\n        (\"v\", \"reverse flow order\"),\n        (\"V\", \"revert changes to request\"),\n        (\"w\", \"save flows \"),\n        (\"W\", \"stream flows to file\"),\n        (\"X\", \"kill and delete flow, even if it's mid-intercept\"),\n        (\"z\", \"clear flow list or eventlog\"),\n        (\"Z\", \"clear unmarked flows\"),\n        (\"tab\", \"tab between eventlog and flow list\"),\n        (\"enter\", \"view flow\"),\n        (\"|\", \"run script on this flow\"),\n    ]\n    text.extend(common.format_keyvals(keys, key=\"key\", val=\"text\", indent=4))\n    return text\n\n\nhelp_context = _mkhelp()\n\nfooter = [\n    ('heading_key', \"?\"), \":help \",\n]\n\n\nclass FlowItem(urwid.WidgetWrap):\n\n    def __init__(self, master, flow):\n        self.master, self.flow = master, flow\n        w = self.get_text()\n        urwid.WidgetWrap.__init__(self, w)\n\n    def get_text(self):\n        cols, _ = self.master.ui.get_cols_rows()\n        return common.format_flow(\n            self.flow,\n            self.flow is self.master.view.focus.flow,\n            hostheader=self.master.options.showhost,\n            max_url_len=cols,\n        )\n\n    def selectable(self):\n        return True\n\n    def mouse_event(self, size, event, button, col, row, focus):\n        if event == \"mouse press\" and button == 1:\n            if self.flow.request:\n                self.master.commands.call(\"console.view.flow @focus\")\n                return True\n\n    def keypress(self, xxx_todo_changeme, key):\n        return key\n\n\nclass FlowListWalker(urwid.ListWalker):\n\n    def __init__(self, master):\n        self.master = master\n\n    def view_changed(self):\n        self._modified()\n\n    def get_focus(self):\n        if not self.master.view.focus.flow:\n            return None, 0\n        f = FlowItem(self.master, self.master.view.focus.flow)\n        return f, self.master.view.focus.index\n\n    def set_focus(self, index):\n        if self.master.view.inbounds(index):\n            self.master.view.focus.index = index\n\n    def get_next(self, pos):\n        pos = pos + 1\n        if not self.master.view.inbounds(pos):\n            return None, None\n        f = FlowItem(self.master, self.master.view[pos])\n        return f, pos\n\n    def get_prev(self, pos):\n        pos = pos - 1\n        if not self.master.view.inbounds(pos):\n            return None, None\n        f = FlowItem(self.master, self.master.view[pos])\n        return f, pos\n\n\nclass FlowListBox(urwid.ListBox):\n    keyctx = \"flowlist\"\n\n    def __init__(\n        self, master: \"mitmproxy.tools.console.master.ConsoleMaster\"\n    ) -> None:\n        self.master = master  # type: \"mitmproxy.tools.console.master.ConsoleMaster\"\n        super().__init__(FlowListWalker(master))\n\n    def keypress(self, size, key):\n        if key == \"m_start\":\n            self.master.commands.call(\"view.go 0\")\n        elif key == \"m_end\":\n            self.master.commands.call(\"view.go -1\")\n        return urwid.ListBox.keypress(self, size, key)\n\n    def view_changed(self):\n        self.body.view_changed()\n", "path": "mitmproxy/tools/console/flowlist.py"}, {"content": "import urwid\nfrom mitmproxy.tools.console import signals\n\nEVENTLOG_SIZE = 10000\n\n\nclass LogBufferWalker(urwid.SimpleListWalker):\n    pass\n\n\nclass EventLog(urwid.ListBox):\n    keyctx = \"eventlog\"\n\n    def __init__(self, master):\n        self.walker = LogBufferWalker([])\n        self.master = master\n        urwid.ListBox.__init__(self, self.walker)\n        signals.sig_add_log.connect(self.sig_add_log)\n\n    def set_focus(self, index):\n        if 0 <= index < len(self.walker):\n            super().set_focus(index)\n\n    def keypress(self, size, key):\n        if key == \"z\":\n            self.clear_events()\n            key = None\n        elif key == \"m_end\":\n            self.set_focus(len(self.walker) - 1)\n        elif key == \"m_start\":\n            self.set_focus(0)\n        return urwid.ListBox.keypress(self, size, key)\n\n    def sig_add_log(self, sender, e, level):\n        txt = \"%s: %s\" % (level, str(e))\n        if level in (\"error\", \"warn\"):\n            e = urwid.Text((level, txt))\n        else:\n            e = urwid.Text(txt)\n        self.walker.append(e)\n        if len(self.walker) > EVENTLOG_SIZE:\n            self.walker.pop(0)\n        if self.master.options.console_focus_follow:\n            self.walker.set_focus(len(self.walker) - 1)\n\n    def clear_events(self):\n        self.walker[:] = []\n", "path": "mitmproxy/tools/console/eventlog.py"}]}