Login flow polish (#3632)

# Description
- Update sign in flow

# Tests
- Passes CI

---------

Co-authored-by: Michael Bolin <mbolin@openai.com>
This commit is contained in:
Ed Bayes
2025-09-15 00:42:53 -07:00
committed by GitHub
parent 2d52e3b40a
commit b9af1d2b16
12 changed files with 168 additions and 108 deletions

View File

@@ -3,23 +3,62 @@ use ratatui::layout::Rect;
use ratatui::prelude::Widget;
use ratatui::style::Stylize;
use ratatui::text::Line;
use ratatui::widgets::Paragraph;
use ratatui::widgets::WidgetRef;
use ratatui::widgets::Wrap;
use crate::frames::FRAME_TICK_DEFAULT;
use crate::frames::FRAMES_DEFAULT;
use crate::onboarding::onboarding_screen::StepStateProvider;
use crate::tui::FrameRequester;
use super::onboarding_screen::StepState;
use std::time::Duration;
use std::time::Instant;
const FRAME_TICK: Duration = FRAME_TICK_DEFAULT;
pub(crate) struct WelcomeWidget {
pub is_logged_in: bool,
pub request_frame: FrameRequester,
pub start: Instant,
}
impl WidgetRef for &WelcomeWidget {
fn render_ref(&self, area: Rect, buf: &mut Buffer) {
let line = Line::from(vec![
">_ ".into(),
"Welcome to Codex, OpenAI's command-line coding agent".bold(),
]);
line.render(area, buf);
let elapsed_ms = self.start.elapsed().as_millis();
// Align next draw to the next FRAME_TICK boundary to reduce jitter.
{
let tick_ms = FRAME_TICK.as_millis();
let rem_ms = elapsed_ms % tick_ms;
let delay_ms = if rem_ms == 0 {
tick_ms
} else {
tick_ms - rem_ms
};
// Safe cast: delay_ms < tick_ms and FRAME_TICK is small.
self.request_frame
.schedule_frame_in(Duration::from_millis(delay_ms as u64));
}
let frames = &FRAMES_DEFAULT;
let idx = ((elapsed_ms / FRAME_TICK.as_millis()) % frames.len() as u128) as usize;
let mut lines: Vec<Line> = Vec::with_capacity(frames.len() + 2);
lines.extend(frames[idx].lines().map(|l| l.into()));
lines.push("".into());
lines.push(Line::from(vec![
" ".into(),
"Welcome to ".into(),
"Codex".bold(),
", OpenAI's command-line coding agent".into(),
]));
Paragraph::new(lines)
.wrap(Wrap { trim: false })
.render(area, buf);
}
}
@@ -31,3 +70,14 @@ impl StepStateProvider for WelcomeWidget {
}
}
}
#[cfg(test)]
mod tests {
use super::*;
/// A number of things break down if FRAME_TICK is zero.
#[test]
fn frame_tick_must_be_nonzero() {
assert!(FRAME_TICK.as_millis() > 0);
}
}