diff options
author | Chris Liechti <cliechti@gmx.net> | 2015-08-27 23:37:38 +0200 |
---|---|---|
committer | Chris Liechti <cliechti@gmx.net> | 2015-08-27 23:37:38 +0200 |
commit | 1df2827d4b49f35b15ac582ba0b142a30d1f8079 (patch) | |
tree | cea524d670397a7091e516a7b1a9be07c59dafb3 | |
parent | ef1fe252d12bb6e41843ee9f8e1425ea927213d3 (diff) | |
download | pyserial-git-1df2827d4b49f35b15ac582ba0b142a30d1f8079.tar.gz |
miniterm: save and restore console codepage on windows
-rw-r--r-- | serial/tools/miniterm.py | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/serial/tools/miniterm.py b/serial/tools/miniterm.py index 8b9605f..6807153 100644 --- a/serial/tools/miniterm.py +++ b/serial/tools/miniterm.py @@ -43,10 +43,10 @@ class ConsoleBase(object): self.output = sys.stdout def setup(self): - pass # Do nothing for 'nt' + pass def cleanup(self): - pass # Do nothing for 'nt' + pass def getkey(self): return None @@ -77,6 +77,8 @@ if os.name == 'nt': class Console(ConsoleBase): def __init__(self): super(Console, self).__init__() + self._saved_ocp = ctypes.windll.kernel32.GetConsoleOutputCP() + self._saved_icp = ctypes.windll.kernel32.GetConsoleCP() ctypes.windll.kernel32.SetConsoleOutputCP(65001) ctypes.windll.kernel32.SetConsoleCP(65001) if sys.version_info < (3, 0): @@ -92,6 +94,10 @@ if os.name == 'nt': else: self.output = codecs.getwriter('UTF-8')(sys.stdout.buffer, 'replace') + def __del__(self): + ctypes.windll.kernel32.SetConsoleOutputCP(self._saved_ocp) + ctypes.windll.kernel32.SetConsoleCP(self._saved_icp) + def getkey(self): while True: z = msvcrt.getwch() |