Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set ANSIBLE_FORCE_COLOR sooner to fix missing color output in tmux #4145

Merged
merged 1 commit into from
Mar 11, 2024

Conversation

vicnett
Copy link
Contributor

@vicnett vicnett commented Mar 4, 2024

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 when should_do_markup() returned True.

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() returning True at first, but then switching to False once console has been set in console.py, thus moving the code that sets ANSIBLE_FORCE_COLOR if it doesn't exist to before console is set rather than after essentially makes the True "stick" since should_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:

  • Setting my $TERM to containing xterm gives expected colored output, but based on some googling it seems it's preferred to let tmux identify itself as screen-256color as mine does.
  • Funnily, making should_do_markup() check for color in $TERM gave me colored Ansible output, but uncolored molecule output...
  • Making 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-fixed should_do_markup was returning False when PY_COLORS was set or when $TERM included xterm) 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).

@ssbarnea ssbarnea merged commit 12a9972 into ansible:main Mar 11, 2024
14 of 15 checks passed
@vicnett vicnett deleted the fix-color-in-tmux branch March 11, 2024 19:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

2 participants