mirror of
https://github.com/openai/codex.git
synced 2026-12-01 00:20:48 +00:00
wip(tui): remove resize reflow debug output
This commit is contained in:
+4
-15
@@ -511,18 +511,8 @@ struct SessionSummary {
|
||||
}
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
struct InitialHistoryReplayMetrics {
|
||||
replay_elapsed: Option<Duration>,
|
||||
render_elapsed: Duration,
|
||||
enqueue_elapsed: Duration,
|
||||
flush_elapsed: Duration,
|
||||
struct InitialHistoryReplayBuffer {
|
||||
retained_lines: VecDeque<Line<'static>>,
|
||||
cell_count: usize,
|
||||
rendered_line_count: usize,
|
||||
retained_line_count: usize,
|
||||
trimmed_line_count: usize,
|
||||
flushed_line_count: usize,
|
||||
replay_finished: bool,
|
||||
}
|
||||
|
||||
pub(crate) struct App {
|
||||
@@ -547,7 +537,7 @@ pub(crate) struct App {
|
||||
pub(crate) deferred_history_lines: Vec<Line<'static>>,
|
||||
has_emitted_history_lines: bool,
|
||||
transcript_reflow: TranscriptReflowState,
|
||||
initial_history_replay_metrics: Option<InitialHistoryReplayMetrics>,
|
||||
initial_history_replay_buffer: Option<InitialHistoryReplayBuffer>,
|
||||
|
||||
pub(crate) enhanced_keys_supported: bool,
|
||||
|
||||
@@ -934,7 +924,7 @@ impl App {
|
||||
deferred_history_lines: Vec::new(),
|
||||
has_emitted_history_lines: false,
|
||||
transcript_reflow: TranscriptReflowState::default(),
|
||||
initial_history_replay_metrics: None,
|
||||
initial_history_replay_buffer: None,
|
||||
commit_anim_running: Arc::new(AtomicBool::new(false)),
|
||||
status_line_invalid_items_warned: status_line_invalid_items_warned.clone(),
|
||||
terminal_title_invalid_items_warned: terminal_title_invalid_items_warned.clone(),
|
||||
@@ -1169,13 +1159,12 @@ impl App {
|
||||
let desired_height =
|
||||
self.chat_widget.desired_height(tui.terminal.size()?.width);
|
||||
if terminal_resize_reflow_active {
|
||||
let stats = tui.draw_with_resize_reflow(desired_height, |frame| {
|
||||
tui.draw_with_resize_reflow(desired_height, |frame| {
|
||||
self.chat_widget.render(frame.area(), frame.buffer);
|
||||
if let Some((x, y)) = self.chat_widget.cursor_pos(frame.area()) {
|
||||
frame.set_cursor_position((x, y));
|
||||
}
|
||||
})?;
|
||||
self.maybe_finish_initial_history_replay_measurement(stats);
|
||||
} else {
|
||||
tui.draw(desired_height, |frame| {
|
||||
self.chat_widget.render(frame.area(), frame.buffer);
|
||||
|
||||
@@ -21,17 +21,11 @@ impl App {
|
||||
}
|
||||
|
||||
pub(super) async fn refresh_in_memory_config_from_disk(&mut self) -> Result<()> {
|
||||
let previous_resize_reflow_config = self.config.terminal_resize_reflow;
|
||||
let mut config = self
|
||||
.rebuild_config_for_cwd(self.chat_widget.config_ref().cwd.to_path_buf())
|
||||
.await?;
|
||||
self.apply_runtime_policy_overrides(&mut config);
|
||||
let resize_reflow_config_changed =
|
||||
previous_resize_reflow_config != config.terminal_resize_reflow;
|
||||
self.config = config;
|
||||
if resize_reflow_config_changed {
|
||||
self.transcript_reflow.clear_row_cap_trim_warning();
|
||||
}
|
||||
self.chat_widget.sync_plugin_mentions_config(&self.config);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -176,8 +176,8 @@ impl App {
|
||||
|
||||
tui.frame_requester().schedule_frame();
|
||||
}
|
||||
AppEvent::BeginInitialHistoryReplayMeasurement => {
|
||||
self.begin_initial_history_replay_measurement();
|
||||
AppEvent::BeginInitialHistoryReplayBuffer => {
|
||||
self.begin_initial_history_replay_buffer();
|
||||
}
|
||||
AppEvent::InsertHistoryCell(cell) => {
|
||||
let cell: Arc<dyn HistoryCell> = cell.into();
|
||||
@@ -186,12 +186,8 @@ impl App {
|
||||
tui.frame_requester().schedule_frame();
|
||||
}
|
||||
self.transcript_cells.push(cell.clone());
|
||||
if self
|
||||
.initial_history_replay_metrics
|
||||
.as_ref()
|
||||
.is_some_and(|metrics| !metrics.replay_finished)
|
||||
{
|
||||
self.insert_history_cell_lines_with_initial_replay_measurement(
|
||||
if self.initial_history_replay_buffer.as_ref().is_some() {
|
||||
self.insert_history_cell_lines_with_initial_replay_buffer(
|
||||
tui,
|
||||
cell.as_ref(),
|
||||
tui.terminal.last_known_screen_size.width,
|
||||
@@ -204,8 +200,8 @@ impl App {
|
||||
);
|
||||
}
|
||||
}
|
||||
AppEvent::EndInitialHistoryReplayMeasurement { replay_elapsed } => {
|
||||
self.finish_initial_history_replay_measurement(tui, replay_elapsed);
|
||||
AppEvent::EndInitialHistoryReplayBuffer => {
|
||||
self.finish_initial_history_replay_buffer(tui);
|
||||
}
|
||||
AppEvent::ConsolidateAgentMessage { source, cwd } => {
|
||||
if !self.terminal_resize_reflow_enabled() {
|
||||
@@ -216,16 +212,9 @@ impl App {
|
||||
return Ok(AppRunControl::Continue);
|
||||
}
|
||||
let end = self.transcript_cells.len();
|
||||
tracing::debug!(
|
||||
"ConsolidateAgentMessage: transcript_cells.len()={end}, source_len={}",
|
||||
source.len()
|
||||
);
|
||||
let start =
|
||||
trailing_run_start::<history_cell::AgentMessageCell>(&self.transcript_cells);
|
||||
if start < end {
|
||||
tracing::debug!(
|
||||
"ConsolidateAgentMessage: replacing cells [{start}..{end}] with AgentMarkdownCell"
|
||||
);
|
||||
let consolidated: Arc<dyn HistoryCell> =
|
||||
Arc::new(history_cell::AgentMarkdownCell::new(source, &cwd));
|
||||
self.transcript_cells
|
||||
@@ -238,9 +227,6 @@ impl App {
|
||||
|
||||
self.maybe_finish_stream_reflow(tui)?;
|
||||
} else {
|
||||
tracing::debug!(
|
||||
"ConsolidateAgentMessage: no cells to consolidate(start={start}, end={end})",
|
||||
);
|
||||
self.maybe_finish_stream_reflow(tui)?;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -92,7 +92,7 @@ impl App {
|
||||
self.deferred_history_lines.clear();
|
||||
self.has_emitted_history_lines = false;
|
||||
self.transcript_reflow.clear();
|
||||
self.initial_history_replay_metrics = None;
|
||||
self.initial_history_replay_buffer = None;
|
||||
self.backtrack = BacktrackState::default();
|
||||
self.backtrack_render_pending = false;
|
||||
}
|
||||
|
||||
@@ -11,7 +11,6 @@
|
||||
//! from the finalized source.
|
||||
|
||||
use std::collections::VecDeque;
|
||||
use std::time::Duration;
|
||||
use std::time::Instant;
|
||||
|
||||
use codex_features::Feature;
|
||||
@@ -19,7 +18,7 @@ use color_eyre::eyre::Result;
|
||||
use ratatui::text::Line;
|
||||
|
||||
use super::App;
|
||||
use super::InitialHistoryReplayMetrics;
|
||||
use super::InitialHistoryReplayBuffer;
|
||||
use super::trailing_run_start;
|
||||
use crate::history_cell;
|
||||
use crate::history_cell::HistoryCell;
|
||||
@@ -27,15 +26,6 @@ use crate::transcript_reflow::TRANSCRIPT_REFLOW_DEBOUNCE;
|
||||
use crate::transcript_reflow::TranscriptReflowKind;
|
||||
use crate::tui;
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub(super) struct ResizeReflowRunStats {
|
||||
kind: TranscriptReflowKind,
|
||||
width: u16,
|
||||
cell_count: usize,
|
||||
rendered_line_count: usize,
|
||||
row_cap_limited: bool,
|
||||
}
|
||||
|
||||
struct ReflowCellDisplay {
|
||||
lines: Vec<Line<'static>>,
|
||||
is_stream_continuation: bool,
|
||||
@@ -43,8 +33,6 @@ struct ReflowCellDisplay {
|
||||
|
||||
pub(super) struct ReflowRenderResult {
|
||||
pub(super) lines: Vec<Line<'static>>,
|
||||
pub(super) rendered_cell_count: usize,
|
||||
pub(super) row_cap_limited: bool,
|
||||
}
|
||||
|
||||
impl App {
|
||||
@@ -94,149 +82,58 @@ impl App {
|
||||
self.terminal_resize_reflow_enabled()
|
||||
}
|
||||
|
||||
pub(super) fn begin_initial_history_replay_measurement(&mut self) {
|
||||
pub(super) fn begin_initial_history_replay_buffer(&mut self) {
|
||||
if self.terminal_resize_reflow_active() && self.overlay.is_none() {
|
||||
self.initial_history_replay_metrics = Some(Default::default());
|
||||
self.initial_history_replay_buffer = Some(Default::default());
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn finish_initial_history_replay_measurement(
|
||||
&mut self,
|
||||
tui: &mut tui::Tui,
|
||||
replay_elapsed: Duration,
|
||||
) {
|
||||
let row_cap = self.resize_reflow_max_rows();
|
||||
let Some(metrics) = &mut self.initial_history_replay_metrics else {
|
||||
pub(super) fn finish_initial_history_replay_buffer(&mut self, tui: &mut tui::Tui) {
|
||||
let Some(buffer) = self.initial_history_replay_buffer.take() else {
|
||||
return;
|
||||
};
|
||||
metrics.replay_elapsed = Some(replay_elapsed);
|
||||
metrics.replay_finished = true;
|
||||
|
||||
let Some(max_rows) = row_cap else {
|
||||
return;
|
||||
};
|
||||
if metrics.retained_lines.is_empty() {
|
||||
if buffer.retained_lines.is_empty() {
|
||||
return;
|
||||
}
|
||||
|
||||
let enqueue_started = Instant::now();
|
||||
let retained_lines = metrics.retained_lines.drain(..).collect::<Vec<_>>();
|
||||
metrics.retained_line_count = retained_lines.len();
|
||||
let retained_lines = buffer.retained_lines.into_iter().collect::<Vec<_>>();
|
||||
tui.insert_history_lines(retained_lines);
|
||||
metrics.enqueue_elapsed += enqueue_started.elapsed();
|
||||
|
||||
if metrics.trimmed_line_count > 0 {
|
||||
self.chat_widget.add_info_message(
|
||||
format!(
|
||||
"Initial transcript replay limited scrollback to the most recent {} rows because replay produced {} rows, above the {} row limit.",
|
||||
metrics.retained_line_count,
|
||||
metrics.rendered_line_count,
|
||||
max_rows,
|
||||
),
|
||||
/*hint*/ None,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn insert_history_cell_lines_with_initial_replay_measurement(
|
||||
pub(super) fn insert_history_cell_lines_with_initial_replay_buffer(
|
||||
&mut self,
|
||||
tui: &mut tui::Tui,
|
||||
cell: &dyn HistoryCell,
|
||||
width: u16,
|
||||
) {
|
||||
let render_started = Instant::now();
|
||||
let display = self.display_lines_for_history_insert(cell, width);
|
||||
let render_elapsed = render_started.elapsed();
|
||||
let rendered_line_count = display.len();
|
||||
|
||||
if let Some(metrics) = &mut self.initial_history_replay_metrics {
|
||||
metrics.cell_count += 1;
|
||||
metrics.rendered_line_count += rendered_line_count;
|
||||
metrics.render_elapsed += render_elapsed;
|
||||
}
|
||||
|
||||
if display.is_empty() {
|
||||
return;
|
||||
}
|
||||
|
||||
let enqueue_started = Instant::now();
|
||||
let max_rows = self.resize_reflow_max_rows();
|
||||
if let Some(metrics) = &mut self.initial_history_replay_metrics {
|
||||
if let Some(buffer) = &mut self.initial_history_replay_buffer {
|
||||
if let Some(max_rows) = max_rows {
|
||||
Self::buffer_initial_history_replay_display_lines(metrics, display, max_rows);
|
||||
Self::buffer_initial_history_replay_display_lines(buffer, display, max_rows);
|
||||
} else if self.overlay.is_some() {
|
||||
self.deferred_history_lines.extend(display);
|
||||
} else {
|
||||
tui.insert_history_lines(display);
|
||||
}
|
||||
metrics.enqueue_elapsed += enqueue_started.elapsed();
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn buffer_initial_history_replay_display_lines(
|
||||
metrics: &mut InitialHistoryReplayMetrics,
|
||||
buffer: &mut InitialHistoryReplayBuffer,
|
||||
display: Vec<Line<'static>>,
|
||||
max_rows: usize,
|
||||
) {
|
||||
metrics.retained_lines.extend(display);
|
||||
while metrics.retained_lines.len() > max_rows {
|
||||
metrics.retained_lines.pop_front();
|
||||
metrics.trimmed_line_count += 1;
|
||||
buffer.retained_lines.extend(display);
|
||||
while buffer.retained_lines.len() > max_rows {
|
||||
buffer.retained_lines.pop_front();
|
||||
}
|
||||
metrics.retained_line_count = metrics.retained_lines.len();
|
||||
}
|
||||
|
||||
pub(super) fn maybe_finish_initial_history_replay_measurement(
|
||||
&mut self,
|
||||
draw_stats: tui::ResizeReflowDrawStats,
|
||||
) {
|
||||
let row_cap = self.resize_reflow_max_rows();
|
||||
let Some(metrics) = &mut self.initial_history_replay_metrics else {
|
||||
return;
|
||||
};
|
||||
if draw_stats.flushed_history {
|
||||
metrics.flush_elapsed += draw_stats.history_flush_elapsed;
|
||||
metrics.flushed_line_count += draw_stats.history_flush_line_count;
|
||||
}
|
||||
let expected_flushed_line_count = if row_cap.is_some() {
|
||||
metrics.retained_line_count
|
||||
} else {
|
||||
metrics.rendered_line_count
|
||||
};
|
||||
if !metrics.replay_finished
|
||||
|| (expected_flushed_line_count > 0
|
||||
&& metrics.flushed_line_count < expected_flushed_line_count)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if let Some(metrics) = self.initial_history_replay_metrics.take() {
|
||||
self.show_initial_history_replay_measurement(metrics);
|
||||
}
|
||||
}
|
||||
|
||||
fn show_initial_history_replay_measurement(&mut self, metrics: InitialHistoryReplayMetrics) {
|
||||
let replay_ms = metrics.replay_elapsed.unwrap_or_default().as_millis();
|
||||
let retained_line_count =
|
||||
if metrics.retained_line_count == 0 && metrics.trimmed_line_count == 0 {
|
||||
metrics.rendered_line_count
|
||||
} else {
|
||||
metrics.retained_line_count
|
||||
};
|
||||
self.chat_widget.add_info_message(
|
||||
format!(
|
||||
"Initial transcript replay took {replay_ms}ms to queue, {}ms to render, {}ms to enqueue, and {}ms to flush ({} rows from {} cells; {} rows retained; {} rows trimmed; {} rows flushed).",
|
||||
metrics.render_elapsed.as_millis(),
|
||||
metrics.enqueue_elapsed.as_millis(),
|
||||
metrics.flush_elapsed.as_millis(),
|
||||
metrics.rendered_line_count,
|
||||
metrics.cell_count,
|
||||
retained_line_count,
|
||||
metrics.trimmed_line_count,
|
||||
metrics.flushed_line_count,
|
||||
),
|
||||
/*hint*/ None,
|
||||
);
|
||||
}
|
||||
|
||||
fn schedule_resize_reflow(
|
||||
@@ -253,60 +150,6 @@ impl App {
|
||||
self.config.terminal_resize_reflow.max_rows
|
||||
}
|
||||
|
||||
fn maybe_note_row_cap_limited_reflow(&mut self, stats: ResizeReflowRunStats) {
|
||||
if !stats.row_cap_limited {
|
||||
return;
|
||||
}
|
||||
|
||||
let Some(max_rows) = self.resize_reflow_max_rows() else {
|
||||
return;
|
||||
};
|
||||
tracing::warn!(
|
||||
max_rows,
|
||||
kind = ?stats.kind,
|
||||
width = stats.width,
|
||||
cell_count = stats.cell_count,
|
||||
rendered_line_count = stats.rendered_line_count,
|
||||
"terminal resize reflow limited scrollback with rendered row cap"
|
||||
);
|
||||
self.maybe_show_row_cap_resize_reflow_trimmed_warning(stats.rendered_line_count, max_rows);
|
||||
}
|
||||
|
||||
fn maybe_show_row_cap_resize_reflow_trimmed_warning(
|
||||
&mut self,
|
||||
kept_line_count: usize,
|
||||
max_rows: usize,
|
||||
) {
|
||||
if self.transcript_reflow.take_row_cap_trim_warning_needed() {
|
||||
self.chat_widget.add_info_message(
|
||||
format!(
|
||||
"Terminal resize reflow limited scrollback to the most recent {kept_line_count} rows before rendering because the row cap is {max_rows}.",
|
||||
),
|
||||
/*hint*/ None,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
fn show_resize_reflow_timing_debug_message(
|
||||
&mut self,
|
||||
elapsed: Duration,
|
||||
stats: ResizeReflowRunStats,
|
||||
) {
|
||||
let kind = match stats.kind {
|
||||
TranscriptReflowKind::VisibleRows => "visible-row",
|
||||
TranscriptReflowKind::Full => "full",
|
||||
};
|
||||
self.chat_widget.add_info_message(
|
||||
format!(
|
||||
"Terminal resize reflow {kind} pass took {}ms ({} rows from {} cells).",
|
||||
elapsed.as_millis(),
|
||||
stats.rendered_line_count,
|
||||
stats.cell_count
|
||||
),
|
||||
/*hint*/ None,
|
||||
);
|
||||
}
|
||||
|
||||
/// Finish stream consolidation by repairing any resize work that happened during streaming.
|
||||
///
|
||||
/// This is called after agent-message stream cells have either been replaced by an
|
||||
@@ -501,16 +344,11 @@ impl App {
|
||||
let reflow_ran_during_stream =
|
||||
!self.transcript_cells.is_empty() && self.should_mark_reflow_as_stream_time();
|
||||
|
||||
let started = Instant::now();
|
||||
let stats = match reflow_kind {
|
||||
TranscriptReflowKind::Full => self.reflow_transcript_now(tui, reflow_kind)?,
|
||||
TranscriptReflowKind::VisibleRows => {
|
||||
self.repaint_visible_transcript_rows(tui, reflow_kind)?
|
||||
}
|
||||
let width = match reflow_kind {
|
||||
TranscriptReflowKind::Full => self.reflow_transcript_now(tui)?,
|
||||
TranscriptReflowKind::VisibleRows => self.repaint_visible_transcript_rows(tui)?,
|
||||
};
|
||||
let elapsed = started.elapsed();
|
||||
self.show_resize_reflow_timing_debug_message(elapsed, stats);
|
||||
self.transcript_reflow.mark_reflowed_width(stats.width);
|
||||
self.transcript_reflow.mark_reflowed_width(width);
|
||||
|
||||
if reflow_ran_during_stream {
|
||||
self.transcript_reflow.mark_ran_during_stream();
|
||||
@@ -524,36 +362,17 @@ impl App {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn reflow_transcript_now(
|
||||
&mut self,
|
||||
tui: &mut tui::Tui,
|
||||
kind: TranscriptReflowKind,
|
||||
) -> Result<ResizeReflowRunStats> {
|
||||
fn reflow_transcript_now(&mut self, tui: &mut tui::Tui) -> Result<u16> {
|
||||
let width = tui.terminal.size()?.width;
|
||||
let cell_count = self.transcript_cells.len();
|
||||
if self.transcript_cells.is_empty() {
|
||||
// Drop any queued pre-resize/pre-consolidation inserts before rebuilding from cells.
|
||||
tui.clear_pending_history_lines();
|
||||
self.reset_history_emission_state();
|
||||
return Ok(ResizeReflowRunStats {
|
||||
kind,
|
||||
width,
|
||||
cell_count,
|
||||
rendered_line_count: 0,
|
||||
row_cap_limited: false,
|
||||
});
|
||||
return Ok(width);
|
||||
}
|
||||
|
||||
let reflow_result = self.render_transcript_lines_for_reflow(width);
|
||||
let reflowed_lines = reflow_result.lines;
|
||||
let stats = ResizeReflowRunStats {
|
||||
kind,
|
||||
width,
|
||||
cell_count: reflow_result.rendered_cell_count,
|
||||
rendered_line_count: reflowed_lines.len(),
|
||||
row_cap_limited: reflow_result.row_cap_limited,
|
||||
};
|
||||
self.maybe_note_row_cap_limited_reflow(stats);
|
||||
|
||||
// Drop any queued pre-resize/pre-consolidation inserts before rebuilding from cells.
|
||||
tui.clear_pending_history_lines();
|
||||
@@ -568,38 +387,19 @@ impl App {
|
||||
tui.insert_reflowed_history_lines(reflowed_lines);
|
||||
}
|
||||
|
||||
Ok(stats)
|
||||
Ok(width)
|
||||
}
|
||||
|
||||
fn repaint_visible_transcript_rows(
|
||||
&mut self,
|
||||
tui: &mut tui::Tui,
|
||||
kind: TranscriptReflowKind,
|
||||
) -> Result<ResizeReflowRunStats> {
|
||||
fn repaint_visible_transcript_rows(&mut self, tui: &mut tui::Tui) -> Result<u16> {
|
||||
let width = tui.terminal.size()?.width;
|
||||
let cell_count = self.transcript_cells.len();
|
||||
if self.transcript_cells.is_empty() {
|
||||
tui.clear_pending_history_lines();
|
||||
self.reset_history_emission_state();
|
||||
return Ok(ResizeReflowRunStats {
|
||||
kind,
|
||||
width,
|
||||
cell_count,
|
||||
rendered_line_count: 0,
|
||||
row_cap_limited: false,
|
||||
});
|
||||
return Ok(width);
|
||||
}
|
||||
|
||||
let reflow_result = self.render_transcript_lines_for_reflow(width);
|
||||
let reflowed_lines = reflow_result.lines;
|
||||
let stats = ResizeReflowRunStats {
|
||||
kind,
|
||||
width,
|
||||
cell_count: reflow_result.rendered_cell_count,
|
||||
rendered_line_count: reflowed_lines.len(),
|
||||
row_cap_limited: reflow_result.row_cap_limited,
|
||||
};
|
||||
self.maybe_note_row_cap_limited_reflow(stats);
|
||||
|
||||
tui.clear_pending_history_lines();
|
||||
tui.terminal.clear_visible_screen()?;
|
||||
@@ -608,7 +408,7 @@ impl App {
|
||||
tui.insert_reflowed_history_lines(reflowed_lines);
|
||||
}
|
||||
|
||||
Ok(stats)
|
||||
Ok(width)
|
||||
}
|
||||
|
||||
pub(super) fn render_transcript_lines_for_reflow(&mut self, width: u16) -> ReflowRenderResult {
|
||||
@@ -645,7 +445,6 @@ impl App {
|
||||
});
|
||||
}
|
||||
|
||||
let rendered_cell_count = cell_displays.len();
|
||||
let mut has_emitted_history_lines = false;
|
||||
let mut reflowed_lines = Vec::new();
|
||||
for display in cell_displays {
|
||||
@@ -658,8 +457,6 @@ impl App {
|
||||
}
|
||||
reflowed_lines.extend(display.lines);
|
||||
}
|
||||
let row_cap_limited =
|
||||
row_cap.is_some_and(|max_rows| start > 0 || reflowed_lines.len() > max_rows);
|
||||
if let Some(max_rows) = row_cap
|
||||
&& reflowed_lines.len() > max_rows
|
||||
{
|
||||
@@ -670,8 +467,6 @@ impl App {
|
||||
|
||||
ReflowRenderResult {
|
||||
lines: reflowed_lines,
|
||||
rendered_cell_count,
|
||||
row_cap_limited,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ pub(super) async fn make_test_app() -> App {
|
||||
deferred_history_lines: Vec::new(),
|
||||
has_emitted_history_lines: false,
|
||||
transcript_reflow: TranscriptReflowState::default(),
|
||||
initial_history_replay_metrics: None,
|
||||
initial_history_replay_buffer: None,
|
||||
enhanced_keys_supported: false,
|
||||
commit_anim_running: Arc::new(AtomicBool::new(false)),
|
||||
status_line_invalid_items_warned: Arc::new(AtomicBool::new(false)),
|
||||
|
||||
@@ -3570,7 +3570,7 @@ async fn make_test_app() -> App {
|
||||
deferred_history_lines: Vec::new(),
|
||||
has_emitted_history_lines: false,
|
||||
transcript_reflow: TranscriptReflowState::default(),
|
||||
initial_history_replay_metrics: None,
|
||||
initial_history_replay_buffer: None,
|
||||
enhanced_keys_supported: false,
|
||||
commit_anim_running: Arc::new(AtomicBool::new(false)),
|
||||
status_line_invalid_items_warned: Arc::new(AtomicBool::new(false)),
|
||||
@@ -3629,7 +3629,7 @@ async fn make_test_app_with_channels() -> (
|
||||
deferred_history_lines: Vec::new(),
|
||||
has_emitted_history_lines: false,
|
||||
transcript_reflow: TranscriptReflowState::default(),
|
||||
initial_history_replay_metrics: None,
|
||||
initial_history_replay_buffer: None,
|
||||
enhanced_keys_supported: false,
|
||||
commit_anim_running: Arc::new(AtomicBool::new(false)),
|
||||
status_line_invalid_items_warned: Arc::new(AtomicBool::new(false)),
|
||||
@@ -3712,11 +3712,6 @@ async fn capped_resize_reflow_renders_recent_suffix_only() {
|
||||
|
||||
let rendered = app.render_transcript_lines_for_reflow(/*width*/ 80);
|
||||
|
||||
assert!(rendered.row_cap_limited);
|
||||
assert!(
|
||||
rendered.rendered_cell_count < app.transcript_cells.len(),
|
||||
"row-capped reflow should not render the whole transcript"
|
||||
);
|
||||
assert_eq!(rendered.lines.len(), 5);
|
||||
assert_eq!(
|
||||
rendered
|
||||
@@ -3744,8 +3739,9 @@ async fn uncapped_resize_reflow_renders_all_cells_when_row_cap_absent() {
|
||||
|
||||
let rendered = app.render_transcript_lines_for_reflow(/*width*/ 80);
|
||||
|
||||
assert!(!rendered.row_cap_limited);
|
||||
assert_eq!(rendered.rendered_cell_count, app.transcript_cells.len());
|
||||
assert_eq!(rendered.lines.len(), 39);
|
||||
assert_eq!(rendered_line_text(&rendered.lines[0]), "cell 0");
|
||||
assert_eq!(rendered_line_text(&rendered.lines[38]), "cell 19");
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
@@ -3758,8 +3754,6 @@ async fn uncapped_resize_reflow_renders_all_cells_under_row_limit() {
|
||||
|
||||
let rendered = app.render_transcript_lines_for_reflow(/*width*/ 80);
|
||||
|
||||
assert!(!rendered.row_cap_limited);
|
||||
assert_eq!(rendered.rendered_cell_count, app.transcript_cells.len());
|
||||
assert_eq!(
|
||||
rendered
|
||||
.lines
|
||||
@@ -3777,30 +3771,28 @@ async fn uncapped_resize_reflow_renders_all_cells_under_row_limit() {
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn initial_replay_measurement_buffers_recent_rows_when_row_cap_present() {
|
||||
async fn initial_replay_buffer_keeps_recent_rows_when_row_cap_present() {
|
||||
let (mut app, _rx, _op_rx) = make_test_app_with_channels().await;
|
||||
enable_terminal_resize_reflow(&mut app);
|
||||
app.config.terminal_resize_reflow.max_rows = Some(3);
|
||||
|
||||
app.begin_initial_history_replay_measurement();
|
||||
app.begin_initial_history_replay_buffer();
|
||||
for index in 0..5 {
|
||||
App::buffer_initial_history_replay_display_lines(
|
||||
app.initial_history_replay_metrics
|
||||
app.initial_history_replay_buffer
|
||||
.as_mut()
|
||||
.expect("measurement active"),
|
||||
.expect("initial replay buffer active"),
|
||||
vec![Line::from(format!("line {index}"))],
|
||||
/*max_rows*/ 3,
|
||||
);
|
||||
}
|
||||
|
||||
let metrics = app
|
||||
.initial_history_replay_metrics
|
||||
let buffer = app
|
||||
.initial_history_replay_buffer
|
||||
.as_ref()
|
||||
.expect("measurement should remain active");
|
||||
assert_eq!(metrics.retained_line_count, 3);
|
||||
assert_eq!(metrics.trimmed_line_count, 2);
|
||||
.expect("initial replay buffer should remain active");
|
||||
assert_eq!(
|
||||
metrics
|
||||
buffer
|
||||
.retained_lines
|
||||
.iter()
|
||||
.map(rendered_line_text)
|
||||
|
||||
@@ -1029,20 +1029,17 @@ impl App {
|
||||
self.chat_widget
|
||||
.set_initial_user_message_submit_suppressed(/*suppressed*/ true);
|
||||
self.chat_widget.handle_thread_session(session);
|
||||
let should_measure_initial_replay =
|
||||
let should_buffer_initial_replay =
|
||||
self.terminal_resize_reflow_active() && !turns.is_empty();
|
||||
let replay_started = should_measure_initial_replay.then(Instant::now);
|
||||
if should_measure_initial_replay {
|
||||
if should_buffer_initial_replay {
|
||||
self.app_event_tx
|
||||
.send(AppEvent::BeginInitialHistoryReplayMeasurement);
|
||||
.send(AppEvent::BeginInitialHistoryReplayBuffer);
|
||||
}
|
||||
self.chat_widget
|
||||
.replay_thread_turns(turns, ReplayKind::ResumeInitialMessages);
|
||||
if let Some(started) = replay_started {
|
||||
if should_buffer_initial_replay {
|
||||
self.app_event_tx
|
||||
.send(AppEvent::EndInitialHistoryReplayMeasurement {
|
||||
replay_elapsed: started.elapsed(),
|
||||
});
|
||||
.send(AppEvent::EndInitialHistoryReplayBuffer);
|
||||
}
|
||||
let pending = std::mem::take(&mut self.pending_primary_events);
|
||||
for pending_event in pending {
|
||||
|
||||
@@ -354,15 +354,13 @@ pub(crate) enum AppEvent {
|
||||
result: Result<SkillsListResponse, String>,
|
||||
},
|
||||
|
||||
/// Begin measuring initial resume replay without changing the replay behavior.
|
||||
BeginInitialHistoryReplayMeasurement,
|
||||
/// Begin buffering initial resume replay rows before they are written to scrollback.
|
||||
BeginInitialHistoryReplayBuffer,
|
||||
|
||||
InsertHistoryCell(Box<dyn HistoryCell>),
|
||||
|
||||
/// Finish measuring initial resume replay after all replay events have been queued.
|
||||
EndInitialHistoryReplayMeasurement {
|
||||
replay_elapsed: std::time::Duration,
|
||||
},
|
||||
/// Finish buffering initial resume replay after all replay events have been queued.
|
||||
EndInitialHistoryReplayBuffer,
|
||||
|
||||
/// Replace the contiguous run of streaming `AgentMessageCell`s at the end of
|
||||
/// the transcript with a single `AgentMarkdownCell` that stores the raw
|
||||
|
||||
@@ -26,7 +26,6 @@ pub(crate) struct TranscriptReflowState {
|
||||
pending_kind: Option<TranscriptReflowKind>,
|
||||
ran_during_stream: bool,
|
||||
resize_requested_during_stream: bool,
|
||||
row_cap_trim_warning_shown: bool,
|
||||
}
|
||||
|
||||
/// Describes how much terminal history repair is needed for a pending resize.
|
||||
@@ -150,18 +149,6 @@ impl TranscriptReflowState {
|
||||
self.last_reflow_width.replace(width) != Some(width)
|
||||
}
|
||||
|
||||
pub(crate) fn clear_row_cap_trim_warning(&mut self) {
|
||||
self.row_cap_trim_warning_shown = false;
|
||||
}
|
||||
|
||||
pub(crate) fn take_row_cap_trim_warning_needed(&mut self) -> bool {
|
||||
if self.row_cap_trim_warning_shown {
|
||||
return false;
|
||||
}
|
||||
self.row_cap_trim_warning_shown = true;
|
||||
true
|
||||
}
|
||||
|
||||
/// Remember that a reflow actually rebuilt history before stream consolidation completed.
|
||||
///
|
||||
/// A mid-stream rebuild can only render the transient stream cells that exist at that moment.
|
||||
@@ -357,22 +344,4 @@ mod tests {
|
||||
|
||||
assert!(!state.take_stream_finish_reflow_needed());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn row_cap_trim_warning_is_reported_once() {
|
||||
let mut state = TranscriptReflowState::default();
|
||||
|
||||
assert!(state.take_row_cap_trim_warning_needed());
|
||||
assert!(!state.take_row_cap_trim_warning_needed());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn clear_row_cap_trim_warning_allows_reporting_again() {
|
||||
let mut state = TranscriptReflowState::default();
|
||||
|
||||
assert!(state.take_row_cap_trim_warning_needed());
|
||||
state.clear_row_cap_trim_warning();
|
||||
|
||||
assert!(state.take_row_cap_trim_warning_needed());
|
||||
}
|
||||
}
|
||||
|
||||
+2
-18
@@ -11,7 +11,6 @@ use std::sync::Arc;
|
||||
use std::sync::atomic::AtomicBool;
|
||||
use std::sync::atomic::Ordering;
|
||||
use std::time::Duration;
|
||||
use std::time::Instant;
|
||||
|
||||
use crossterm::Command;
|
||||
use crossterm::SynchronizedUpdate;
|
||||
@@ -482,13 +481,6 @@ pub struct Tui {
|
||||
alt_screen_enabled: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Clone, Copy)]
|
||||
pub(crate) struct ResizeReflowDrawStats {
|
||||
pub(crate) history_flush_elapsed: Duration,
|
||||
pub(crate) history_flush_line_count: usize,
|
||||
pub(crate) flushed_history: bool,
|
||||
}
|
||||
|
||||
impl Tui {
|
||||
pub fn new(terminal: Terminal) -> Self {
|
||||
let (draw_tx, _) = broadcast::channel(1);
|
||||
@@ -916,7 +908,7 @@ impl Tui {
|
||||
&mut self,
|
||||
height: u16,
|
||||
draw_fn: impl FnOnce(&mut custom_terminal::Frame),
|
||||
) -> Result<ResizeReflowDrawStats> {
|
||||
) -> Result<()> {
|
||||
// If we are resuming from ^Z, we need to prepare the resume action now so we can apply it
|
||||
// in the synchronized update.
|
||||
#[cfg(unix)]
|
||||
@@ -925,7 +917,6 @@ impl Tui {
|
||||
.prepare_resume_action(&mut self.terminal, &mut self.alt_saved_viewport);
|
||||
|
||||
stdout().sync_update(|_| {
|
||||
let mut stats = ResizeReflowDrawStats::default();
|
||||
#[cfg(unix)]
|
||||
if let Some(prepared) = prepared_resume.take() {
|
||||
prepared.apply(&mut self.terminal)?;
|
||||
@@ -934,16 +925,11 @@ impl Tui {
|
||||
let terminal = &mut self.terminal;
|
||||
let mut needs_full_repaint =
|
||||
Self::update_inline_viewport_for_resize_reflow(terminal, height, self.is_zellij)?;
|
||||
let history_flush_line_count = self.pending_history_lines.len();
|
||||
let history_flush_start = Instant::now();
|
||||
let flushed_history = Self::flush_pending_history_lines(
|
||||
terminal,
|
||||
&mut self.pending_history_lines,
|
||||
self.is_zellij,
|
||||
)?;
|
||||
stats.history_flush_elapsed = history_flush_start.elapsed();
|
||||
stats.history_flush_line_count = history_flush_line_count;
|
||||
stats.flushed_history = history_flush_line_count > 0;
|
||||
needs_full_repaint |= flushed_history;
|
||||
let flushed_reflow_history = Self::flush_pending_reflow_history_lines(
|
||||
terminal,
|
||||
@@ -972,9 +958,7 @@ impl Tui {
|
||||
|
||||
terminal.draw(|frame| {
|
||||
draw_fn(frame);
|
||||
})?;
|
||||
|
||||
Ok(stats)
|
||||
})
|
||||
})?
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user