//! Theme-derived styling for the configurable footer statusline. use ratatui::style::Color; use ratatui::style::Style; use ratatui::style::Styled; use ratatui::text::Span; use super::status_line_setup::StatusLineItem; use crate::render::highlight::foreground_style_for_scopes; use crate::style::readable_color_on; use crate::style::secondary_text_style; use crate::terminal_hyperlinks::HyperlinkLine; use crate::terminal_palette::StdoutColorLevel; use crate::terminal_palette::effective_stdout_color_level; use crate::thread_color::thread_color; use akode_protocol::ThreadId; pub(crate) const STATUS_LINE_SEPARATOR: &str = " · "; const STATUS_LINE_COLOR_SATURATION_PERCENT: u16 = 85; const STATUS_LINE_COLOR_BRIGHTNESS_PERCENT: u16 = 100; #[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, serde::Deserialize, serde::Serialize)] pub(crate) enum StatusLineAccent { #[serde(rename = "status-model")] Model, #[serde(rename = "status-path")] Path, #[serde(rename = "status-branch")] Branch, #[serde(rename = "status-state")] State, #[serde(rename = "status-usage")] Usage, #[serde(rename = "status-limit")] Limit, #[serde(rename = "status-metadata")] Metadata, #[serde(rename = "status-mode")] Mode, #[serde(rename = "status-thread")] Thread, #[serde(rename = "status-progress")] Progress, } impl StatusLineAccent { fn for_item(item: StatusLineItem) -> Self { match item { StatusLineItem::ModelName | StatusLineItem::ModelWithReasoning | StatusLineItem::Provider | StatusLineItem::Reasoning => Self::Model, StatusLineItem::CurrentDir | StatusLineItem::ProjectRoot => Self::Path, StatusLineItem::GitBranch | StatusLineItem::PullRequestNumber | StatusLineItem::BranchChanges => Self::Branch, StatusLineItem::Status => Self::State, StatusLineItem::ContextRemaining | StatusLineItem::ContextUsed | StatusLineItem::ContextWindowSize | StatusLineItem::UsedTokens | StatusLineItem::TotalInputTokens | StatusLineItem::TotalOutputTokens => Self::Usage, StatusLineItem::FiveHourLimit | StatusLineItem::WeeklyLimit => Self::Limit, StatusLineItem::CodexVersion | StatusLineItem::Hostname | StatusLineItem::SessionId | StatusLineItem::Profile => Self::Metadata, StatusLineItem::FastMode | StatusLineItem::RawOutput => Self::Mode, StatusLineItem::Permissions => Self::Mode, StatusLineItem::ApprovalMode => Self::Mode, StatusLineItem::ThreadName | StatusLineItem::ThreadTitle => Self::Thread, StatusLineItem::TaskProgress => Self::Progress, } } pub(crate) fn scopes(self) -> &'static [&'static str] { match self { Self::Model => &["entity.name.type", "support.type", "variable"], Self::Path => &["string", "markup.underline.link"], Self::Branch => &["entity.name.function", "entity.name.tag"], Self::State => &["keyword.control", "keyword"], Self::Usage => &["constant.numeric", "constant"], Self::Limit => &["constant.language", "storage.type"], Self::Metadata => &["comment", "constant.other"], Self::Mode => &["storage.modifier", "keyword.operator"], Self::Thread => &["markup.heading", "entity.name.section"], Self::Progress => &["markup.inserted", "constant.numeric"], } } pub(crate) fn fallback_color(self) -> Color { match self { Self::Model | Self::State | Self::Metadata | Self::Mode => Color::Cyan, Self::Path | Self::Usage | Self::Progress => Color::Green, Self::Branch | Self::Limit | Self::Thread => Color::Magenta, } } } pub(crate) fn status_line_from_segments( segments: I, use_theme_colors: bool, thread_id: Option, pull_request_url: Option<&str>, ) -> Option where I: IntoIterator, { status_line_from_segments_with_resolver( segments, use_theme_colors, thread_id, pull_request_url, |accent| foreground_style_for_scopes(accent.scopes()), ) } fn status_line_from_segments_with_resolver( segments: I, use_theme_colors: bool, thread_id: Option, pull_request_url: Option<&str>, theme_style_for_accent: F, ) -> Option where I: IntoIterator, F: Fn(StatusLineAccent) -> Option