Set ANSIBLE_FORCE_COLOR sooner to fix missing color output in tmux #4145
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What
This fixes a strange issue of missing colored output I was experiencing when using tmux by moving code to set the
ANSIBLE_FORCE_COLOR
environment variable if it didn't already exist whenshould_do_markup()
returnedTrue
.Why
I was going insane investigating why I wasn't getting colored output in my normal environment, but got it just fine when I tried it without outside of tmux.
I've narrowed it down to
should_do_markup()
returningTrue
at first, but then switching toFalse
onceconsole
has been set inconsole.py
, thus moving the code that setsANSIBLE_FORCE_COLOR
if it doesn't exist to beforeconsole
is set rather than after essentially makes theTrue
"stick" sinceshould_do_markup()
checks for it. This presumably should have no effect outside of fixing my issue, although I admittedly still don't know what actually caused it so what do I know...Other things I've tried:
$TERM
to containingxterm
gives expected colored output, but based on some googling it seems it's preferred to let tmux identify itself asscreen-256color
as mine does.should_do_markup()
check forcolor
in$TERM
gave me colored Ansible output, but uncolored molecule output...should_do_markup()
a boolean instead of a function, and setting it once using the same function code it currently has. This worked, but some tests were failing (apparently the now-fixedshould_do_markup
was returningFalse
whenPY_COLORS
was set or when$TERM
includedxterm
) and I quickly gave up figuring out why...Testing
I just did a full run of
tox
on my branch and everything passed 🎉I didn't add any tests because my change only moved a code block up within the same file, and this functionality is already well covered in existing tests (which, again, still pass).