From 415da54e6737402d69658d40ec7b7df8cefae672 Mon Sep 17 00:00:00 2001 From: Sviatoslav Sydorenko Date: Thu, 1 Aug 2024 23:15:21 +0200 Subject: [PATCH] Support terminals that implement `truecolor` --- lib/ansible/constants.py | 8 ++++++++ test/lib/ansible_test/_internal/delegation.py | 7 +++++++ test/lib/ansible_test/_internal/util.py | 7 +++++++ 3 files changed, 22 insertions(+) diff --git a/lib/ansible/constants.py b/lib/ansible/constants.py index c2ce7e5ec9d..96916aae2d5 100644 --- a/lib/ansible/constants.py +++ b/lib/ansible/constants.py @@ -4,6 +4,7 @@ from __future__ import annotations +import os import re from string import ascii_letters, digits @@ -60,6 +61,13 @@ COLOR_CODES = { 'magenta': u'0;35', 'bright magenta': u'1;35', 'normal': u'0', } +COLOR_CODES = { + name: + str(int(re.search(r'1;(?P3\d)', ansi_seq).group('color_code')) + 60) + if os.getenv('COLORTERM') == 'truecolor' and '1;3' in ansi_seq + else ansi_seq + for name, ansi_seq in COLOR_CODES.items() +} REJECT_EXTS = ['.pyc', '.pyo', '.swp', '.bak', '~', '.rpm', '.md', '.txt', '.rst'] # this is concatenated with other config settings as lists; cannot be tuple BOOL_TRUE = BOOLEANS_TRUE COLLECTION_PTYPE_COMPAT = {'module': 'modules'} diff --git a/test/lib/ansible_test/_internal/delegation.py b/test/lib/ansible_test/_internal/delegation.py index 74c4adbfc6a..ce1f05d098e 100644 --- a/test/lib/ansible_test/_internal/delegation.py +++ b/test/lib/ansible_test/_internal/delegation.py @@ -293,6 +293,13 @@ def generate_command( ANSIBLE_TEST_CONTENT_ROOT=content_root, ) + if color_term := os.getenv('COLORTERM'): + # NOTE: The current terminal emulator may have this set to `truecolor` + # NOTE: which is important for setting different color defaults. This + # NOTE: may be evident in Kitty that does not interpret the bold ANSI + # NOTE: marker as bright like some of the others. + env_vars['COLORTERM'] = color_term + if isinstance(args.controller, OriginConfig): # Expose the ansible and ansible_test library directories to the Python environment. # This is only required when delegation is used on the origin host. diff --git a/test/lib/ansible_test/_internal/util.py b/test/lib/ansible_test/_internal/util.py index 1da631a0b5f..407cdb0994a 100644 --- a/test/lib/ansible_test/_internal/util.py +++ b/test/lib/ansible_test/_internal/util.py @@ -733,6 +733,13 @@ def common_environment() -> dict[str, str]: env.update(pass_vars(required=required, optional=optional)) + if color_term := os.getenv('COLORTERM'): + # NOTE: The current terminal emulator may have this set to `truecolor` + # NOTE: which is important for setting different color defaults. This + # NOTE: may be evident in Kitty that does not interpret the bold ANSI + # NOTE: marker as bright like some of the others. + env['COLORTERM'] = color_term + return env