Skip to content

Commit

Permalink
Enable PWNLIB_COLOR=always environment variable (#1816)
Browse files Browse the repository at this point in the history
This allows piping with color into tools like ansifilter, which take
ANSI-escape-coded colorized text and emits data in other formats,
notably HTML.

This is useful for writing blog posts with PWNLIB_DEBUG=1 to display
hex-dumped data written to stdout that would not normally be colorized.

Currently this ONLY works for the environment variable PWNLIB_COLOR,
and does not make use of pwnlib.args due to cyclic imports.
  • Loading branch information
heapcrash committed Feb 25, 2021
1 parent cc42100 commit 8f8adf7
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion pwnlib/term/text.py
Expand Up @@ -2,6 +2,7 @@
from __future__ import division

import functools
import os
import sys
import types

Expand All @@ -11,7 +12,7 @@
def eval_when(when):
if hasattr(when, 'isatty') or \
when in ('always', 'never', 'auto', sys.stderr, sys.stdout):
if when == 'always':
if os.environ.get('PWNLIB_COLOR') == 'always' or when == 'always':
return True
elif when == 'never':
return False
Expand Down

0 comments on commit 8f8adf7

Please sign in to comment.