From 87ccbd69df1b084988cf6d04cf3bfd74eaa748a0 Mon Sep 17 00:00:00 2001 From: Cassie Jones Date: Sun, 7 Feb 2021 03:07:24 -0500 Subject: [PATCH] [tools] Move ANSI color printing code into its own file --- tools/fmt.py | 28 ++++++++++++++++++++++++++++ tools/lit.py | 20 ++------------------ 2 files changed, 30 insertions(+), 18 deletions(-) create mode 100644 tools/fmt.py diff --git a/tools/fmt.py b/tools/fmt.py new file mode 100644 index 0000000..d7d0563 --- /dev/null +++ b/tools/fmt.py @@ -0,0 +1,28 @@ +import sys + + +IS_TTY = sys.stdout.isatty() + + +def red(x): + if not IS_TTY: + return x + return f"\033[31m{x}\033[0m" + + +def green(x): + if not IS_TTY: + return x + return f"\033[32m{x}\033[0m" + + +def yellow(x): + if not IS_TTY: + return x + return f"\033[33m{x}\033[0m" + + +def blue(x): + if not IS_TTY: + return x + return f"\033[34m{x}\033[0m" diff --git a/tools/lit.py b/tools/lit.py index ff3e498..3648c04 100755 --- a/tools/lit.py +++ b/tools/lit.py @@ -6,30 +6,14 @@ import sys import shlex from pathlib import Path +from fmt import green, yellow, red + ROOT = Path(__file__).parent.parent TOOLS = ROOT / "tools" TARGET_RELEASE = ROOT / "target" / "release" -IS_TTY = sys.stdout.isatty() - -def green(x): - if not IS_TTY: - return x - return f"\033[32m{x}\033[0m" - -def yellow(x): - if not IS_TTY: - return x - return f"\033[33m{x}\033[0m" - -def red(x): - if not IS_TTY: - return x - return f"\033[31m{x}\033[0m" - - def relative(path): return str(Path(path).relative_to(Path.cwd())) -- 2.47.0