terminalwriter: remove unused function ansi_print
This commit is contained in:
parent
b6cc90e0af
commit
a6819726cd
|
@ -45,62 +45,6 @@ def get_line_width(text):
|
||||||
return sum(char_width(c) for c in text)
|
return sum(char_width(c) for c in text)
|
||||||
|
|
||||||
|
|
||||||
# XXX unify with _escaped func below
|
|
||||||
def ansi_print(text, esc, file=None, newline=True, flush=False):
|
|
||||||
if file is None:
|
|
||||||
file = sys.stderr
|
|
||||||
text = text.rstrip()
|
|
||||||
if esc and not isinstance(esc, tuple):
|
|
||||||
esc = (esc,)
|
|
||||||
if esc and sys.platform != "win32" and file.isatty():
|
|
||||||
text = (
|
|
||||||
"".join(["\x1b[%sm" % cod for cod in esc]) + text + "\x1b[0m"
|
|
||||||
) # ANSI color code "reset"
|
|
||||||
if newline:
|
|
||||||
text += "\n"
|
|
||||||
|
|
||||||
if esc and win32_and_ctypes and file.isatty():
|
|
||||||
if 1 in esc:
|
|
||||||
bold = True
|
|
||||||
esc = tuple([x for x in esc if x != 1])
|
|
||||||
else:
|
|
||||||
bold = False
|
|
||||||
esctable = {
|
|
||||||
(): FOREGROUND_WHITE, # normal
|
|
||||||
(31,): FOREGROUND_RED, # red
|
|
||||||
(32,): FOREGROUND_GREEN, # green
|
|
||||||
(33,): FOREGROUND_GREEN | FOREGROUND_RED, # yellow
|
|
||||||
(34,): FOREGROUND_BLUE, # blue
|
|
||||||
(35,): FOREGROUND_BLUE | FOREGROUND_RED, # purple
|
|
||||||
(36,): FOREGROUND_BLUE | FOREGROUND_GREEN, # cyan
|
|
||||||
(37,): FOREGROUND_WHITE, # white
|
|
||||||
(39,): FOREGROUND_WHITE, # reset
|
|
||||||
}
|
|
||||||
attr = esctable.get(esc, FOREGROUND_WHITE)
|
|
||||||
if bold:
|
|
||||||
attr |= FOREGROUND_INTENSITY
|
|
||||||
STD_OUTPUT_HANDLE = -11
|
|
||||||
STD_ERROR_HANDLE = -12
|
|
||||||
if file is sys.stderr:
|
|
||||||
handle = GetStdHandle(STD_ERROR_HANDLE)
|
|
||||||
else:
|
|
||||||
handle = GetStdHandle(STD_OUTPUT_HANDLE)
|
|
||||||
oldcolors = GetConsoleInfo(handle).wAttributes
|
|
||||||
attr |= oldcolors & 0x0F0
|
|
||||||
SetConsoleTextAttribute(handle, attr)
|
|
||||||
while len(text) > 32768:
|
|
||||||
file.write(text[:32768])
|
|
||||||
text = text[32768:]
|
|
||||||
if text:
|
|
||||||
file.write(text)
|
|
||||||
SetConsoleTextAttribute(handle, oldcolors)
|
|
||||||
else:
|
|
||||||
file.write(text)
|
|
||||||
|
|
||||||
if flush:
|
|
||||||
file.flush()
|
|
||||||
|
|
||||||
|
|
||||||
def should_do_markup(file):
|
def should_do_markup(file):
|
||||||
if os.environ.get("PY_COLORS") == "1":
|
if os.environ.get("PY_COLORS") == "1":
|
||||||
return True
|
return True
|
||||||
|
|
Loading…
Reference in New Issue