Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions codex-rs/tui/src/terminal_palette.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ mod imp {
use std::sync::Mutex;
use std::sync::OnceLock;

const TERMINAL_QUERIES_ENABLED: bool = false;
Copy link
Collaborator

Choose a reason for hiding this comment

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

If query_terminal_palette() is really the issue, then I would rather exit early there.

Rather than categorically disable, we could call:

fn detect_terminal() -> String {

and if that value isn't a "known fast" terminal (like iTerm), then we return Err?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe check if the value from detect_terminal() starts with "iTerm.app" for now?

It's nice not to have unreachable code sitting around.


struct Cache<T> {
attempted: bool,
value: Option<T>,
Expand Down Expand Up @@ -70,6 +72,9 @@ mod imp {
}

pub(super) fn terminal_palette() -> Option<[(u8, u8, u8); 256]> {
if !TERMINAL_QUERIES_ENABLED {
return None;
}
static CACHE: OnceLock<Option<[(u8, u8, u8); 256]>> = OnceLock::new();
*CACHE.get_or_init(|| match query_terminal_palette() {
Ok(Some(palette)) => Some(palette),
Expand All @@ -78,12 +83,18 @@ mod imp {
}

pub(super) fn default_colors() -> Option<DefaultColors> {
if !TERMINAL_QUERIES_ENABLED {
return None;
}
let cache = default_colors_cache();
let mut cache = cache.lock().ok()?;
cache.get_or_init_with(|| query_default_colors().unwrap_or_default())
}

pub(super) fn requery_default_colors() {
if !TERMINAL_QUERIES_ENABLED {
return;
}
if let Ok(mut cache) = default_colors_cache().lock() {
cache.refresh_with(|| query_default_colors().unwrap_or_default());
}
Expand Down
Loading