mirror of
https://github.com/openai/codex.git
synced 2026-11-27 23:31:09 +00:00
## Why Reading daily totals required selecting each bar, and changing grouping required opening a picker. Section navigation could shift vertically, while scroll hints appeared even when content fit. ## What changed - Make `g` cycle through available groupings and summary views directly. - Show daily totals on charts spanning up to seven days when space permits, prioritizing the selected value and keeping neighboring labels separate. - Keep section navigation at a stable height, show more legend rows in taller maximized reports, and move their update timestamp into the footer. - Hide scroll hints when content fits, including an exact fit, and show only the active summary view label. ## Testing Add regression tests and snapshots for seven-day totals, narrow label spacing, grouping wraparound and server capabilities, configured `g` navigation in ungrouped sections, stable tab placement, adaptive legends, footer timestamps, and overflow-dependent scroll hints. GitOrigin-RevId: 9d14f314b4a22ca2d926f0e69c6b89e4f9c8550d
107 lines
3.5 KiB
Rust
107 lines
3.5 KiB
Rust
//! Responsive panels with consistent category colors and signed daily amounts.
|
|
|
|
use super::AnalyticsView;
|
|
use super::render::columns;
|
|
use super::styles::secondary_style;
|
|
use crate::analytics::sections::Section;
|
|
use crate::style::accent_style;
|
|
use crate::wrapping::RtOptions;
|
|
use crate::wrapping::word_wrap_lines;
|
|
use ratatui::style::Styled;
|
|
use ratatui::style::Stylize;
|
|
use ratatui::text::Line;
|
|
use std::ops::Range;
|
|
|
|
/// Panel content and measured geometry shared by layout and scrolling.
|
|
pub(super) struct Panel {
|
|
pub(super) lines: Vec<Line<'static>>,
|
|
pub(super) selection: Range<usize>,
|
|
pub(super) chart_bands: usize,
|
|
}
|
|
|
|
impl AnalyticsView {
|
|
pub(super) fn panel(&self, section: Section, width: usize, chart_height: usize) -> Panel {
|
|
let focused = section == self.section;
|
|
let title = format!(
|
|
"{} {}",
|
|
if focused { "▎" } else { " " },
|
|
self.section_title(section)
|
|
);
|
|
let heading = if focused {
|
|
title.set_style(accent_style()).into()
|
|
} else {
|
|
title.bold().into()
|
|
};
|
|
let group = self.sections[section].group;
|
|
let heading = if matches!(
|
|
section,
|
|
Section::Usage | Section::Credits | Section::Activity | Section::Plan
|
|
) {
|
|
columns(
|
|
heading,
|
|
format!("By {}", self.group_label(section, group).to_lowercase())
|
|
.set_style(secondary_style())
|
|
.into(),
|
|
width,
|
|
)
|
|
} else {
|
|
heading
|
|
};
|
|
let mut lines = vec![heading, "─".repeat(width).dim().into()];
|
|
if section == Section::Usage && self.business() {
|
|
lines.push(
|
|
format!(
|
|
"{} · m change model",
|
|
self.token_model.as_deref().unwrap_or("All models")
|
|
)
|
|
.set_style(secondary_style())
|
|
.into(),
|
|
);
|
|
}
|
|
let selection;
|
|
let mut chart_bands = 0;
|
|
|
|
if section == Section::Summary {
|
|
selection = 0..1;
|
|
lines.extend(self.summary_lines(width));
|
|
} else if section == Section::Plan {
|
|
let (plan, detail) = self.plan_lines(width);
|
|
selection = lines.len() + detail.start..lines.len() + detail.end;
|
|
lines.extend(plan);
|
|
} else if section == Section::Chats {
|
|
let (chats, detail) = if self.business() {
|
|
self.chat_lines(width)
|
|
} else {
|
|
self.task_lines(width)
|
|
};
|
|
selection = lines.len() + detail.start..lines.len() + detail.end;
|
|
lines.extend(chats);
|
|
} else {
|
|
let history = self.history_lines(section, width, chart_height);
|
|
chart_bands = history.bands;
|
|
lines.extend(history.lines);
|
|
selection = 0..lines.len();
|
|
}
|
|
|
|
let mut wrapped = Vec::new();
|
|
let mut wrapped_selection = 0..0;
|
|
for (index, line) in lines.into_iter().enumerate() {
|
|
if index == selection.start {
|
|
wrapped_selection.start = wrapped.len();
|
|
}
|
|
wrapped.extend(word_wrap_lines(
|
|
[line],
|
|
RtOptions::new(width.max(/*other*/ 1)),
|
|
));
|
|
if index + 1 == selection.end {
|
|
wrapped_selection.end = wrapped.len();
|
|
}
|
|
}
|
|
Panel {
|
|
lines: wrapped,
|
|
selection: wrapped_selection,
|
|
chart_bands,
|
|
}
|
|
}
|
|
}
|