mirror of
https://github.com/openai/codex.git
synced 2026-05-04 05:11:37 +03:00
This PR replicates the `tui` code directory and creates a temporary parallel `tui_app_server` directory. It also implements a new feature flag `tui_app_server` to select between the two tui implementations. Once the new app-server-based TUI is stabilized, we'll delete the old `tui` directory and feature flag.
63 lines
1.9 KiB
Rust
63 lines
1.9 KiB
Rust
use codex_protocol::config_types::CollaborationModeMask;
|
|
use codex_protocol::config_types::ModeKind;
|
|
|
|
use crate::model_catalog::ModelCatalog;
|
|
|
|
fn filtered_presets(model_catalog: &ModelCatalog) -> Vec<CollaborationModeMask> {
|
|
model_catalog
|
|
.list_collaboration_modes()
|
|
.into_iter()
|
|
.filter(|mask| mask.mode.is_some_and(ModeKind::is_tui_visible))
|
|
.collect()
|
|
}
|
|
|
|
pub(crate) fn presets_for_tui(model_catalog: &ModelCatalog) -> Vec<CollaborationModeMask> {
|
|
filtered_presets(model_catalog)
|
|
}
|
|
|
|
pub(crate) fn default_mask(model_catalog: &ModelCatalog) -> Option<CollaborationModeMask> {
|
|
let presets = filtered_presets(model_catalog);
|
|
presets
|
|
.iter()
|
|
.find(|mask| mask.mode == Some(ModeKind::Default))
|
|
.cloned()
|
|
.or_else(|| presets.into_iter().next())
|
|
}
|
|
|
|
pub(crate) fn mask_for_kind(
|
|
model_catalog: &ModelCatalog,
|
|
kind: ModeKind,
|
|
) -> Option<CollaborationModeMask> {
|
|
if !kind.is_tui_visible() {
|
|
return None;
|
|
}
|
|
filtered_presets(model_catalog)
|
|
.into_iter()
|
|
.find(|mask| mask.mode == Some(kind))
|
|
}
|
|
|
|
/// Cycle to the next collaboration mode preset in list order.
|
|
pub(crate) fn next_mask(
|
|
model_catalog: &ModelCatalog,
|
|
current: Option<&CollaborationModeMask>,
|
|
) -> Option<CollaborationModeMask> {
|
|
let presets = filtered_presets(model_catalog);
|
|
if presets.is_empty() {
|
|
return None;
|
|
}
|
|
let current_kind = current.and_then(|mask| mask.mode);
|
|
let next_index = presets
|
|
.iter()
|
|
.position(|mask| mask.mode == current_kind)
|
|
.map_or(0, |idx| (idx + 1) % presets.len());
|
|
presets.get(next_index).cloned()
|
|
}
|
|
|
|
pub(crate) fn default_mode_mask(model_catalog: &ModelCatalog) -> Option<CollaborationModeMask> {
|
|
mask_for_kind(model_catalog, ModeKind::Default)
|
|
}
|
|
|
|
pub(crate) fn plan_mask(model_catalog: &ModelCatalog) -> Option<CollaborationModeMask> {
|
|
mask_for_kind(model_catalog, ModeKind::Plan)
|
|
}
|