Skip to content

Support Truecolor in prompt_toolkit sessions#1550

Merged
rolandwalker merged 1 commit intomainfrom
RW/support-truecolor-prompt-toolkit
Feb 16, 2026
Merged

Support Truecolor in prompt_toolkit sessions#1550
rolandwalker merged 1 commit intomainfrom
RW/support-truecolor-prompt-toolkit

Conversation

@rolandwalker
Copy link
Contributor

Description

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.

I must admit that between this and dbcli/cli_helpers#102 I cannot yet see a difference. But there was a request for it, which is reasonable.

It would be great if someone attached some screenshots showing the difference.

Checklist

  • I added this contribution to the changelog.md file.
  • I added my name to the AUTHORS file (or it's already there).
  • To lint and format the code, I ran
    uv run ruff check && uv run ruff format && uv run mypy --install-types .

@rolandwalker rolandwalker self-assigned this Feb 14, 2026
Copy link
Contributor

@scottnemes scottnemes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Think you'd have to being using gradients or similar to be able to notice this, so it's a pretty niche use case from what I can gather anyway.

@rolandwalker rolandwalker force-pushed the RW/support-truecolor-prompt-toolkit branch from 3478134 to d5ec82a Compare February 16, 2026 09:12
@github-actions
Copy link

Findings

  1. Potential regression: forcing 8‑bit color when COLORTERM isn’t set
    PromptSession will now always get ColorDepth.DEPTH_8_BIT unless COLORTERM contains truecolor. That can downgrade users whose terminals support truecolor but don’t export COLORTERM, and it also bypasses prompt_toolkit’s own autodetection if it improves in newer versions.
    File: mycli/main.py:1172
    Suggestion: fall back to ColorDepth.DEPTH_DEFAULT (or omit color_depth) when COLORTERM doesn’t indicate truecolor. Example:

    • color_depth = ColorDepth.DEPTH_24_BIT if is_truecolor else ColorDepth.DEPTH_DEFAULT
  2. Case‑sensitivity and variant strings
    The check is case‑sensitive and only matches truecolor. Common variants include TrueColor, TRUECOLOR, and 24bit.
    File: mycli/main.py:1172
    Suggestion: normalize and handle 24bit, e.g. val = os.getenv("COLORTERM","").lower() and check for "truecolor" or "24bit".

Missing tests / edge cases

  • No tests cover the COLORTERM logic. Add a small unit test around the session creation logic (or a helper) to confirm:
    • COLORTERM=truecolor → 24‑bit
    • COLORTERM=24bit → 24‑bit
    • COLORTERM unset / empty / mixed‑case → default behavior (not forced to 8‑bit)

If you want, I can propose a minimal refactor to make this testable without integration testing.

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.
@rolandwalker rolandwalker force-pushed the RW/support-truecolor-prompt-toolkit branch from d5ec82a to 7bdc71b Compare February 16, 2026 09:16
@github-actions
Copy link

Findings (ordered by severity)

  1. Potential compatibility edge case: PromptSession(..., color_depth=...) is passed None when COLORTERM doesn’t include truecolor. If the installed prompt_toolkit version doesn’t accept None for color_depth, this will raise at runtime. Consider omitting the parameter entirely in that case, or passing the explicit default enum. File: mycli/main.py:1169.

  2. Edge case: Some terminals advertise truecolor via COLORTERM=24bit (or truecolour). Current check only looks for truecolor, so those users won’t get 24‑bit even if supported. Consider matching both truecolor and 24bit (and maybe truecolour). File: mycli/main.py:1169.

Missing tests / coverage

  1. There are no tests covering the COLORTERM detection logic. A small unit test that patches os.environ to verify color_depth selection would guard against regressions. File: mycli/main.py:1169.

I didn’t run tests.

If you want, I can draft a minimal test and adjust the detection logic.

@rolandwalker rolandwalker merged commit 2031dc0 into main Feb 16, 2026
10 checks passed
@rolandwalker rolandwalker deleted the RW/support-truecolor-prompt-toolkit branch February 16, 2026 09:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants