Do not output colors when redirecting output

This commit is contained in:
Yuri D'Elia 2021-04-23 12:26:15 +02:00
parent 8b5d01e3b1
commit 2e6e2c4fde
1 changed files with 10 additions and 4 deletions

View File

@ -15,12 +15,18 @@
"""Check lang files."""
from argparse import ArgumentParser
from traceback import print_exc
from sys import stderr
from sys import stdout, stderr
import textwrap
red = lambda text: '\033[0;31m' + text + '\033[0m'
green = lambda text: '\033[0;32m' + text + '\033[0m'
yellow = lambda text: '\033[0;33m' + text + '\033[0m'
def color_maybe(color_attr, text):
if stdout.isatty():
return '\033[0;' + str(color_attr) + 'm' + text + '\033[0m'
else:
return text
red = lambda text: color_maybe(31, text)
green = lambda text: color_maybe(32, text)
yellow = lambda text: color_maybe(33, text)
def parse_txt(lang, no_warning):
"""Parse txt file and check strings to display definition."""