miniterm: save and restore console codepage on windows
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 @@
         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 @@
     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 @@
             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()