use super::*;
pub(super) fn tui_perf_enabled(_state: &state::MissionControlState) -> bool {
#[cfg(any(test, debug_assertions))]
{
_state.perf.enabled()
}
#[cfg(not(any(test, debug_assertions)))]
{
false
}
}
pub(super) fn draw_frame<B>(
terminal: &mut ratatui::Terminal<B>,
state: &mut state::MissionControlState,
last_area: &mut ratatui::layout::Rect,
_receiver: &Receiver<TuiEvent>,
redraw_intent: &mut RedrawIntent,
drain_budget_state: &mut DrainLoopBudgetState,
) -> Result<bool>
where
B: ratatui::backend::Backend,
B::Error: Send + Sync + 'static,
{
#[cfg(any(test, debug_assertions))]
let input_paint_started = drain_budget_state.take_input_paint_started();
state
.focused_conversation_mut()
.begin_final_assistant_plain_first_paint();
#[cfg(any(test, debug_assertions))]
let draw_started = if state.perf.enabled() {
state.perf.set_backlog_before_draw(_receiver.len());
state.perf.reset_projected_cards();
Some(Instant::now())
} else {
None
};
let focused = state.focused_conversation_mut();
if focused.images.borrow().enabled() {
focused.images.borrow_mut().cell_pixels =
terminal::graphics::current_cell_pixels().unwrap_or_default();
}
let draw_result = terminal.draw(|frame| {
*last_area = frame.area();
render::draw(frame, state);
});
#[cfg(any(test, debug_assertions))]
if draw_result.is_ok() {
let completed_at = Instant::now();
if let Some(started) = draw_started {
state
.perf
.record_draw_us(completed_at.duration_since(started).as_micros() as u64);
}
if let Some(started) = input_paint_started {
state.perf.record_prompt_edit_to_draw_us(
completed_at.duration_since(started).as_micros() as u64,
);
}
}
draw_result?;
crate::tui::release_notes::confirm_draw(state);
let focused = state.focused_conversation_mut();
if focused.images.borrow().enabled() {
terminal::graphics::draw_images(&focused.images.borrow().placements)?;
} else {
terminal::graphics::draw_images(&[])?;
}
focused.images.borrow_mut().start_next_request();
redraw_intent.clear();
let continue_after_pending_draw = drain_budget_state.after_draw();
let final_plain_refresh = state
.focused_conversation_mut()
.finish_final_assistant_plain_first_paint();
if final_plain_refresh {
redraw_intent.request_immediate();
}
Ok(continue_after_pending_draw || final_plain_refresh)
}