terminalwriter: move Win32ConsoleWriter definition under win32 conditional
This way non-Windows platforms skip it. It also uses things defined inside the `if`.
This commit is contained in:
parent
5e2d820308
commit
1d596b27a7
|
@ -300,7 +300,26 @@ class TerminalWriter:
|
|||
self.write(" " * diff2last)
|
||||
|
||||
|
||||
class Win32ConsoleWriter(TerminalWriter):
|
||||
class WriteFile:
|
||||
def __init__(self, writemethod, encoding=None):
|
||||
self.encoding = encoding
|
||||
self._writemethod = writemethod
|
||||
|
||||
def write(self, data):
|
||||
if self.encoding:
|
||||
data = data.encode(self.encoding, "replace")
|
||||
self._writemethod(data)
|
||||
|
||||
def flush(self):
|
||||
return
|
||||
|
||||
|
||||
if win32_and_ctypes:
|
||||
import ctypes # noqa: F811
|
||||
from ctypes import wintypes
|
||||
from ctypes import windll # type: ignore[attr-defined] # noqa: F821
|
||||
|
||||
class Win32ConsoleWriter(TerminalWriter):
|
||||
def write(self, msg, **kw):
|
||||
if msg:
|
||||
if not isinstance(msg, (bytes, str)):
|
||||
|
@ -333,26 +352,6 @@ class Win32ConsoleWriter(TerminalWriter):
|
|||
if oldcolors:
|
||||
SetConsoleTextAttribute(handle, oldcolors)
|
||||
|
||||
|
||||
class WriteFile:
|
||||
def __init__(self, writemethod, encoding=None):
|
||||
self.encoding = encoding
|
||||
self._writemethod = writemethod
|
||||
|
||||
def write(self, data):
|
||||
if self.encoding:
|
||||
data = data.encode(self.encoding, "replace")
|
||||
self._writemethod(data)
|
||||
|
||||
def flush(self):
|
||||
return
|
||||
|
||||
|
||||
if win32_and_ctypes:
|
||||
import ctypes # noqa: F811
|
||||
from ctypes import wintypes
|
||||
from ctypes import windll # type: ignore[attr-defined] # noqa: F821
|
||||
|
||||
TerminalWriter = Win32ConsoleWriter # type: ignore[misc] # noqa: F821
|
||||
|
||||
# ctypes access to the Windows console
|
||||
|
|
Loading…
Reference in New Issue