Rinomina: crate akode-*, cartelle akode-rs/ e akode-cli/, binario akode, ~/.akode, AKODE_* (A)
Riapplica la fase 5 di aKode (86e7c72e) sulla base ripulita:
- crate codex-* -> akode-*, codex-rs -> akode-rs, codex-cli -> akode-cli, binario e ausiliari akode;
- ~/.codex -> ~/.akode, CODEX_HOME -> AKODE_HOME, variabili CODEX_* -> AKODE_*, .codex/ -> .akode/ di progetto;
nessun fallback a ~/.codex o a CODEX_*;
- testi per l'utente "Codex" -> "aKode"; testi verso il modello e istruzioni di sistema invariati;
- snapshot insta rinominati (non ancora rigenerati).
I conflitti con la base ripulita sono stati risolti riapplicando la rinomina ai file senza le
funzioni di imeAI (script di mappa dei token per file).
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
493
akode-rs/tui/src/bottom_pane/status_line_style.rs
Normal file
493
akode-rs/tui/src/bottom_pane/status_line_style.rs
Normal file
@@ -0,0 +1,493 @@
|
||||
//! 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<I>(
|
||||
segments: I,
|
||||
use_theme_colors: bool,
|
||||
thread_id: Option<ThreadId>,
|
||||
pull_request_url: Option<&str>,
|
||||
) -> Option<HyperlinkLine>
|
||||
where
|
||||
I: IntoIterator<Item = (StatusLineItem, String)>,
|
||||
{
|
||||
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<I, F>(
|
||||
segments: I,
|
||||
use_theme_colors: bool,
|
||||
thread_id: Option<ThreadId>,
|
||||
pull_request_url: Option<&str>,
|
||||
theme_style_for_accent: F,
|
||||
) -> Option<HyperlinkLine>
|
||||
where
|
||||
I: IntoIterator<Item = (StatusLineItem, String)>,
|
||||
F: Fn(StatusLineAccent) -> Option<Style>,
|
||||
{
|
||||
let mut line = HyperlinkLine::default();
|
||||
for (item, mut text) in segments {
|
||||
// Paragraph skips control characters, so they must not enter this single row's link offsets.
|
||||
text.retain(|ch| !ch.is_control());
|
||||
if !line.line.spans.is_empty() {
|
||||
line.line
|
||||
.push_span(STATUS_LINE_SEPARATOR.set_style(secondary_text_style()));
|
||||
}
|
||||
let style = if use_theme_colors
|
||||
&& matches!(
|
||||
item,
|
||||
StatusLineItem::ThreadName | StatusLineItem::ThreadTitle
|
||||
)
|
||||
&& let Some(thread_id) = thread_id
|
||||
{
|
||||
Style::default().fg(thread_color(thread_id))
|
||||
} else if use_theme_colors {
|
||||
let accent = StatusLineAccent::for_item(item);
|
||||
soften_status_line_style(
|
||||
theme_style_for_accent(accent)
|
||||
.unwrap_or_else(|| Style::default().fg(accent.fallback_color())),
|
||||
)
|
||||
} else {
|
||||
secondary_text_style()
|
||||
};
|
||||
let style = if use_theme_colors {
|
||||
let foreground = style.fg.unwrap_or(Color::Reset);
|
||||
if effective_stdout_color_level() == StdoutColorLevel::Ansi16
|
||||
&& matches!(foreground, Color::Rgb(..) | Color::Indexed(16..))
|
||||
{
|
||||
style.fg(StatusLineAccent::for_item(item).fallback_color())
|
||||
} else {
|
||||
style.fg(readable_color_on(foreground, /*background*/ None))
|
||||
}
|
||||
} else {
|
||||
style
|
||||
};
|
||||
if item == StatusLineItem::PullRequestNumber {
|
||||
line.push_span(Span::styled(text, style.underlined()), pull_request_url);
|
||||
} else {
|
||||
line.line.push_span(Span::styled(text, style));
|
||||
}
|
||||
}
|
||||
|
||||
(!line.line.spans.is_empty()).then_some(line)
|
||||
}
|
||||
|
||||
fn soften_status_line_style(mut style: Style) -> Style {
|
||||
if let Some(fg) = style.fg {
|
||||
style.fg = Some(soften_status_line_color(fg));
|
||||
}
|
||||
style
|
||||
}
|
||||
|
||||
#[allow(clippy::disallowed_methods)]
|
||||
fn soften_status_line_color(color: Color) -> Color {
|
||||
match color {
|
||||
Color::Rgb(r, g, b) => {
|
||||
let luma = weighted_luma(r, g, b);
|
||||
Color::Rgb(
|
||||
soften_rgb_channel(r, luma),
|
||||
soften_rgb_channel(g, luma),
|
||||
soften_rgb_channel(b, luma),
|
||||
)
|
||||
}
|
||||
Color::LightRed => Color::Red,
|
||||
Color::LightGreen => Color::Green,
|
||||
Color::LightYellow => Color::Yellow,
|
||||
Color::LightBlue => Color::Blue,
|
||||
Color::LightMagenta => Color::Magenta,
|
||||
Color::LightCyan => Color::Cyan,
|
||||
Color::White => Color::Gray,
|
||||
Color::Reset
|
||||
| Color::Black
|
||||
| Color::Red
|
||||
| Color::Green
|
||||
| Color::Yellow
|
||||
| Color::Blue
|
||||
| Color::Magenta
|
||||
| Color::Cyan
|
||||
| Color::Gray
|
||||
| Color::DarkGray
|
||||
| Color::Indexed(_) => color,
|
||||
}
|
||||
}
|
||||
|
||||
fn weighted_luma(r: u8, g: u8, b: u8) -> u16 {
|
||||
(77 * u16::from(r) + 150 * u16::from(g) + 29 * u16::from(b)) / 256
|
||||
}
|
||||
|
||||
fn soften_rgb_channel(channel: u8, luma: u16) -> u8 {
|
||||
let channel = u16::from(channel);
|
||||
let softened = (channel * STATUS_LINE_COLOR_SATURATION_PERCENT
|
||||
+ luma * (100 - STATUS_LINE_COLOR_SATURATION_PERCENT)
|
||||
+ 50)
|
||||
/ 100;
|
||||
|
||||
((softened * STATUS_LINE_COLOR_BRIGHTNESS_PERCENT + 50) / 100) as u8
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use pretty_assertions::assert_eq;
|
||||
use ratatui::style::Modifier;
|
||||
use ratatui::text::Line;
|
||||
|
||||
fn line_text(line: &Line<'static>) -> String {
|
||||
line.spans
|
||||
.iter()
|
||||
.map(|span| span.content.as_ref())
|
||||
.collect::<String>()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn status_line_segments_preserve_order_and_plain_text() {
|
||||
let line = status_line_from_segments_with_resolver(
|
||||
[
|
||||
(StatusLineItem::ModelName, "gpt-5".to_string()),
|
||||
(StatusLineItem::CurrentDir, "/repo".to_string()),
|
||||
(StatusLineItem::GitBranch, "main".to_string()),
|
||||
],
|
||||
/*use_theme_colors*/ true,
|
||||
/*thread_id*/ None,
|
||||
/*pull_request_url*/ None,
|
||||
|_| None,
|
||||
)
|
||||
.expect("status line")
|
||||
.line;
|
||||
|
||||
assert_eq!(line_text(&line), "gpt-5 · /repo · main");
|
||||
assert_eq!(line.spans[0].style.fg, Some(Color::Cyan));
|
||||
assert!(!line.spans[0].style.add_modifier.contains(Modifier::DIM));
|
||||
assert_eq!(line.spans[2].style.fg, Some(Color::Green));
|
||||
assert!(!line.spans[2].style.add_modifier.contains(Modifier::DIM));
|
||||
assert_eq!(line.spans[4].style.fg, Some(Color::Magenta));
|
||||
assert!(!line.spans[4].style.add_modifier.contains(Modifier::DIM));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn status_line_segments_use_secondary_separators_and_theme_styles_first() {
|
||||
let line = status_line_from_segments_with_resolver(
|
||||
[
|
||||
(StatusLineItem::ModelName, "gpt-5".to_string()),
|
||||
(StatusLineItem::ContextUsed, "Context 12% used".to_string()),
|
||||
],
|
||||
/*use_theme_colors*/ true,
|
||||
/*thread_id*/ None,
|
||||
/*pull_request_url*/ None,
|
||||
|accent| match accent {
|
||||
StatusLineAccent::Model => Some(Style::default().red()),
|
||||
_ => None,
|
||||
},
|
||||
)
|
||||
.expect("status line")
|
||||
.line;
|
||||
|
||||
assert_eq!(line.spans[0].style.fg, Some(Color::Red));
|
||||
assert!(!line.spans[0].style.add_modifier.contains(Modifier::DIM));
|
||||
assert_eq!(line.spans[1].style, secondary_text_style());
|
||||
assert_eq!(line.spans[2].style.fg, Some(Color::Green));
|
||||
assert!(!line.spans[2].style.add_modifier.contains(Modifier::DIM));
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[allow(clippy::disallowed_methods)]
|
||||
fn status_line_segments_soften_rgb_theme_styles_without_dimming_text() {
|
||||
let colors = crate::terminal_probe::DefaultColors {
|
||||
fg: (255, 255, 255),
|
||||
bg: (0, 0, 0),
|
||||
};
|
||||
crate::terminal_palette::with_test_default_colors(colors, || {
|
||||
let line = status_line_from_segments_with_resolver(
|
||||
[(StatusLineItem::ModelName, "gpt-5".to_string())],
|
||||
/*use_theme_colors*/ true,
|
||||
/*thread_id*/ None,
|
||||
/*pull_request_url*/ None,
|
||||
|_| Some(Style::default().fg(Color::Rgb(255, 0, 0))),
|
||||
)
|
||||
.expect("status line")
|
||||
.line;
|
||||
|
||||
assert_eq!(
|
||||
line.spans[0].style.fg,
|
||||
Some(readable_color_on(
|
||||
Color::Rgb(228, 11, 11),
|
||||
/*background*/ None
|
||||
))
|
||||
);
|
||||
assert!(!line.spans[0].style.add_modifier.contains(Modifier::DIM));
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn status_line_segments_can_disable_theme_colors() {
|
||||
let line = status_line_from_segments_with_resolver(
|
||||
[
|
||||
(StatusLineItem::ModelName, "gpt-5".to_string()),
|
||||
(StatusLineItem::ContextUsed, "Context 12% used".to_string()),
|
||||
],
|
||||
/*use_theme_colors*/ false,
|
||||
/*thread_id*/ None,
|
||||
/*pull_request_url*/ None,
|
||||
|_| Some(Style::default().red()),
|
||||
)
|
||||
.expect("status line")
|
||||
.line;
|
||||
|
||||
assert_eq!(line_text(&line), "gpt-5 · Context 12% used");
|
||||
assert_eq!(line.spans[0].style, secondary_text_style());
|
||||
assert_eq!(line.spans[1].style, secondary_text_style());
|
||||
assert_eq!(line.spans[2].style, secondary_text_style());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn pull_request_number_uses_link_style() {
|
||||
let line = status_line_from_segments_with_resolver(
|
||||
[(StatusLineItem::PullRequestNumber, "PR #20252".to_string())],
|
||||
/*use_theme_colors*/ false,
|
||||
/*thread_id*/ None,
|
||||
/*pull_request_url*/ None,
|
||||
|_| None,
|
||||
)
|
||||
.expect("status line")
|
||||
.line;
|
||||
|
||||
assert_eq!(line.spans[0].style, secondary_text_style().underlined());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn status_line_segments_return_none_when_empty() {
|
||||
assert_eq!(
|
||||
status_line_from_segments_with_resolver(
|
||||
Vec::<(StatusLineItem, String)>::new(),
|
||||
/*use_theme_colors*/ true,
|
||||
/*thread_id*/ None,
|
||||
/*pull_request_url*/ None,
|
||||
|_| None,
|
||||
),
|
||||
None
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn light_status_line_corrects_pale_custom_theme_colors() {
|
||||
use ratatui::buffer::Buffer;
|
||||
use ratatui::layout::Rect;
|
||||
use ratatui::widgets::Widget;
|
||||
|
||||
let colors = crate::terminal_probe::DefaultColors {
|
||||
fg: (30, 30, 30),
|
||||
bg: (255, 255, 255),
|
||||
};
|
||||
crate::terminal_palette::with_test_default_colors(colors, || {
|
||||
let line = status_line_from_segments_with_resolver(
|
||||
[
|
||||
(StatusLineItem::ModelName, "gpt-5".to_string()),
|
||||
(StatusLineItem::CurrentDir, "~/code".to_string()),
|
||||
(
|
||||
StatusLineItem::Permissions,
|
||||
"Custom permissions".to_string(),
|
||||
),
|
||||
],
|
||||
/*use_theme_colors*/ true,
|
||||
/*thread_id*/ None,
|
||||
/*pull_request_url*/ None,
|
||||
|accent| {
|
||||
let rgb = match accent {
|
||||
StatusLineAccent::Model => (240, 210, 160),
|
||||
StatusLineAccent::Path => (190, 230, 180),
|
||||
_ => (215, 180, 240),
|
||||
};
|
||||
Some(Style::default().fg(crate::terminal_palette::rgb_color(rgb)))
|
||||
},
|
||||
)
|
||||
.expect("status line")
|
||||
.line;
|
||||
let area = Rect::new(
|
||||
/*x*/ 0, /*y*/ 0, /*width*/ 42, /*height*/ 1,
|
||||
);
|
||||
let mut buffer = Buffer::empty(area);
|
||||
line.render(area, &mut buffer);
|
||||
insta::assert_snapshot!(format!("{buffer:?}"));
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn status_line_theme_colors_at_limited_color_depths() {
|
||||
use ratatui::buffer::Buffer;
|
||||
use ratatui::layout::Rect;
|
||||
use ratatui::widgets::Widget;
|
||||
|
||||
const CHILD: &str = "AKODE_STATUS_LINE_COLOR_TEST_CHILD";
|
||||
let Ok(level) = std::env::var(CHILD) else {
|
||||
for level in ["0", "1"] {
|
||||
let output = std::process::Command::new(std::env::current_exe().unwrap())
|
||||
.args([
|
||||
"--exact",
|
||||
"bottom_pane::status_line_style::tests::status_line_theme_colors_at_limited_color_depths",
|
||||
])
|
||||
.env(CHILD, level)
|
||||
.env("FORCE_COLOR", level)
|
||||
.output()
|
||||
.unwrap();
|
||||
assert!(
|
||||
output.status.success(),
|
||||
"level {level}: {}\n{}",
|
||||
String::from_utf8_lossy(&output.stdout),
|
||||
String::from_utf8_lossy(&output.stderr)
|
||||
);
|
||||
}
|
||||
return;
|
||||
};
|
||||
let theme = crate::render::highlight::resolve_theme_by_name(
|
||||
"coldark-dark",
|
||||
/*codex_home*/ None,
|
||||
)
|
||||
.unwrap();
|
||||
crate::render::highlight::set_syntax_theme(theme);
|
||||
let line = status_line_from_segments(
|
||||
[
|
||||
(StatusLineItem::ModelName, "gpt-5".to_string()),
|
||||
(StatusLineItem::CurrentDir, "~/code".to_string()),
|
||||
(StatusLineItem::UsedTokens, "12k tokens".to_string()),
|
||||
],
|
||||
/*use_theme_colors*/ true,
|
||||
/*thread_id*/ None,
|
||||
/*pull_request_url*/ None,
|
||||
)
|
||||
.expect("status line")
|
||||
.line;
|
||||
if level == "0" {
|
||||
assert_eq!(
|
||||
line.spans
|
||||
.iter()
|
||||
.map(|span| span.style.fg)
|
||||
.collect::<Vec<_>>(),
|
||||
vec![Some(Color::Reset); line.spans.len()]
|
||||
);
|
||||
} else {
|
||||
let area = Rect::new(
|
||||
/*x*/ 0, /*y*/ 0, /*width*/ 30, /*height*/ 1,
|
||||
);
|
||||
let mut buffer = Buffer::empty(area);
|
||||
line.render(area, &mut buffer);
|
||||
insta::assert_snapshot!(format!("{buffer:?}"), @r###"
|
||||
Buffer {
|
||||
area: Rect { x: 0, y: 0, width: 30, height: 1 },
|
||||
content: [
|
||||
"gpt-5 · ~/code · 12k tokens ",
|
||||
],
|
||||
styles: [
|
||||
x: 0, y: 0, fg: Cyan, bg: Reset, underline: Reset, modifier: NONE,
|
||||
x: 5, y: 0, fg: Reset, bg: Reset, underline: Reset, modifier: NONE,
|
||||
x: 8, y: 0, fg: Green, bg: Reset, underline: Reset, modifier: NONE,
|
||||
x: 14, y: 0, fg: Reset, bg: Reset, underline: Reset, modifier: NONE,
|
||||
x: 17, y: 0, fg: Green, bg: Reset, underline: Reset, modifier: NONE,
|
||||
x: 27, y: 0, fg: Reset, bg: Reset, underline: Reset, modifier: NONE,
|
||||
]
|
||||
}
|
||||
"###);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user