6from .ansi
import AnsiFore, AnsiBack, AnsiStyle, Style, BEL
7from .winterm
import enable_vt_processing, WinTerm, WinColor, WinStyle
8from .win32
import windll, winapi_test
18 Wraps a stream (such as stdout), acting as a transparent proxy for all
19 attribute access apart from method 'write()', which is delegated to our
56 except AttributeError:
68 except (AttributeError, ValueError):
74 Implements a 'write()' method which, on Windows, will strip ANSI character
75 sequences from the text, and if outputting to a tty, will convert them into
78 ANSI_CSI_RE =
re.compile(
'\001?\033\\[((?:\\d|;)*)([a-zA-Z])\002?')
79 ANSI_OSC_RE =
re.compile(
'\001?\033\\]([^\a]*)(\a)\002?')
81 def __init__(self, wrapped, convert=None, strip=None, autoreset=False):
96 conversion_supported = on_windows
and winapi_test()
101 system_has_native_ansi =
not on_windows
or enable_vt_processing(fd)
102 have_tty =
not self.
stream.closed
and self.
stream.isatty()
103 need_conversion = conversion_supported
and not system_has_native_ansi
107 strip = need_conversion
or not have_tty
112 convert = need_conversion
and have_tty
123 True if this class is actually needed. If false, then the output
124 stream will not be affected, nor will win32 calls be issued, so
125 wrapping stdout is not actually required. This will generally be
126 False on non-Windows platforms, unless optional functionality like
127 autoreset has been requested using kwargs to init()
194 Write the given text to our wrapped stream, stripping any ANSI
195 sequences from the text, and optionally converting them into win32
223 while len(params) < 2:
225 params = params + (1,)
232 elif command
in 'ABCD':
246 func(*args, **kwargs)
251 elif command
in 'Hf':
253 elif command
in 'ABCD':
256 x, y = {
'A': (0, -n),
'B': (0, n),
'C': (n, 0),
'D': (-n, 0)}[command]
263 text = text[:start] + text[end:]
271 if params[0]
in '02':
convert_ansi(self, paramstring, command)
write_plain_text(self, text, start, end)
__init__(self, wrapped, convert=None, strip=None, autoreset=False)
call_win32(self, command, params)
extract_params(self, command, paramstring)
write_and_convert(self, text)
__init__(self, wrapped, converter)
__enter__(self, *args, **kwargs)
__exit__(self, *args, **kwargs)
__setstate__(self, state)