diff --git a/codex-rs/tui/src/chatwidget.rs b/codex-rs/tui/src/chatwidget.rs index a23a0efbd3..6b45b9b2f9 100644 --- a/codex-rs/tui/src/chatwidget.rs +++ b/codex-rs/tui/src/chatwidget.rs @@ -633,6 +633,8 @@ pub(crate) struct ChatWidget { forked_from: Option, interrupted_turn_notice_mode: InterruptedTurnNoticeMode, frame_requester: FrameRequester, + // Shared by the placeholder and configured headers so startup motion does not restart while + // session metadata arrives. startup_logo_animation: Option, // Whether to include the initial welcome banner on session configured show_welcome_banner: bool, @@ -1159,6 +1161,8 @@ impl ChatWidget { if let Some(pet) = self.ambient_pet.as_ref() { pet.schedule_next_frame(); } + // Session-header cells expose a tick only while the one-shot mascot motion is active. + // Once it expires, settle configured session info into stable transcript history. if self.startup_logo_animation.is_some() { if self .transcript @@ -1495,7 +1499,10 @@ impl ChatWidget { Box::new(header) } - /// Merge the real session info cell with any placeholder header to avoid double boxes. + /// Merge configured session info with the placeholder while preserving startup mascot motion. + /// + /// The configured header remains active until the shared startup animation settles, avoiding a + /// second header box and keeping transcript history static after the eventual flush. fn apply_session_info_cell(&mut self, cell: history_cell::SessionInfoCell) { let mut session_info_cell = Some(Box::new(cell) as Box); let merged_header = if let Some(active) = self.transcript.active_cell.take() { diff --git a/codex-rs/tui/src/chatwidget/constructor.rs b/codex-rs/tui/src/chatwidget/constructor.rs index 09e41d3405..a141916c66 100644 --- a/codex-rs/tui/src/chatwidget/constructor.rs +++ b/codex-rs/tui/src/chatwidget/constructor.rs @@ -61,6 +61,7 @@ impl ChatWidget { settings: fallback_default, }; + // Select startup motion once so the placeholder and configured headers share one clock. let startup_logo_animation = config.animations.then(codex_logo::startup_animation); let active_cell = Some(Self::placeholder_session_header_cell( &config, diff --git a/codex-rs/tui/src/chatwidget/session_flow.rs b/codex-rs/tui/src/chatwidget/session_flow.rs index 061ce897cb..69be9a555d 100644 --- a/codex-rs/tui/src/chatwidget/session_flow.rs +++ b/codex-rs/tui/src/chatwidget/session_flow.rs @@ -121,6 +121,7 @@ impl ChatWidget { show_fast_status, ); if let Some(animation) = self.startup_logo_animation { + // Continue the placeholder's original motion instead of restarting at handoff. session_info_cell = session_info_cell.with_startup_logo_animation(animation); } self.apply_session_info_cell(session_info_cell); diff --git a/codex-rs/tui/src/codex_logo.rs b/codex-rs/tui/src/codex_logo.rs index 1e28bc6fa3..f1390f3a1d 100644 --- a/codex-rs/tui/src/codex_logo.rs +++ b/codex-rs/tui/src/codex_logo.rs @@ -1,3 +1,16 @@ +//! Unicode mascot rendering primitives for the startup session header. +//! +//! This module owns the small amount of runtime state needed to animate the generated frame +//! tables in `codex_logo_frames`. It does not decide where the mascot is rendered or schedule +//! redraws; the session-header cell renders the selected frame and `ChatWidget` drives the +//! lifecycle while the header remains active. +//! +//! A startup animation is intentionally copyable. The placeholder header created before session +//! configuration and the configured session header must share the same selected motion and +//! `Instant`, otherwise the mascot can restart or switch motions when session metadata arrives. +//! Once the fixed startup window expires, callers render `STATIC_FRAME` and stop scheduling +//! mascot redraws. + use crate::codex_logo_frames::BLINK_FRAMES; use crate::codex_logo_frames::READ_BELOW_FRAMES; use crate::codex_logo_frames::THINKING_FRAMES; @@ -11,6 +24,7 @@ pub(crate) use crate::codex_logo_frames::HEIGHT; pub(crate) use crate::codex_logo_frames::LogoFrame; pub(crate) use crate::codex_logo_frames::WIDTH; +/// Number of columns reserved between the mascot and session text. pub(crate) const GAP_WIDTH: usize = 1; const ANIMATION_FRAME_MILLIS: u64 = 200; @@ -36,6 +50,7 @@ const DARK_GRADIENT: [(u8, u8, u8); HEIGHT] = [ (27, 57, 176), ]; +/// Motion sequences eligible for the one-shot startup animation. #[derive(Clone, Copy, Debug, Eq, PartialEq)] pub(crate) enum StartupAnimationKind { ReadBelow, @@ -43,6 +58,11 @@ pub(crate) enum StartupAnimationKind { Working, } +/// Selected startup motion and the clock origin shared across header handoffs. +/// +/// Keep this value intact when replacing the placeholder header with configured session +/// information. Constructing another value during that handoff would restart the animation and +/// could choose a different motion. #[derive(Clone, Copy, Debug, Eq, PartialEq)] pub(crate) struct StartupAnimation { kind: StartupAnimationKind, @@ -55,8 +75,10 @@ const STARTUP_ANIMATION_KINDS: [StartupAnimationKind; 3] = [ StartupAnimationKind::ReadBelow, ]; +/// Reference frame rendered after startup motion settles or when animations are disabled. pub(crate) const STATIC_FRAME: LogoFrame = BLINK_FRAMES[0]; +/// Starts one randomly selected mascot motion at the current instant. pub(crate) fn startup_animation() -> StartupAnimation { let mut rng = rand::rng(); StartupAnimation { @@ -65,14 +87,19 @@ pub(crate) fn startup_animation() -> StartupAnimation { } } +/// Returns the total lifetime of the one-shot startup motion. pub(crate) fn startup_animation_duration() -> Duration { Duration::from_millis(ANIMATION_FRAME_MILLIS * FRAME_COUNT as u64 * STARTUP_ANIMATION_LOOPS) } +/// Returns the redraw cadence expected while startup motion is active. pub(crate) fn animation_frame_interval() -> Duration { Duration::from_millis(ANIMATION_FRAME_MILLIS) } +/// Returns the current frame tick while startup motion remains active. +/// +/// `None` means the caller should settle the header to `STATIC_FRAME` and stop scheduling redraws. pub(crate) fn animation_tick(animation: StartupAnimation) -> Option { let elapsed = animation.start.elapsed(); if elapsed >= startup_animation_duration() { @@ -82,10 +109,12 @@ pub(crate) fn animation_tick(animation: StartupAnimation) -> Option { } } +/// Resolves the generated mascot frame for an active animation tick. pub(crate) fn frame_for_tick(animation: StartupAnimation, tick: u64) -> &'static LogoFrame { &animation_frames(animation.kind)[tick as usize % FRAME_COUNT] } +/// Selects a readable static mascot gradient for the terminal background. pub(crate) fn gradient_for_bg(bg: Option<(u8, u8, u8)>) -> [(u8, u8, u8); HEIGHT] { if bg.is_some_and(color::is_light) { DARK_GRADIENT @@ -94,6 +123,7 @@ pub(crate) fn gradient_for_bg(bg: Option<(u8, u8, u8)>) -> [(u8, u8, u8); HEIGHT } } +/// Selects the mascot gradient for an active tick, including the moving highlight row. pub(crate) fn gradient_for_animation_tick( bg: Option<(u8, u8, u8)>, tick: u64, diff --git a/codex-rs/tui/src/history_cell/mod.rs b/codex-rs/tui/src/history_cell/mod.rs index b09f66adec..ce308cd629 100644 --- a/codex-rs/tui/src/history_cell/mod.rs +++ b/codex-rs/tui/src/history_cell/mod.rs @@ -297,6 +297,11 @@ pub(crate) trait HistoryCell: std::fmt::Debug + Send + Sync + Any { } /// Settles transient visuals before an active cell is committed to transcript history. + /// + /// Implementations with time-dependent rendering should discard that state here so committed + /// history remains stable and does not require redraw scheduling. `ChatWidget` calls this when + /// flushing an active cell; forgetting to forward it through wrapper cells can leave transcript + /// history dependent on an expired animation clock. fn finalize_for_history(&mut self) {} } diff --git a/codex-rs/tui/src/history_cell/session.rs b/codex-rs/tui/src/history_cell/session.rs index bf9e46e04a..16834bb6e0 100644 --- a/codex-rs/tui/src/history_cell/session.rs +++ b/codex-rs/tui/src/history_cell/session.rs @@ -120,10 +120,17 @@ impl HistoryCell for TooltipHistoryCell { } } +/// Session header plus any startup guidance or tooltip cells rendered with it. #[derive(Debug)] pub struct SessionInfoCell(CompositeHistoryCell); impl SessionInfoCell { + /// Preserves a startup mascot animation when configured session information replaces a placeholder. + /// + /// `new_session_info` always includes one `SessionHeaderHistoryCell`. This method locates that + /// nested header so the placeholder and configured header can share the same selected motion + /// and clock origin. If the session-info composition changes, keep this propagation path + /// intact or the startup mascot will stop or restart during the handoff. pub(crate) fn with_startup_logo_animation( mut self, animation: codex_logo::StartupAnimation, @@ -266,6 +273,11 @@ pub(crate) fn has_yolo_permissions( } ) } +/// Header card rendered while a session is configuring and after its metadata arrives. +/// +/// The same type is used for the dim placeholder and configured header so both layouts follow the +/// same mascot width and fallback rules. `logo_animation` is transient: active cells may render +/// time-dependent frames, while committed history must be finalized to the static reference frame. #[derive(Debug)] pub(crate) struct SessionHeaderHistoryCell { version: &'static str, @@ -321,6 +333,10 @@ impl SessionHeaderHistoryCell { self } + /// Attaches transient startup mascot state to this header. + /// + /// Pass through the original `StartupAnimation` when replacing a placeholder header. Creating + /// a new value here would restart the clock and may switch the selected motion mid-startup. pub(crate) fn with_startup_logo_animation( mut self, animation: codex_logo::StartupAnimation, @@ -459,6 +475,9 @@ impl HistoryCell for SessionHeaderHistoryCell { }; let text_lines = build_text_lines(text_width); + // Rebuild text against the full inner width when the side-by-side layout cannot fit. + // Reusing `text_lines` would keep the directory truncated for mascot space after the + // mascot itself has been removed. if !show_logo || text_lines.iter().any(|line| line_width(line) > text_width) { return with_border(build_text_lines(inner_width)); }