From 05e3fdf5e9d9294fa0fbfbf4ac0b57024f75d00f 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/ansible_util.py | 2 ++ 2 files changed, 10 insertions(+) diff --git a/lib/ansible/constants.py b/lib/ansible/constants.py index 5e5799c1326..4199de78d8b 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 @@ -117,6 +118,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') BOOL_TRUE = BOOLEANS_TRUE COLLECTION_PTYPE_COMPAT = {'module': 'modules'} diff --git a/test/lib/ansible_test/_internal/ansible_util.py b/test/lib/ansible_test/_internal/ansible_util.py index c2d363506b3..f63a9c2b872 100644 --- a/test/lib/ansible_test/_internal/ansible_util.py +++ b/test/lib/ansible_test/_internal/ansible_util.py @@ -118,6 +118,8 @@ def ansible_environment(args: CommonConfig, color: bool = True, ansible_config: # ansible-test specific environment variables require an 'ANSIBLE_TEST_' prefix to distinguish them from ansible-core env vars defined by config ANSIBLE_TEST_ANSIBLE_LIB_ROOT=ANSIBLE_LIB_ROOT, # used by the coverage injector ) + if color_term := os.getenv('COLORTERM'): + ansible['COLORTERM'] = color_term if isinstance(args, IntegrationConfig) and args.coverage: # standard path injection is not effective for the persistent connection helper, instead the location must be configured