mirror of
https://github.com/openai/codex.git
synced 2026-11-16 22:00:36 +00:00
Unify TUI status content and layout caching in StatusLine (#61200)
## What changed - Replace `FooterContent` and the separate layout cache with a `StatusLine` that owns native or extension content and caches its layout by bounds. - Move footer padding into the caller's layout and retain cached wrapping for unchanged agent-labeled status lines. - Remove extension-to-single-line conversion and render prepared UI trees directly within their allotted rectangles. ## Testing Extend composer coverage to verify that replacing measured extension content updates the displayed rows. Adapt status-line and UI-tree tests to exercise direct rendering, clipping, hyperlinks, and viewport bounds. GitOrigin-RevId: 72273c87d689b8b59748ab243793a9e2a45f4884
This commit is contained in:
@@ -14,16 +14,12 @@ use super::TextProps;
|
||||
use super::TextWeight;
|
||||
use super::UiTree;
|
||||
use super::theme::RenderTheme;
|
||||
use crate::terminal_hyperlinks::HyperlinkLine;
|
||||
use crate::terminal_hyperlinks::TerminalHyperlink;
|
||||
use crate::terminal_hyperlinks::mark_hyperlink_cells;
|
||||
use ratatui::buffer::Buffer;
|
||||
use ratatui::layout::Rect;
|
||||
use ratatui::layout::Size;
|
||||
use ratatui::style::Modifier;
|
||||
use ratatui::style::Style;
|
||||
use ratatui::text::Span;
|
||||
use std::ops::Range;
|
||||
use syntect::highlighting::Theme;
|
||||
use vtparse::CollectingVTActor;
|
||||
use vtparse::VTAction;
|
||||
@@ -42,13 +38,6 @@ impl UiTree {
|
||||
}
|
||||
|
||||
impl PreparedUiTree {
|
||||
pub(crate) fn measure_natural(&self) -> Size {
|
||||
self.0.as_ref().map_or_else(Size::default, |node| {
|
||||
let width = u16::try_from(node.widths.preferred).unwrap_or(u16::MAX);
|
||||
Size::new(width, node.natural_height)
|
||||
})
|
||||
}
|
||||
|
||||
pub(crate) fn measure(&self, bounds: Size) -> Size {
|
||||
layout(self.0.as_ref(), bounds, /*draw*/ None)
|
||||
}
|
||||
@@ -83,29 +72,6 @@ impl PreparedUiTree {
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
pub(crate) fn render_line(&self, width: u16, theme: &Theme) -> HyperlinkLine {
|
||||
let natural = self.measure_natural();
|
||||
if width == 1 && (natural.width > 1 || natural.height > 1) {
|
||||
return ratatui::text::Line::from("…").into();
|
||||
}
|
||||
let mut line = HyperlinkLine::default();
|
||||
let mut theme = RenderTheme::new(theme);
|
||||
layout(
|
||||
self.0.as_ref(),
|
||||
Size::new(width, /*height*/ 1),
|
||||
Some(&mut |_, col, text, cells, paint| {
|
||||
line.line
|
||||
.push_span(Span::styled(text.to_owned(), paint.style(&mut theme)));
|
||||
if cells > 0
|
||||
&& let Some(href) = &paint.href
|
||||
{
|
||||
push_link(&mut line, col..col + cells, href);
|
||||
}
|
||||
}),
|
||||
);
|
||||
line
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
@@ -332,18 +298,6 @@ fn sanitize_leaf(mut raw: String) -> String {
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn push_link(line: &mut HyperlinkLine, columns: Range<usize>, href: &str) {
|
||||
if let Some(last) = line.hyperlinks.last_mut()
|
||||
&& last.columns.end == columns.start
|
||||
&& last.destination == href
|
||||
{
|
||||
last.columns.end = columns.end;
|
||||
} else {
|
||||
line.hyperlinks
|
||||
.push(TerminalHyperlink::web(columns, href.to_owned()));
|
||||
}
|
||||
}
|
||||
|
||||
impl TextProps {
|
||||
fn apply_to(&self, paint: &mut Paint) {
|
||||
if let Some(color) = self.color {
|
||||
|
||||
@@ -10,7 +10,6 @@ use crate::ui_tree::UiNode;
|
||||
pub(super) struct PreparedNode {
|
||||
pub(super) kind: NodeKind,
|
||||
pub(super) widths: Widths,
|
||||
pub(super) natural_height: u16,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
@@ -62,7 +61,6 @@ impl PreparedNode {
|
||||
widths.preferred = widths.preferred.max(width);
|
||||
}
|
||||
Some(Self {
|
||||
natural_height: u16::try_from(text.lines.len()).unwrap_or(u16::MAX),
|
||||
kind: NodeKind::Text(text),
|
||||
widths,
|
||||
})
|
||||
@@ -97,11 +95,6 @@ impl PreparedNode {
|
||||
};
|
||||
Some(Self {
|
||||
widths,
|
||||
natural_height: children
|
||||
.iter()
|
||||
.map(|child| child.natural_height)
|
||||
.max()
|
||||
.unwrap_or_default(),
|
||||
kind: NodeKind::Row {
|
||||
children,
|
||||
gap,
|
||||
|
||||
Reference in New Issue
Block a user