From 7bdc71b53bee8077216d367855b1932d2cfa2309 Mon Sep 17 00:00:00 2001 From: Roland Walker Date: Sat, 14 Feb 2026 06:28:55 -0500 Subject: [PATCH] support truecolor in prompt_toolkit sessions Support truecolor in prompt_toolkit sessions if the environment variable COLORTERM contains "truecolor"; otherwise fall back to 8-bit color depth, the prompt_tookit default. --- changelog.md | 1 + mycli/main.py | 2 ++ 2 files changed, 3 insertions(+) diff --git a/changelog.md b/changelog.md index 04e6b391..c2ab70bc 100644 --- a/changelog.md +++ b/changelog.md @@ -9,6 +9,7 @@ Features * Optionally defer auto-completions until a minimum number of characters is typed. * Make the completion interface more responsive using a background thread. * Option to suppress control-d exit behavior. +* Better support Truecolor terminals. Bug Fixes diff --git a/mycli/main.py b/mycli/main.py index 397b83e7..f099f100 100755 --- a/mycli/main.py +++ b/mycli/main.py @@ -42,6 +42,7 @@ from prompt_toolkit.key_binding.key_processor import KeyPressEvent from prompt_toolkit.layout.processors import ConditionalProcessor, HighlightMatchingBracketProcessor from prompt_toolkit.lexers import PygmentsLexer +from prompt_toolkit.output import ColorDepth from prompt_toolkit.shortcuts import CompleteStyle, PromptSession import pymysql from pymysql.constants.ER import HANDSHAKE_ERROR @@ -1168,6 +1169,7 @@ def one_iteration(text: str | None = None) -> None: editing_mode = EditingMode.EMACS self.prompt_app = PromptSession( + color_depth=ColorDepth.DEPTH_24_BIT if 'truecolor' in os.getenv('COLORTERM', '').lower() else None, lexer=PygmentsLexer(MyCliLexer), reserve_space_for_menu=self.get_reserved_space(), message=get_message,