aboutsummaryrefslogtreecommitdiffstats
path: root/mitmproxy
diff options
context:
space:
mode:
authorEdgar Boda-Majer <eboda@users.noreply.github.com>2016-11-20 16:40:04 +0100
committerThomas Kriechbaumer <Kriechi@users.noreply.github.com>2016-11-20 16:40:04 +0100
commit078f36d86a939b479a8f670d761c0fc22930c5ce (patch)
treed0fe4812197c2e8e27a5f1ea3cd3530464dd5a58 /mitmproxy
parentb6e419d6403cbd15eb4a95d4082f234dbf6acbf0 (diff)
downloadmitmproxy-078f36d86a939b479a8f670d761c0fc22930c5ce.tar.gz
mitmproxy-078f36d86a939b479a8f670d761c0fc22930c5ce.tar.bz2
mitmproxy-078f36d86a939b479a8f670d761c0fc22930c5ce.zip
handle SIGINT with a quit prompt (#1760)
Diffstat (limited to 'mitmproxy')
-rw-r--r--mitmproxy/tools/console/master.py27
1 files changed, 18 insertions, 9 deletions
diff --git a/mitmproxy/tools/console/master.py b/mitmproxy/tools/console/master.py
index 3db6f425..f8850404 100644
--- a/mitmproxy/tools/console/master.py
+++ b/mitmproxy/tools/console/master.py
@@ -3,6 +3,7 @@ import mimetypes
import os
import os.path
import shlex
+import signal
import stat
import subprocess
import sys
@@ -91,6 +92,11 @@ class ConsoleMaster(master.Master):
self.addons.add(*addons.default_addons())
self.addons.add(intercept.Intercept(), self.view)
+ def sigint_handler(*args, **kwargs):
+ self.prompt_for_exit()
+
+ signal.signal(signal.SIGINT, sigint_handler)
+
def __setattr__(self, name, value):
self.__dict__[name] = value
signals.update_settings.send(self)
@@ -101,6 +107,17 @@ class ConsoleMaster(master.Master):
expire=1
)
+ def prompt_for_exit(self):
+ signals.status_prompt_onekey.send(
+ self,
+ prompt = "Quit",
+ keys = (
+ ("yes", "y"),
+ ("no", "n"),
+ ),
+ callback = self.quit,
+ )
+
def sig_add_log(self, sender, e, level):
if self.options.verbosity < log.log_tier(level):
return
@@ -139,15 +156,7 @@ class ConsoleMaster(master.Master):
self.view_stack.pop()
self.loop.widget = self.view_stack[-1]
else:
- signals.status_prompt_onekey.send(
- self,
- prompt = "Quit",
- keys = (
- ("yes", "y"),
- ("no", "n"),
- ),
- callback = self.quit,
- )
+ self.prompt_for_exit()
def sig_push_view_state(self, sender, window):
"""