feat: skip animations on small terminals (#3647)
Changes: - skip the welcome animation when the terminal area is below 60x21 - skip the model upgrade animation when the terminal area is below 60x24 to avoid clipping --------- Co-authored-by: Michael Bolin <mbolin@openai.com>
This commit is contained in:
committed by
GitHub
parent
f037b2fd56
commit
934d728946
@@ -22,6 +22,8 @@ use std::time::Duration;
|
|||||||
use tokio_stream::StreamExt;
|
use tokio_stream::StreamExt;
|
||||||
|
|
||||||
const FRAME_TICK: Duration = FRAME_TICK_DEFAULT;
|
const FRAME_TICK: Duration = FRAME_TICK_DEFAULT;
|
||||||
|
const MIN_ANIMATION_HEIGHT: u16 = 24;
|
||||||
|
const MIN_ANIMATION_WIDTH: u16 = 60;
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||||
pub(crate) enum ModelUpgradeDecision {
|
pub(crate) enum ModelUpgradeDecision {
|
||||||
@@ -121,13 +123,17 @@ impl WidgetRef for &ModelUpgradePopup {
|
|||||||
fn render_ref(&self, area: Rect, buf: &mut Buffer) {
|
fn render_ref(&self, area: Rect, buf: &mut Buffer) {
|
||||||
Clear.render(area, buf);
|
Clear.render(area, buf);
|
||||||
|
|
||||||
let mut lines: Vec<Line> = self.frames()[self.frame_idx]
|
// Skip the animation entirely when the viewport is too small so we don't clip frames.
|
||||||
.lines()
|
let show_animation =
|
||||||
.map(|l| l.to_string().into())
|
area.height >= MIN_ANIMATION_HEIGHT && area.width >= MIN_ANIMATION_WIDTH;
|
||||||
.collect();
|
|
||||||
|
|
||||||
// Spacer between animation and text content.
|
let mut lines: Vec<Line> = Vec::new();
|
||||||
lines.push("".into());
|
if show_animation {
|
||||||
|
let frame = self.frames()[self.frame_idx];
|
||||||
|
lines.extend(frame.lines().map(|l| l.into()));
|
||||||
|
// Spacer between animation and text content.
|
||||||
|
lines.push("".into());
|
||||||
|
}
|
||||||
|
|
||||||
lines.push(
|
lines.push(
|
||||||
format!(" Codex is now powered by {GPT_5_CODEX_DISPLAY_NAME}, a new model that is")
|
format!(" Codex is now powered by {GPT_5_CODEX_DISPLAY_NAME}, a new model that is")
|
||||||
|
|||||||
@@ -17,6 +17,8 @@ use std::time::Duration;
|
|||||||
use std::time::Instant;
|
use std::time::Instant;
|
||||||
|
|
||||||
const FRAME_TICK: Duration = FRAME_TICK_DEFAULT;
|
const FRAME_TICK: Duration = FRAME_TICK_DEFAULT;
|
||||||
|
const MIN_ANIMATION_HEIGHT: u16 = 21;
|
||||||
|
const MIN_ANIMATION_WIDTH: u16 = 60;
|
||||||
|
|
||||||
pub(crate) struct WelcomeWidget {
|
pub(crate) struct WelcomeWidget {
|
||||||
pub is_logged_in: bool,
|
pub is_logged_in: bool,
|
||||||
@@ -44,11 +46,17 @@ impl WidgetRef for &WelcomeWidget {
|
|||||||
|
|
||||||
let frames = &FRAMES_DEFAULT;
|
let frames = &FRAMES_DEFAULT;
|
||||||
let idx = ((elapsed_ms / FRAME_TICK.as_millis()) % frames.len() as u128) as usize;
|
let idx = ((elapsed_ms / FRAME_TICK.as_millis()) % frames.len() as u128) as usize;
|
||||||
|
// Skip the animation entirely when the viewport is too small so we don't clip frames.
|
||||||
|
let show_animation =
|
||||||
|
area.height >= MIN_ANIMATION_HEIGHT && area.width >= MIN_ANIMATION_WIDTH;
|
||||||
|
|
||||||
let mut lines: Vec<Line> = Vec::with_capacity(frames.len() + 2);
|
let mut lines: Vec<Line> = Vec::new();
|
||||||
lines.extend(frames[idx].lines().map(|l| l.into()));
|
if show_animation {
|
||||||
|
let frame_line_count = frames[idx].lines().count();
|
||||||
lines.push("".into());
|
lines.reserve(frame_line_count + 2);
|
||||||
|
lines.extend(frames[idx].lines().map(|l| l.into()));
|
||||||
|
lines.push("".into());
|
||||||
|
}
|
||||||
lines.push(Line::from(vec![
|
lines.push(Line::from(vec![
|
||||||
" ".into(),
|
" ".into(),
|
||||||
"Welcome to ".into(),
|
"Welcome to ".into(),
|
||||||
|
|||||||
Reference in New Issue
Block a user