Skip to content

Conversation

bolinfest
Copy link
Collaborator

@bolinfest bolinfest commented Oct 8, 2025

No description provided.

Copy link
Collaborator

@nornagon-openai nornagon-openai left a comment

Choose a reason for hiding this comment

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

Firstly, this palette should only be queried on terminals which are not 24-bit capable, which iTerm is, so as written this PR just disables all palette querying.

As such, this will break the user message background color in Terminal.app, which doesn't support true color. On terminals which support 256-color but not 24-bit color, we need to know the color palette of the terminal in order to choose a background color from the indexed palette that is close to the default background color.

FWIW on my machine (admittedly a fancy macbook pro), querying all 256 colors on Terminal.app is somewhere around a few 100 ms. Pretty fast.

There are some other things we could do to hide or reduce this query time:

  1. We could query a subset of the entire 256 color palette, which on Terminal.app on my machine looks like this:
    Image
    we could e.g. only query the 24 grayscale colors near the end of the palette, as they're the most likely to be close to the default background color, instead of all 256 colors. perhaps if we detect a default background color that isn't close to white or black, we can query the whole set.
  2. given the 24 grayscale colors are ordered, we could binary search them to find the closest one to the target bg color, for an average of log₂(24) ~= 5 queries.
  3. we could skip the query altogether and make assumptions about what the palette is. it's probably almost always pretty close to this

Comment on lines +107 to +111
// Many modern GPU terminals ignore OSC, so only perform the query on
// terminals known to support it.
if !codex_core::terminal::user_agent().starts_with("iTerm.app") {
return Ok(None);
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

"ignore OSC" doesn't make sense; there are a large number of OSC codes and different terminals respond to different subsets of them.

@nornagon-openai
Copy link
Collaborator

#4957 is my take on this.

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