diff --git a/mitmproxy/tools/console/master.py b/mitmproxy/tools/console/master.py index 37f8a0546..e4802cce2 100644 --- a/mitmproxy/tools/console/master.py +++ b/mitmproxy/tools/console/master.py @@ -200,6 +200,16 @@ class ConsoleMaster(master.Master): "Please run mitmproxy in an interactive shell environment.", file=sys.stderr) sys.exit(1) + if os.name != "nt" and "utf" not in urwid.detected_encoding.lower(): + print( + f"mitmproxy expects a UTF-8 console environment, not {urwid.detected_encoding!r}. " + f"Set your LANG environment variable to something like en_US.UTF-8.", + file=sys.stderr + ) + # Experimental (04/2022): We just don't exit here and see if/how that affects users. + # sys.exit(1) + urwid.set_encoding("utf8") + signals.call_in.connect(self.sig_call_in) self.ui = window.Screen() self.ui.set_terminal_properties(256) diff --git a/mitmproxy/tools/main.py b/mitmproxy/tools/main.py index 6771cb1ae..5584888a8 100644 --- a/mitmproxy/tools/main.py +++ b/mitmproxy/tools/main.py @@ -12,22 +12,6 @@ from mitmproxy.tools import cmdline from mitmproxy.utils import debug, arg_check -def assert_utf8_env(): - spec = "" - for i in ["LANG", "LC_CTYPE", "LC_ALL"]: - spec += os.environ.get(i, "").lower() - if "utf" not in spec: - print( - "Error: mitmproxy requires a UTF console environment.", - file=sys.stderr - ) - print( - "Set your LANG environment variable to something like en_US.UTF-8", - file=sys.stderr - ) - sys.exit(1) - - def process_options(parser, opts, args): if args.version: print(debug.dump_system_info()) @@ -123,11 +107,6 @@ def run( def mitmproxy(args=None) -> typing.Optional[int]: # pragma: no cover - if os.name == "nt": - import urwid - urwid.set_encoding("utf8") - else: - assert_utf8_env() from mitmproxy.tools import console run(console.master.ConsoleMaster, cmdline.mitmproxy, args) return None