Skip to content

Commit

Permalink
Add --color option to file_parser.py to force color output
Browse files Browse the repository at this point in the history
  • Loading branch information
julianneswinoga committed Mar 11, 2023
1 parent 1f0363c commit ce98e98
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions tracex_parser/file_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
help='Path to the input trx file(s) that contains TraceX event data')
parser.add_argument('-v', '--verbose', action='count', default=0,
help='Set the verbosity of logging')
parser.add_argument('-n', '--nocolor', action='store_true', help='Do not add color to the output')
parser.add_argument('-n', '--nocolor', action='store_true', help='Never color the output')
parser.add_argument('-c', '--color', action='store_true', help='Always color the output')


def get_endian_str(buf: bytes) -> Tuple[str, int]:
Expand Down Expand Up @@ -211,6 +212,18 @@ def main():
signal(SIGPIPE, SIG_DFL)

# set up colours
have_colours = sys.stdout.isatty() and not args.nocolor
# Truth table for what we want.
# Precedence is: color, nocolor, tty
# tty | nocolor | color | output
# ==============================
# 0 | 0 | 0 | 0
# 0 | 0 | 1 | 1
# 0 | 1 | 0 | 1
# 0 | 1 | 1 | 1
# 1 | 0 | 0 | 1
# 1 | 0 | 1 | 1
# 1 | 1 | 0 | 0
# 1 | 1 | 1 | 1
have_colours = (sys.stdout.isatty() and not args.nocolor) or args.color
colour = TextColour(have_colours)
main()

0 comments on commit ce98e98

Please sign in to comment.