mirror of
https://github.com/openai/codex.git
synced 2026-05-05 22:01:37 +03:00
Use markdown for migration screen (#8952)
Next steps will be routing this to model info
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
use crate::key_hint;
|
||||
use crate::markdown_render::render_markdown_text_with_width;
|
||||
use crate::render::Insets;
|
||||
use crate::render::renderable::ColumnRenderable;
|
||||
use crate::render::renderable::Renderable;
|
||||
@@ -34,6 +35,7 @@ pub(crate) struct ModelMigrationCopy {
|
||||
pub heading: Vec<Span<'static>>,
|
||||
pub content: Vec<Line<'static>>,
|
||||
pub can_opt_out: bool,
|
||||
pub markdown: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
@@ -55,15 +57,30 @@ impl MigrationMenuOption {
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub(crate) fn migration_copy_for_models(
|
||||
current_model: &str,
|
||||
target_model: &str,
|
||||
model_link: Option<String>,
|
||||
migration_copy: Option<String>,
|
||||
migration_markdown: Option<String>,
|
||||
target_display_name: String,
|
||||
target_description: Option<String>,
|
||||
can_opt_out: bool,
|
||||
) -> ModelMigrationCopy {
|
||||
if let Some(migration_markdown) = migration_markdown {
|
||||
return ModelMigrationCopy {
|
||||
heading: Vec::new(),
|
||||
content: Vec::new(),
|
||||
can_opt_out,
|
||||
markdown: Some(fill_migration_markdown(
|
||||
&migration_markdown,
|
||||
current_model,
|
||||
target_model,
|
||||
)),
|
||||
};
|
||||
}
|
||||
|
||||
let heading_text = Span::from(format!(
|
||||
"Codex just got an upgrade. Introducing {target_display_name}."
|
||||
))
|
||||
@@ -113,6 +130,7 @@ pub(crate) fn migration_copy_for_models(
|
||||
heading: vec![heading_text],
|
||||
content,
|
||||
can_opt_out,
|
||||
markdown: None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -237,9 +255,13 @@ impl WidgetRef for &ModelMigrationScreen {
|
||||
|
||||
let mut column = ColumnRenderable::new();
|
||||
column.push("");
|
||||
column.push(self.heading_line());
|
||||
column.push(Line::from(""));
|
||||
self.render_content(&mut column);
|
||||
if let Some(markdown) = self.copy.markdown.as_ref() {
|
||||
self.render_markdown_content(markdown, area.width, &mut column);
|
||||
} else {
|
||||
column.push(self.heading_line());
|
||||
column.push(Line::from(""));
|
||||
self.render_content(&mut column);
|
||||
}
|
||||
if self.copy.can_opt_out {
|
||||
self.render_menu(&mut column);
|
||||
}
|
||||
@@ -290,6 +312,21 @@ impl ModelMigrationScreen {
|
||||
}
|
||||
}
|
||||
|
||||
fn render_markdown_content(
|
||||
&self,
|
||||
markdown: &str,
|
||||
area_width: u16,
|
||||
column: &mut ColumnRenderable,
|
||||
) {
|
||||
let horizontal_inset = 2;
|
||||
let content_width = area_width.saturating_sub(horizontal_inset);
|
||||
let wrap_width = (content_width > 0).then_some(content_width as usize);
|
||||
let rendered = render_markdown_text_with_width(markdown, wrap_width);
|
||||
for line in rendered.lines {
|
||||
column.push(line.inset(Insets::tlbr(0, horizontal_inset, 0, 0)));
|
||||
}
|
||||
}
|
||||
|
||||
fn render_menu(&self, column: &mut ColumnRenderable) {
|
||||
column.push(Line::from(""));
|
||||
column.push(
|
||||
@@ -348,6 +385,12 @@ fn is_ctrl_exit_combo(key_event: KeyEvent) -> bool {
|
||||
&& matches!(key_event.code, KeyCode::Char('c') | KeyCode::Char('d'))
|
||||
}
|
||||
|
||||
fn fill_migration_markdown(template: &str, current_model: &str, target_model: &str) -> String {
|
||||
template
|
||||
.replace("{model_from}", current_model)
|
||||
.replace("{model_to}", target_model)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::ModelMigrationScreen;
|
||||
@@ -378,6 +421,7 @@ mod tests {
|
||||
"Upgrade to gpt-5.2-codex for the latest and greatest agentic coding model."
|
||||
.to_string(),
|
||||
),
|
||||
None,
|
||||
"gpt-5.1-codex-max".to_string(),
|
||||
Some("Codex-optimized flagship for deep and fast reasoning.".to_string()),
|
||||
true,
|
||||
@@ -406,6 +450,7 @@ mod tests {
|
||||
"gpt-5.1",
|
||||
Some("https://www.codex.com/models/gpt-5.1".to_string()),
|
||||
None,
|
||||
None,
|
||||
"gpt-5.1".to_string(),
|
||||
Some("Broad world knowledge with strong general reasoning.".to_string()),
|
||||
false,
|
||||
@@ -432,6 +477,7 @@ mod tests {
|
||||
"gpt-5.1-codex-max",
|
||||
Some("https://www.codex.com/models/gpt-5.1-codex-max".to_string()),
|
||||
None,
|
||||
None,
|
||||
"gpt-5.1-codex-max".to_string(),
|
||||
Some("Codex-optimized flagship for deep and fast reasoning.".to_string()),
|
||||
false,
|
||||
@@ -458,6 +504,7 @@ mod tests {
|
||||
"gpt-5.1-codex-mini",
|
||||
Some("https://www.codex.com/models/gpt-5.1-codex-mini".to_string()),
|
||||
None,
|
||||
None,
|
||||
"gpt-5.1-codex-mini".to_string(),
|
||||
Some("Optimized for codex. Cheaper, faster, but less capable.".to_string()),
|
||||
false,
|
||||
@@ -480,6 +527,7 @@ mod tests {
|
||||
"gpt-new",
|
||||
Some("https://www.codex.com/models/gpt-new".to_string()),
|
||||
None,
|
||||
None,
|
||||
"gpt-new".to_string(),
|
||||
Some("Latest recommended model for better performance.".to_string()),
|
||||
true,
|
||||
@@ -508,6 +556,7 @@ mod tests {
|
||||
"gpt-new",
|
||||
Some("https://www.codex.com/models/gpt-new".to_string()),
|
||||
None,
|
||||
None,
|
||||
"gpt-new".to_string(),
|
||||
Some("Latest recommended model for better performance.".to_string()),
|
||||
true,
|
||||
|
||||
Reference in New Issue
Block a user