Add consistent theme-based thread colors across the TUI (#44857)

## What changed

Assign thread colors deterministically from the full thread ID and the active syntax theme's accents. Use the same color for thread names and titles in the status line, status previews, agents overview, and resume/fork pickers, independent of renaming or list order.

Preserve thread colors when picker rows are selected and honor `tui.status_line_use_colors`. Load the configured theme before startup pickers render and refresh the cached palette when the theme changes. Fall back to the terminal's default color when no accents are available.

## Testing

Add unit and snapshot tests for palette extraction and refresh, default accent coverage, selected titles in both picker layouts, color suppression, and preview/footer consistency during automatic naming.

GitOrigin-RevId: 2b83a66bb3e80d4a1daea48ab9a86dbf2b525eef
This commit is contained in:
Eric Traut authored and copyberry committed 2026-09-11 16:20:50 +00:00
1 parent 654b0a77d0
commit 0818b6550b
17 files changed
+398 -19

No files matched your search

+1
View File
@@ -321,6 +321,7 @@ impl App {
&self.app_server_target,
self.environment_manager.as_ref(),
),
self.local_settings.tui.status_line_use_colors,
self.app_event_tx.clone(),
self.keymap.clone(),
Arc::clone(&self.agents_overview.view_state),
@@ -1,5 +1,40 @@
use super::*;
#[tokio::test]
async fn overview_thread_colors_match_footer_and_respect_color_suppression() {
let mut app = make_test_app().await;
let id = ThreadId::from_u128(/*value*/ 42);
let mut snapshot = Vec::new();
for enabled in [true, false] {
app.local_settings.tui.status_line_use_colors = enabled;
let mut thread = overview_thread(
id,
/*parent_thread_id*/ None,
"Original prompt",
ThreadStatus::Idle,
);
thread.name = Some("Named task".into());
let view = app.agents_overview_view(vec![thread], Some(id));
let mut terminal = Terminal::new(TestBackend::new(100, 30)).unwrap();
terminal
.draw(|frame| view.render(frame.area(), frame.buffer_mut()))
.unwrap();
let buffer = terminal.backend().buffer();
for row in buffer.content.chunks(100) {
let text: String = row.iter().map(ratatui::buffer::Cell::symbol).collect();
if let Some(x) = text.find("Named task") {
let x = text[..x].chars().count();
snapshot.push(format!(
"{} | title style: {:?}",
text.trim_end(),
row[x].style()
));
}
}
}
insta::assert_snapshot!(snapshot.join("\n"));
}
#[tokio::test]
async fn older_server_notice_is_visible_in_agents_overview() {
let mut app = make_test_app().await;
@@ -1425,6 +1460,7 @@ async fn shared_overview_shows_only_root_sessions() {
view.rows.clone(),
Some(first_root),
/*worktrees_enabled*/ false,
/*use_theme_colors*/ true,
crate::app_event_sender::AppEventSender::new(event_tx),
app.keymap.clone(),
Arc::clone(&app.agents_overview.view_state),
@@ -1666,6 +1702,7 @@ async fn filtered_dashboard_actions_use_configured_shortcuts() {
.rows,
Some(first),
/*worktrees_enabled*/ false,
/*use_theme_colors*/ true,
crate::app_event_sender::AppEventSender::new(event_tx),
app.keymap.clone(),
Arc::clone(&app.agents_overview.view_state),
+16 -2
View File
@@ -179,6 +179,7 @@ impl AgentsOverviewViewState {
}
pub(super) struct AgentsOverviewView {
use_theme_colors: bool,
pub(super) rows: Vec<AgentsOverviewRow>,
project_groups: Vec<AgentsOverviewProjectGroup>,
selected: usize,
@@ -195,6 +196,7 @@ impl AgentsOverviewView {
rows: Vec<AgentsOverviewRow>,
selected_thread_id: Option<ThreadId>,
worktrees_enabled: bool,
use_theme_colors: bool,
app_event_tx: AppEventSender,
keymap: RuntimeKeymap,
state: Arc<Mutex<AgentsOverviewViewState>>,
@@ -220,6 +222,7 @@ impl AgentsOverviewView {
.map(|row| AgentsOverviewProjectGroup::for_thread(&row.thread, worktrees_enabled))
.collect();
let mut view = Self {
use_theme_colors,
rows,
project_groups,
selected,
@@ -242,6 +245,14 @@ impl AgentsOverviewView {
self.rows.iter().map(|row| row.thread_id).collect()
}
fn title_style(&self, thread_id: ThreadId) -> Style {
if self.use_theme_colors {
Style::default().fg(crate::thread_color::thread_color(thread_id))
} else {
Style::default()
}
}
fn state(&self) -> MutexGuard<'_, AgentsOverviewViewState> {
self.state.lock().unwrap_or_else(PoisonError::into_inner)
}
@@ -439,7 +450,7 @@ impl AgentsOverviewView {
" ".into(),
dot,
" ".into(),
display_title(&row.thread).into(),
Span::styled(display_title(&row.thread), self.title_style(row.thread_id)),
current.dim(),
];
if project_grouping {
@@ -460,7 +471,10 @@ impl AgentsOverviewView {
Line::from("Task details".bold()),
Line::default(),
crate::line_truncation::truncate_line_with_ellipsis_if_overflow(
display_title(&row.thread).to_owned().bold().into(),
Line::from(Span::styled(
display_title(&row.thread).to_owned(),
self.title_style(row.thread_id).bold(),
)),
width,
),
Line::from(vec![dot, " ".into(), status.into()]),
@@ -0,0 +1,8 @@
---
source: tui/src/app/agents_overview_tests.rs
expression: "snapshot.join(\"\\n\")"
---
› ○ Named task Ready │ | title style: Style::new().fg(Color::Rgb(242, 205, 205)).bg(Color::Reset).underline_color(Color::Reset)
│ Named task | title style: Style::new().fg(Color::Rgb(242, 205, 205)).bg(Color::Reset).underline_color(Color::Reset).bold()
› ○ Named task Ready │ | title style: Style::new().fg(Color::Reset).bg(Color::Reset).underline_color(Color::Reset)
│ Named task | title style: Style::new().fg(Color::Reset).bg(Color::Reset).underline_color(Color::Reset).bold()