mirror of
https://github.com/openai/codex.git
synced 2026-11-17 22:10:37 +00:00
Add a status line provider picker to /statusline (#61988)
## What changed - Add a "Choose a statusline plugin" action when status line extensions are enabled. Discover MCP providers, show the current selection, and let users save a provider or return to the default status line. - Preserve the highlighted row when discovery completes and start reading provider contents only after an explicit selection. - Keep the item editor open across picker transitions and disconnects, allow switching to the default while offline, and guard transitions against repeated activation keys. - Limit displayed numeric shortcuts to the first nine selectable rows. ## Testing Add tests for discovery focus, stale discovery results, explicit reader activation, repeated Enter keys, disconnect handling, and numeric shortcuts. Extend the terminal integration test to switch between the default status line and an MCP provider through the picker. GitOrigin-RevId: 76a254d7afee3a1b8cfc801617a2176893276e0e
This commit is contained in:
@@ -273,6 +273,7 @@ mod resume_config;
|
||||
mod resume_preparation;
|
||||
mod right_click_paste;
|
||||
mod status_line_settings;
|
||||
mod statusline_picker;
|
||||
pub(crate) use right_click_paste::PasteEnvironment;
|
||||
mod pane_motion;
|
||||
mod safety_buffering;
|
||||
@@ -559,6 +560,7 @@ struct InitialHistoryReplayBuffer {
|
||||
}
|
||||
|
||||
pub(crate) struct App {
|
||||
statusline_picker: Option<statusline_picker::StatuslinePicker>,
|
||||
provider_writes: HashMap<crate::backend_id::BackendId, crate::model_catalog::ProviderWrite>,
|
||||
feature_write_lock: Arc<tokio::sync::Mutex<()>>,
|
||||
config_notification_test_generation: u64,
|
||||
|
||||
@@ -64,6 +64,10 @@ impl App {
|
||||
AppEvent::OpenDaemonMenu
|
||||
| AppEvent::OpenWarnings
|
||||
| AppEvent::StatusLineSetup { .. }
|
||||
| AppEvent::OpenStatuslinePicker(_)
|
||||
| AppEvent::CloseStatuslinePicker(_)
|
||||
| AppEvent::ChooseStatuslineProvider { .. }
|
||||
| AppEvent::StatuslinePicker { .. }
|
||||
| AppEvent::StatusLineSetupCancelled
|
||||
| AppEvent::TerminalTitleSetup { .. }
|
||||
| AppEvent::TerminalTitleSetupPreview { .. }
|
||||
@@ -476,6 +480,23 @@ impl App {
|
||||
}
|
||||
}
|
||||
}
|
||||
AppEvent::OpenStatuslinePicker(key) => {
|
||||
if self.chat_widget.active_view_is(crate::bottom_pane::StatusLineSetupView::VIEW_ID) {
|
||||
self.open_statusline_picker(app_server);
|
||||
self.chat_widget.suppress_current_view_key_until_release(
|
||||
key,
|
||||
Instant::now(),
|
||||
crate::activation_key_guard::ActivationKeySuppression::ViewTransition,
|
||||
);
|
||||
}
|
||||
}
|
||||
AppEvent::CloseStatuslinePicker(scan) => {
|
||||
if self.statusline_picker.as_ref().is_some_and(|picker| picker.id == scan) {
|
||||
self.statusline_picker = None;
|
||||
}
|
||||
}
|
||||
AppEvent::ChooseStatuslineProvider { scan, id, key } => self.choose_statusline_provider(scan, id, key, app_server).await,
|
||||
AppEvent::StatuslinePicker { scan, updates } => self.finish_statusline_discovery(scan, updates, app_server),
|
||||
AppEvent::StatuslineRead(event) => {
|
||||
self.chat_widget.handle_statusline_read(event, app_server);
|
||||
}
|
||||
|
||||
@@ -304,6 +304,9 @@ impl App {
|
||||
self.agents_overview.pending_pin_change = None;
|
||||
self.agents_overview.pending_usage = None;
|
||||
self.agents_overview.usage_disabled = false;
|
||||
self.statusline_picker = None;
|
||||
self.chat_widget
|
||||
.dismiss_provider_view(super::statusline_picker::PICKER);
|
||||
self.reconnect.presentation = if self
|
||||
.chat_widget
|
||||
.selected_index_for_active_view(agents_overview::AGENTS_OVERVIEW_VIEW_ID)
|
||||
|
||||
@@ -573,6 +573,7 @@ impl App {
|
||||
mut chat_widget: ChatWidget,
|
||||
thread_provider: Option<&str>,
|
||||
) {
|
||||
self.statusline_picker = None;
|
||||
chat_widget.inherit_view_transition_key_guard(&mut self.chat_widget);
|
||||
chat_widget.fork_in_progress = self.chat_widget.fork_in_progress;
|
||||
self.pending_right_click_paste = None;
|
||||
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
---
|
||||
source: tui/src/app/statusline_picker_tests.rs
|
||||
expression: "render_bottom_popup(&app.chat_widget, 67)"
|
||||
---
|
||||
Select a status line provider
|
||||
|
||||
|
||||
1. Calendar (current) work / calendar
|
||||
› 2. Default status line
|
||||
3. Alerts health / alerts
|
||||
4. Quota health / quota
|
||||
5. Usage usage / limits
|
||||
|
||||
enter select · esc back
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
---
|
||||
source: tui/src/app/statusline_picker_tests.rs
|
||||
expression: "render_bottom_popup(&app.chat_widget, 67)"
|
||||
---
|
||||
Select a status line provider
|
||||
Plugin providers are unavailable while disconnected.
|
||||
|
||||
|
||||
calendar (Unavailable) (current) work / calendar
|
||||
› 1. Default status line
|
||||
|
||||
enter select · esc back
|
||||
@@ -987,6 +987,7 @@ See the Codex keymap documentation for supported actions and examples."
|
||||
let agents_overview =
|
||||
agents_overview::AgentsOverviewState::new(local_settings.tui.agents_overview_grouping);
|
||||
let mut app = Self {
|
||||
statusline_picker: None,
|
||||
provider_writes,
|
||||
feature_write_lock: Arc::default(),
|
||||
config_notification_test_generation: 0,
|
||||
|
||||
@@ -9,10 +9,6 @@ use codex_config::types::BuiltinStatusLine;
|
||||
use codex_config::types::StatusLineSelection;
|
||||
|
||||
impl App {
|
||||
#[cfg_attr(
|
||||
not(test),
|
||||
expect(dead_code, reason = "called by the upcoming provider picker")
|
||||
)]
|
||||
pub(super) async fn save_status_line_provider(
|
||||
&mut self,
|
||||
provider: StatusLineSelection,
|
||||
|
||||
@@ -0,0 +1,275 @@
|
||||
//! Discover providers for the open statusline picker and apply explicit selections.
|
||||
|
||||
use super::*;
|
||||
use crate::backend_id::BackendId;
|
||||
use crate::bottom_pane::ColumnWidthMode;
|
||||
use crate::bottom_pane::SelectionKeyAction;
|
||||
use crate::config_update::format_config_error;
|
||||
use crate::statusline_provider::ProviderId;
|
||||
use crate::statusline_provider::StatuslineProvider;
|
||||
use crate::statusline_provider::discovery::DiscoveryUpdate;
|
||||
use crate::statusline_provider::discovery::refresh_statusline_providers;
|
||||
use codex_config::types::BuiltinStatusLine;
|
||||
use codex_config::types::StatusLineProviderId;
|
||||
use codex_config::types::StatusLineSelection;
|
||||
use futures::StreamExt;
|
||||
use tokio_util::task::AbortOnDropHandle;
|
||||
|
||||
pub(super) const PICKER: &str = "statusline-providers";
|
||||
|
||||
pub(super) struct StatuslinePicker {
|
||||
pub(super) id: Uuid,
|
||||
backend: BackendId,
|
||||
thread: Option<ThreadId>,
|
||||
selected: Option<ProviderId>,
|
||||
providers: Vec<StatuslineProvider>,
|
||||
offline: bool,
|
||||
worker: Option<AbortOnDropHandle<()>>,
|
||||
}
|
||||
|
||||
fn label(text: String) -> String {
|
||||
crate::ui_tree::sanitize_leaf(text).replace(['\n', '\t'], " ")
|
||||
}
|
||||
|
||||
impl StatuslinePicker {
|
||||
fn provider(&self, id: &ProviderId) -> Option<&StatuslineProvider> {
|
||||
self.providers.iter().find(|provider| provider.id == *id)
|
||||
}
|
||||
|
||||
fn choose(&self, id: Option<ProviderId>) -> SelectionKeyAction {
|
||||
let scan = self.id;
|
||||
Box::new(move |tx, key| {
|
||||
tx.send(AppEvent::ChooseStatuslineProvider {
|
||||
scan,
|
||||
id: id.clone(),
|
||||
key,
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
fn provider_row(
|
||||
&self,
|
||||
id: &ProviderId,
|
||||
provider: Option<&StatuslineProvider>,
|
||||
) -> SelectionItem {
|
||||
let saved = StatusLineProviderId::from(id);
|
||||
let current = self.selected.as_ref() == Some(id);
|
||||
let mut name = match provider {
|
||||
Some(provider) => provider.title.clone(),
|
||||
None => label(saved.tool.clone()),
|
||||
};
|
||||
if let Some(plugin) = provider.and_then(|p| p.plugin_label.as_ref()) {
|
||||
name = format!("{name} · {plugin}");
|
||||
}
|
||||
if self.offline || (self.worker.is_none() && provider.is_none()) {
|
||||
name.push_str(" (Unavailable)");
|
||||
}
|
||||
SelectionItem {
|
||||
name,
|
||||
description: Some(label(format!("{} / {}", saved.server, saved.tool))),
|
||||
is_current: current,
|
||||
is_disabled: self.offline,
|
||||
on_accept_key: Some(self.choose(Some(id.clone()))),
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
|
||||
fn view(&self, initial_selected_idx: Option<usize>) -> SelectionViewParams {
|
||||
let mut items = Vec::new();
|
||||
if let Some(id) = &self.selected {
|
||||
items.push(self.provider_row(id, self.provider(id)));
|
||||
}
|
||||
items.push(SelectionItem {
|
||||
name: "Default status line".into(),
|
||||
is_current: self.selected.is_none(),
|
||||
on_accept_key: Some(self.choose(/*id*/ None)),
|
||||
..Default::default()
|
||||
});
|
||||
for provider in &self.providers {
|
||||
if Some(&provider.id) != self.selected.as_ref() {
|
||||
items.push(self.provider_row(&provider.id, Some(provider)));
|
||||
}
|
||||
}
|
||||
let subtitle = if self.offline {
|
||||
Some("Plugin providers are unavailable while disconnected.")
|
||||
} else {
|
||||
self.worker
|
||||
.as_ref()
|
||||
.map(|_| "Discovering MCP status line providers…")
|
||||
};
|
||||
let scan = self.id;
|
||||
SelectionViewParams {
|
||||
view_id: Some(PICKER),
|
||||
title: Some("Select a status line provider".into()),
|
||||
subtitle: subtitle.map(str::to_owned),
|
||||
items,
|
||||
initial_selected_idx,
|
||||
col_width_mode: ColumnWidthMode::AutoVisible,
|
||||
allow_input_when_disconnected: self.offline,
|
||||
on_cancel: Some(Box::new(move |tx| {
|
||||
tx.send(AppEvent::CloseStatuslinePicker(scan))
|
||||
})),
|
||||
..SelectionViewParams::picker()
|
||||
}
|
||||
}
|
||||
|
||||
fn applies_to(
|
||||
&mut self,
|
||||
thread: Option<ThreadId>,
|
||||
backend: BackendId,
|
||||
config: &Config,
|
||||
) -> bool {
|
||||
if self.backend != backend || !config.features.enabled(Feature::TuiExtensionsStatusLine) {
|
||||
return false;
|
||||
}
|
||||
// The picker may open before the displayed thread receives its ID.
|
||||
self.thread = self.thread.or(thread);
|
||||
self.thread == thread
|
||||
}
|
||||
}
|
||||
|
||||
impl App {
|
||||
pub(super) fn open_statusline_picker(&mut self, owner: &AppServerSession) {
|
||||
if !self
|
||||
.config
|
||||
.features
|
||||
.enabled(Feature::TuiExtensionsStatusLine)
|
||||
{
|
||||
return;
|
||||
}
|
||||
let selected = self
|
||||
.chat_widget
|
||||
.configured_statusline_provider()
|
||||
.map(ProviderId::from);
|
||||
let id = Uuid::new_v4();
|
||||
let worker = (!self.reconnect.offline).then(|| {
|
||||
let known = selected.iter().map(|id| id.server.clone()).collect();
|
||||
let stream = refresh_statusline_providers(owner.request_handle(), known);
|
||||
let events = self.app_event_tx.clone();
|
||||
AbortOnDropHandle::new(tokio::spawn(async move {
|
||||
events.send(AppEvent::StatuslinePicker {
|
||||
scan: id,
|
||||
updates: stream.collect().await,
|
||||
});
|
||||
}))
|
||||
});
|
||||
let picker = StatuslinePicker {
|
||||
id,
|
||||
backend: owner.backend_id(),
|
||||
thread: self.chat_widget.thread_id(),
|
||||
selected,
|
||||
providers: Vec::new(),
|
||||
offline: self.reconnect.offline,
|
||||
worker,
|
||||
};
|
||||
self.chat_widget
|
||||
.show_selection_view(picker.view(/*initial_selected_idx*/ None));
|
||||
self.statusline_picker = Some(picker);
|
||||
}
|
||||
|
||||
fn statusline_picker_for(
|
||||
&mut self,
|
||||
scan: Uuid,
|
||||
owner: &AppServerSession,
|
||||
) -> Option<&mut StatuslinePicker> {
|
||||
let picker = self
|
||||
.statusline_picker
|
||||
.as_mut()
|
||||
.filter(|picker| picker.id == scan)?;
|
||||
if self
|
||||
.chat_widget
|
||||
.selected_index_for_present_view(PICKER)
|
||||
.is_none()
|
||||
|| !picker.applies_to(
|
||||
self.chat_widget.thread_id(),
|
||||
owner.backend_id(),
|
||||
&self.config,
|
||||
)
|
||||
{
|
||||
self.statusline_picker = None;
|
||||
return None;
|
||||
}
|
||||
self.statusline_picker.as_mut()
|
||||
}
|
||||
|
||||
pub(super) fn finish_statusline_discovery(
|
||||
&mut self,
|
||||
scan: Uuid,
|
||||
updates: Vec<DiscoveryUpdate>,
|
||||
owner: &AppServerSession,
|
||||
) {
|
||||
let selected_index = self.chat_widget.selected_index_for_present_view(PICKER);
|
||||
let Some(picker) = self.statusline_picker_for(scan, owner) else {
|
||||
return;
|
||||
};
|
||||
if picker.worker.take().is_none() {
|
||||
return;
|
||||
}
|
||||
for update in updates {
|
||||
let DiscoveryUpdate::Server(_server, Ok(mut providers)) = update else {
|
||||
continue;
|
||||
};
|
||||
for provider in &mut providers {
|
||||
provider.title = label(std::mem::take(&mut provider.title));
|
||||
provider.plugin_label = provider.plugin_label.take().map(label);
|
||||
}
|
||||
picker.providers.extend(providers);
|
||||
}
|
||||
picker
|
||||
.providers
|
||||
.sort_unstable_by(|a, b| (&a.title, &a.id).cmp(&(&b.title, &b.id)));
|
||||
let view = picker.view(selected_index);
|
||||
self.chat_widget
|
||||
.replace_selection_view_if_present(PICKER, view);
|
||||
}
|
||||
|
||||
pub(super) async fn choose_statusline_provider(
|
||||
&mut self,
|
||||
scan: Uuid,
|
||||
id: Option<ProviderId>,
|
||||
key: crate::key_hint::KeyBinding,
|
||||
owner: &AppServerSession,
|
||||
) {
|
||||
if !self.chat_widget.active_view_is(PICKER) {
|
||||
return;
|
||||
}
|
||||
let offline = self.reconnect.offline;
|
||||
let Some(picker) = self.statusline_picker_for(scan, owner) else {
|
||||
return;
|
||||
};
|
||||
let (selection, provider_from_picker) = match id {
|
||||
None => (
|
||||
StatusLineSelection::Builtin(BuiltinStatusLine::Default),
|
||||
None,
|
||||
),
|
||||
Some(id) => {
|
||||
let provider = picker.provider(&id);
|
||||
if offline || (provider.is_none() && Some(&id) != picker.selected.as_ref()) {
|
||||
return;
|
||||
}
|
||||
(StatusLineSelection::Mcp((&id).into()), provider.cloned())
|
||||
}
|
||||
};
|
||||
if let Err(error) = self
|
||||
.save_status_line_provider(selection, provider_from_picker)
|
||||
.await
|
||||
{
|
||||
self.chat_widget.report_config_save_error(format!(
|
||||
"Failed to save status line selection: {}",
|
||||
format_config_error(&error)
|
||||
));
|
||||
return;
|
||||
}
|
||||
self.statusline_picker = None;
|
||||
self.chat_widget.dismiss_provider_view(PICKER);
|
||||
self.chat_widget.suppress_current_view_key_until_release(
|
||||
key,
|
||||
Instant::now(),
|
||||
crate::activation_key_guard::ActivationKeySuppression::ViewTransition,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "statusline_picker_tests.rs"]
|
||||
mod tests;
|
||||
@@ -0,0 +1,213 @@
|
||||
#![cfg(test)]
|
||||
//! Verify focus during discovery and the handoff from a saved selection to the reader.
|
||||
|
||||
use super::*;
|
||||
use crate::app::tests::make_test_app_with_channels;
|
||||
use crate::app::tests::test_thread_session;
|
||||
use crate::app_server_session::ThreadParamsMode;
|
||||
use crate::chatwidget::tests::render_bottom_popup;
|
||||
use crate::statusline_provider::test_support::advertised;
|
||||
use crate::tui::test_support::make_test_tui;
|
||||
use codex_app_server_client::AppServerClient;
|
||||
use codex_app_server_client::CloudClient;
|
||||
use codex_app_server_client::CloudCommand;
|
||||
use crossterm::event::KeyEvent;
|
||||
use crossterm::event::KeyEventKind;
|
||||
use crossterm::event::KeyModifiers;
|
||||
use pretty_assertions::assert_eq;
|
||||
use tokio::sync::mpsc;
|
||||
|
||||
async fn picker() -> anyhow::Result<(
|
||||
Box<App>,
|
||||
AppServerSession,
|
||||
mpsc::Receiver<CloudCommand>,
|
||||
mpsc::UnboundedReceiver<AppEvent>,
|
||||
)> {
|
||||
let (mut app, events, _) = make_test_app_with_channels().await;
|
||||
app.config
|
||||
.features
|
||||
.enable(Feature::TuiExtensionsStatusLine)?;
|
||||
app.chat_widget
|
||||
.set_feature_enabled(Feature::TuiExtensionsStatusLine, /*enabled*/ true);
|
||||
let (client, commands, _) = CloudClient::channel(/*capacity*/ 8);
|
||||
let owner = AppServerSession::new(
|
||||
BackendId::new(),
|
||||
AppServerClient::Cloud(client),
|
||||
ThreadParamsMode::Cloud,
|
||||
);
|
||||
Ok((app, owner, commands, events))
|
||||
}
|
||||
|
||||
#[tokio::test(start_paused = true)]
|
||||
async fn holding_enter_opens_the_statusline_picker_without_selecting() -> anyhow::Result<()> {
|
||||
let (mut app, mut owner, _commands, mut events) = picker().await?;
|
||||
let mut tui = make_test_tui()?;
|
||||
app.chat_widget
|
||||
.restore_user_message_to_composer("/statusline".into());
|
||||
app.chat_widget.handle_key_event(KeyCode::Enter.into());
|
||||
app.chat_widget.handle_key_event(KeyCode::Enter.into());
|
||||
let open = std::iter::from_fn(|| events.try_recv().ok())
|
||||
.find(|event| matches!(event, AppEvent::OpenStatuslinePicker(_)))
|
||||
.expect("Enter opens the provider picker");
|
||||
crate::boxed_future!(app.handle_event(&mut tui, &mut owner, open))
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
let repeat = KeyEvent::new_with_kind(KeyCode::Enter, KeyModifiers::NONE, KeyEventKind::Repeat);
|
||||
app.chat_widget.handle_key_event(repeat);
|
||||
app.chat_widget.handle_key_event(KeyEvent::new_with_kind(
|
||||
KeyCode::Enter,
|
||||
KeyModifiers::NONE,
|
||||
KeyEventKind::Release,
|
||||
));
|
||||
assert!(
|
||||
!std::iter::from_fn(|| events.try_recv().ok())
|
||||
.any(|event| matches!(event, AppEvent::ChooseStatuslineProvider { .. }))
|
||||
);
|
||||
app.chat_widget.handle_key_event(KeyCode::Enter.into());
|
||||
let choice = std::iter::from_fn(|| events.try_recv().ok())
|
||||
.find(|event| matches!(event, AppEvent::ChooseStatuslineProvider { .. }))
|
||||
.expect("fresh Enter chooses the provider");
|
||||
crate::boxed_future!(app.handle_event(&mut tui, &mut owner, choice))
|
||||
.await
|
||||
.unwrap();
|
||||
assert!(
|
||||
app.chat_widget
|
||||
.active_view_is(crate::bottom_pane::StatusLineSetupView::VIEW_ID)
|
||||
);
|
||||
app.chat_widget.handle_key_event(repeat);
|
||||
assert!(
|
||||
!std::iter::from_fn(|| events.try_recv().ok())
|
||||
.any(|event| matches!(event, AppEvent::OpenStatuslinePicker(_)))
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test(start_paused = true)]
|
||||
async fn statusline_picker_disconnect_leaves_the_item_editor_open() -> anyhow::Result<()> {
|
||||
let (mut app, owner, mut commands, mut events) = picker().await?;
|
||||
app.app_server_target = AppServerTarget::Remote {
|
||||
endpoint: crate::resolve_remote_addr("ws://127.0.0.1:9").unwrap(),
|
||||
};
|
||||
app.chat_widget.local_settings.tui.status_line_use_colors = false;
|
||||
app.chat_widget
|
||||
.restore_user_message_to_composer("/statusline".into());
|
||||
app.chat_widget.handle_key_event(KeyCode::Enter.into());
|
||||
app.chat_widget.handle_key_event(KeyCode::Down.into());
|
||||
app.chat_widget.handle_key_event(KeyCode::Char(' ').into());
|
||||
app.open_statusline_picker(&owner);
|
||||
let mut inventory = commands.recv().await.unwrap();
|
||||
|
||||
assert!(app.begin_reconnect());
|
||||
inventory.response.closed().await;
|
||||
assert!(
|
||||
app.chat_widget
|
||||
.active_view_is(crate::bottom_pane::StatusLineSetupView::VIEW_ID)
|
||||
);
|
||||
app.chat_widget.handle_key_event(KeyCode::Enter.into());
|
||||
assert!(
|
||||
std::iter::from_fn(|| events.try_recv().ok()).any(|event| matches!(
|
||||
event,
|
||||
AppEvent::StatusLineSetup {
|
||||
use_theme_colors: true,
|
||||
..
|
||||
}
|
||||
))
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test(start_paused = true)]
|
||||
async fn discovery_batch_keeps_the_highlight() -> anyhow::Result<()> {
|
||||
let (mut app, owner, _commands, _events) = picker().await?;
|
||||
let calendar = advertised("work", "calendar", "ui://work/day");
|
||||
app.chat_widget.local_settings.tui.status_line_provider =
|
||||
Some(Box::new(StatusLineSelection::Mcp((&calendar.id).into())));
|
||||
let update = |server: &str, providers| DiscoveryUpdate::Server(server.into(), Ok(providers));
|
||||
app.open_statusline_picker(&owner);
|
||||
let scan = app.statusline_picker.as_ref().unwrap().id;
|
||||
let retired = advertised("work", "retired", "ui://work/retired");
|
||||
app.finish_statusline_discovery(Uuid::new_v4(), vec![update("work", vec![retired])], &owner);
|
||||
let initial = render_bottom_popup(&app.chat_widget, /*width*/ 67);
|
||||
assert!(initial.contains("Discovering MCP status line providers"));
|
||||
assert!(initial.contains("Default status line"));
|
||||
assert!(initial.contains("calendar"));
|
||||
assert!(!initial.contains("retired"));
|
||||
app.chat_widget.handle_key_event(KeyCode::Down.into());
|
||||
let named = |server, tool, title: &str| {
|
||||
let mut provider = advertised(server, tool, "ui://unused");
|
||||
provider.title = title.into();
|
||||
provider
|
||||
};
|
||||
app.finish_statusline_discovery(
|
||||
scan,
|
||||
vec![
|
||||
update("usage", vec![named("usage", "limits", "Usage")]),
|
||||
update(
|
||||
"health",
|
||||
vec![
|
||||
named("health", "quota", "Quota"),
|
||||
named("health", "alerts", "Alerts"),
|
||||
],
|
||||
),
|
||||
update("work", vec![calendar]),
|
||||
],
|
||||
&owner,
|
||||
);
|
||||
insta::assert_snapshot!(render_bottom_popup(&app.chat_widget, /*width*/ 67));
|
||||
|
||||
app.chat_widget.handle_key_event(KeyCode::Esc.into());
|
||||
app.reconnect.offline = true;
|
||||
app.open_statusline_picker(&owner);
|
||||
insta::assert_snapshot!(
|
||||
"statusline_providers_disconnected",
|
||||
render_bottom_popup(&app.chat_widget, /*width*/ 67)
|
||||
);
|
||||
let offline = app.statusline_picker.as_ref().unwrap().id;
|
||||
app.choose_statusline_provider(
|
||||
offline,
|
||||
/*id*/ None,
|
||||
crate::key_hint::plain(KeyCode::Enter),
|
||||
&owner,
|
||||
)
|
||||
.await;
|
||||
assert_eq!(
|
||||
app.local_settings.tui.status_line_provider.as_deref(),
|
||||
Some(&StatusLineSelection::Builtin(BuiltinStatusLine::Default))
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test(start_paused = true)]
|
||||
async fn discovery_only_starts_a_reader_on_explicit_selection() -> anyhow::Result<()> {
|
||||
let (mut app, owner, _requests, mut events) = picker().await?;
|
||||
let thread = ThreadId::new();
|
||||
let cwd = app.config.cwd.to_path_buf();
|
||||
app.chat_widget
|
||||
.handle_thread_session(test_thread_session(thread, cwd));
|
||||
let provider = advertised("work", "calendar", "ui://work/day");
|
||||
|
||||
for uri in ["ui://work/day", "ui://work/replacement"] {
|
||||
app.open_statusline_picker(&owner);
|
||||
let scan = app.statusline_picker.as_ref().unwrap().id;
|
||||
let found = advertised("work", "calendar", uri);
|
||||
let update = DiscoveryUpdate::Server(found.id.server.clone(), Ok(vec![found]));
|
||||
app.finish_statusline_discovery(scan, vec![update], &owner);
|
||||
assert!(
|
||||
!std::iter::from_fn(|| events.try_recv().ok())
|
||||
.any(|event| matches!(event, AppEvent::StatuslineRead(_)))
|
||||
);
|
||||
app.choose_statusline_provider(
|
||||
scan,
|
||||
Some(provider.id.clone()),
|
||||
crate::key_hint::plain(KeyCode::Enter),
|
||||
&owner,
|
||||
)
|
||||
.await;
|
||||
assert!(
|
||||
std::iter::from_fn(|| events.try_recv().ok())
|
||||
.any(|event| matches!(event, AppEvent::StatuslineRead(_)))
|
||||
);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
@@ -43,6 +43,7 @@ pub(crate) async fn make_test_app() -> Box<App> {
|
||||
let session_telemetry = test_session_telemetry(&config, model.as_str());
|
||||
|
||||
Box::new(App {
|
||||
statusline_picker: None,
|
||||
provider_writes: HashMap::new(),
|
||||
feature_write_lock: Arc::default(),
|
||||
config_notification_test_generation: 0,
|
||||
|
||||
@@ -9176,6 +9176,7 @@ async fn make_test_app() -> Box<App> {
|
||||
let session_telemetry = test_session_telemetry(&config, model.as_str());
|
||||
|
||||
Box::new(App {
|
||||
statusline_picker: None,
|
||||
provider_writes: HashMap::new(),
|
||||
feature_write_lock: Arc::default(),
|
||||
config_notification_test_generation: 0,
|
||||
@@ -9320,6 +9321,7 @@ pub(super) async fn make_test_app_with_channels() -> (
|
||||
|
||||
(
|
||||
Box::new(App {
|
||||
statusline_picker: None,
|
||||
provider_writes: HashMap::new(),
|
||||
feature_write_lock: Arc::default(),
|
||||
config_notification_test_generation: 0,
|
||||
|
||||
@@ -1903,6 +1903,17 @@ pub(crate) enum AppEvent {
|
||||
},
|
||||
/// Dismiss the status-line setup UI without changing config.
|
||||
StatusLineSetupCancelled,
|
||||
OpenStatuslinePicker(crate::key_hint::KeyBinding),
|
||||
CloseStatuslinePicker(uuid::Uuid),
|
||||
ChooseStatuslineProvider {
|
||||
scan: uuid::Uuid,
|
||||
id: Option<crate::statusline_provider::ProviderId>,
|
||||
key: crate::key_hint::KeyBinding,
|
||||
},
|
||||
StatuslinePicker {
|
||||
scan: uuid::Uuid,
|
||||
updates: Vec<crate::statusline_provider::discovery::DiscoveryUpdate>,
|
||||
},
|
||||
|
||||
/// Apply a user-confirmed terminal-title item ordering/selection.
|
||||
TerminalTitleSetup {
|
||||
|
||||
@@ -123,6 +123,7 @@ pub(crate) enum SelectionRowDisplay {
|
||||
|
||||
/// One selectable item in the generic selection list.
|
||||
pub(crate) type SelectionAction = Box<dyn Fn(&AppEventSender) + Send + Sync>;
|
||||
pub(crate) type SelectionKeyAction = Box<dyn Fn(&AppEventSender, KeyBinding) + Send + Sync>;
|
||||
|
||||
/// A second way to accept the highlighted row, sharing its dismissal behavior.
|
||||
pub(crate) struct SelectionSecondaryAction {
|
||||
@@ -185,6 +186,8 @@ pub(crate) struct SelectionItem {
|
||||
pub is_current: bool,
|
||||
pub is_disabled: bool,
|
||||
pub actions: Vec<SelectionAction>,
|
||||
/// Primary action that also needs the physical key to guard a view transition.
|
||||
pub on_accept_key: Option<SelectionKeyAction>,
|
||||
pub secondary_action: Option<SelectionSecondaryAction>,
|
||||
/// Footer hint shown while this row is selected.
|
||||
pub footer_hint: Option<Line<'static>>,
|
||||
@@ -787,8 +790,12 @@ impl ListSelectionView {
|
||||
format!("{prefix} {label}. ")
|
||||
} else {
|
||||
enabled_row_number += 1;
|
||||
let n = enabled_row_number;
|
||||
format!("{prefix} {n}. ")
|
||||
if enabled_row_number <= 9 {
|
||||
format!("{prefix} {enabled_row_number}. ")
|
||||
} else {
|
||||
let number_width = enabled_row_number.to_string().len();
|
||||
format!("{prefix} {}", " ".repeat(number_width + 2))
|
||||
}
|
||||
};
|
||||
let wrap_prefix_width = UnicodeWidthStr::width(wrap_prefix.as_str());
|
||||
let mut name_prefix_spans = Vec::new();
|
||||
@@ -970,7 +977,7 @@ impl ListSelectionView {
|
||||
}
|
||||
}
|
||||
|
||||
fn accept(&mut self, kind: SelectionActionKind) {
|
||||
fn accept(&mut self, kind: SelectionActionKind, key: KeyBinding) {
|
||||
let selected_actual_idx = self.selected_actual_idx();
|
||||
if matches!(kind, SelectionActionKind::Primary)
|
||||
&& selected_actual_idx
|
||||
@@ -990,6 +997,9 @@ impl ListSelectionView {
|
||||
for act in &item.actions {
|
||||
act(&self.app_event_tx);
|
||||
}
|
||||
if let Some(action) = &item.on_accept_key {
|
||||
action(&self.app_event_tx, key);
|
||||
}
|
||||
}
|
||||
SelectionActionKind::Secondary => {
|
||||
let Some(action) = &item.secondary_action else {
|
||||
@@ -1012,7 +1022,7 @@ impl ListSelectionView {
|
||||
}
|
||||
}
|
||||
|
||||
fn select_shortcut(&mut self, actual_idx: usize) {
|
||||
fn select_shortcut(&mut self, actual_idx: usize, key: KeyBinding) {
|
||||
let previously_selected = self.selected_actual_idx();
|
||||
self.state.selected_idx = Some(actual_idx);
|
||||
if self
|
||||
@@ -1024,7 +1034,7 @@ impl ListSelectionView {
|
||||
self.fire_selection_changed();
|
||||
}
|
||||
} else {
|
||||
self.accept(SelectionActionKind::Primary);
|
||||
self.accept(SelectionActionKind::Primary, key);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1287,6 +1297,15 @@ impl BottomPaneView for ListSelectionView {
|
||||
}
|
||||
|
||||
fn handle_key_event(&mut self, key_event: KeyEvent) {
|
||||
self.handle_key_event_with_activation_key(key_event, /*activation_key*/ None);
|
||||
}
|
||||
|
||||
fn handle_key_event_with_activation_key(
|
||||
&mut self,
|
||||
key_event: KeyEvent,
|
||||
activation_key: Option<KeyBinding>,
|
||||
) {
|
||||
let key = activation_key.unwrap_or_else(|| KeyBinding::from_event(key_event));
|
||||
// An active search reserves printable keys for the query. On-demand search leaves the
|
||||
// configured list bindings untouched until its shortcut is pressed.
|
||||
let search_field_visible = self.search_field_visible();
|
||||
@@ -1343,7 +1362,7 @@ impl BottomPaneView for ListSelectionView {
|
||||
code: KeyCode::Enter,
|
||||
modifiers: KeyModifiers::NONE,
|
||||
..
|
||||
} if self.on_demand_search_active() => self.accept(SelectionActionKind::Primary),
|
||||
} if self.on_demand_search_active() => self.accept(SelectionActionKind::Primary, key),
|
||||
KeyEvent {
|
||||
code: KeyCode::Backspace,
|
||||
..
|
||||
@@ -1379,7 +1398,7 @@ impl BottomPaneView for ListSelectionView {
|
||||
self.on_ctrl_c();
|
||||
}
|
||||
_ if allow_plain_char_actions && self.keymap.accept.is_pressed(key_event) => {
|
||||
self.accept(SelectionActionKind::Primary)
|
||||
self.accept(SelectionActionKind::Primary, key)
|
||||
}
|
||||
_ if allow_plain_char_navigation
|
||||
&& self
|
||||
@@ -1388,7 +1407,7 @@ impl BottomPaneView for ListSelectionView {
|
||||
.and_then(|item| item.secondary_action.as_ref())
|
||||
.is_some_and(|action| action.key.is_press(key_event)) =>
|
||||
{
|
||||
self.accept(SelectionActionKind::Secondary);
|
||||
self.accept(SelectionActionKind::Secondary, key);
|
||||
}
|
||||
_ if self.is_searchable
|
||||
&& !self.search_active
|
||||
@@ -1429,7 +1448,7 @@ impl BottomPaneView for ListSelectionView {
|
||||
|| item.child_label == Some(c))
|
||||
&& Self::item_is_enabled(item)
|
||||
}) {
|
||||
self.select_shortcut(idx);
|
||||
self.select_shortcut(idx, key);
|
||||
return;
|
||||
}
|
||||
if self.auto_number_shortcuts
|
||||
@@ -1438,7 +1457,7 @@ impl BottomPaneView for ListSelectionView {
|
||||
.map(|d| d as usize)
|
||||
.and_then(|number| self.actual_idx_for_enabled_number(number))
|
||||
{
|
||||
self.select_shortcut(idx);
|
||||
self.select_shortcut(idx, key);
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
@@ -2871,6 +2890,30 @@ mod tests {
|
||||
assert_eq!(view.take_last_selected_index(), Some(3));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn automatic_shortcuts_stop_at_nine() {
|
||||
let (tx, _rx) = unbounded_channel();
|
||||
let mut view = new_view(
|
||||
SelectionViewParams {
|
||||
items: (1..=10)
|
||||
.map(|n| SelectionItem {
|
||||
name: format!("Row {n}"),
|
||||
..Default::default()
|
||||
})
|
||||
.collect(),
|
||||
initial_selected_idx: Some(8),
|
||||
..Default::default()
|
||||
},
|
||||
AppEventSender::new(tx),
|
||||
);
|
||||
let rows = view.build_rows();
|
||||
assert_eq!(rows[8].name_prefix_spans[0].content, "› 9. ");
|
||||
assert_eq!(rows[9].name_prefix_spans[0].content, " ");
|
||||
view.handle_key_event(KeyEvent::from(KeyCode::Down));
|
||||
view.handle_key_event(KeyEvent::from(KeyCode::Enter));
|
||||
assert_eq!(view.take_last_selected_index(), Some(9));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn c0_ctrl_p_respects_unbound_list_move_up() {
|
||||
let (tx_raw, _rx) = unbounded_channel::<AppEvent>();
|
||||
|
||||
@@ -288,6 +288,7 @@ pub(crate) use list_selection_view::SELECTION_TOGGLE_BLOCKED_PREFIX;
|
||||
pub(crate) use list_selection_view::SELECTION_TOGGLE_UNAVAILABLE_PREFIX;
|
||||
pub(crate) use list_selection_view::SelectionAction;
|
||||
pub(crate) use list_selection_view::SelectionItem;
|
||||
pub(crate) use list_selection_view::SelectionKeyAction;
|
||||
pub(crate) use list_selection_view::SelectionSecondaryAction;
|
||||
|
||||
struct DelayedApprovalRequest {
|
||||
|
||||
@@ -72,6 +72,7 @@ use crate::bottom_pane::popup_consts::MAX_POPUP_ROWS;
|
||||
use crate::bottom_pane::scroll_state::ScrollState;
|
||||
use crate::bottom_pane::selection_popup_common::render_rows_single_line_with_col_width_mode;
|
||||
use crate::key_hint;
|
||||
use crate::key_hint::KeyBinding;
|
||||
use crate::key_hint::KeyBindingListExt;
|
||||
use crate::key_hint::is_plain_text_key_event;
|
||||
use crate::keymap::ListAction;
|
||||
@@ -135,6 +136,8 @@ pub(crate) struct MultiSelectItem {
|
||||
|
||||
/// Whether to draw a divider after this item when another visible item follows.
|
||||
pub section_break_after: bool,
|
||||
/// An action row opens its child on Enter and has no checkbox.
|
||||
pub on_activate: Option<fn(&AppEventSender, KeyBinding)>,
|
||||
}
|
||||
|
||||
impl Default for MultiSelectItem {
|
||||
@@ -146,6 +149,7 @@ impl Default for MultiSelectItem {
|
||||
enabled: false,
|
||||
orderable: true,
|
||||
section_break_after: false,
|
||||
on_activate: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -184,6 +188,7 @@ pub(crate) struct MultiSelectPicker {
|
||||
|
||||
/// Footer line showing keyboard hints.
|
||||
footer_hint: Line<'static>,
|
||||
action_footer_hint: Line<'static>,
|
||||
|
||||
/// Current search/filter query entered by the user.
|
||||
search_query: String,
|
||||
@@ -290,7 +295,17 @@ impl MultiSelectPicker {
|
||||
}
|
||||
|
||||
fn footer_lines(&self, width: u16) -> Vec<Line<'_>> {
|
||||
wrap_styled_line(&self.footer_hint, width.saturating_sub(/*rhs*/ 2))
|
||||
let action = self
|
||||
.state
|
||||
.selected_idx
|
||||
.and_then(|index| self.filtered_indices.get(index))
|
||||
.is_some_and(|index| self.items[*index].on_activate.is_some());
|
||||
let hint = if action {
|
||||
&self.action_footer_hint
|
||||
} else {
|
||||
&self.footer_hint
|
||||
};
|
||||
wrap_styled_line(hint, width.saturating_sub(/*rhs*/ 2))
|
||||
}
|
||||
|
||||
/// Calculates the height needed for the row list area.
|
||||
@@ -318,9 +333,13 @@ impl MultiSelectPicker {
|
||||
visible_to_row.push(rows.len());
|
||||
let is_selected = self.state.selected_idx == Some(visible_idx);
|
||||
let prefix = if is_selected { '›' } else { ' ' };
|
||||
let marker = if item.enabled { 'x' } else { ' ' };
|
||||
let item_name = truncate_text(&item.name, ITEM_NAME_TRUNCATE_LEN);
|
||||
let name = format!("{prefix} [{marker}] {item_name}");
|
||||
let name = if item.on_activate.is_some() {
|
||||
format!("{prefix} {}", item.name)
|
||||
} else {
|
||||
let marker = if item.enabled { 'x' } else { ' ' };
|
||||
let item_name = truncate_text(&item.name, ITEM_NAME_TRUNCATE_LEN);
|
||||
format!("{prefix} [{marker}] {item_name}")
|
||||
};
|
||||
rows.push(GenericDisplayRow {
|
||||
name,
|
||||
description: item.description.clone(),
|
||||
@@ -368,6 +387,9 @@ impl MultiSelectPicker {
|
||||
return;
|
||||
};
|
||||
|
||||
if item.on_activate.is_some() {
|
||||
return;
|
||||
}
|
||||
item.enabled = !item.enabled;
|
||||
self.update_preview_line();
|
||||
if let Some(on_change) = &self.on_change {
|
||||
@@ -379,7 +401,17 @@ impl MultiSelectPicker {
|
||||
///
|
||||
/// Collects the IDs of all enabled items and passes them to the
|
||||
/// `on_confirm` callback. Does nothing if already complete.
|
||||
fn confirm_selection(&mut self) {
|
||||
fn confirm_selection(&mut self, activation_key: KeyBinding) {
|
||||
if let Some(action) = self
|
||||
.state
|
||||
.selected_idx
|
||||
.and_then(|index| self.filtered_indices.get(index))
|
||||
.and_then(|index| self.items[*index].on_activate)
|
||||
{
|
||||
action(&self.app_event_tx, activation_key);
|
||||
return;
|
||||
}
|
||||
|
||||
if self.complete || (self.require_selection && !self.items.iter().any(|item| item.enabled))
|
||||
{
|
||||
return;
|
||||
@@ -500,6 +532,14 @@ impl BottomPaneView for MultiSelectPicker {
|
||||
}
|
||||
|
||||
fn handle_key_event(&mut self, key_event: KeyEvent) {
|
||||
self.handle_key_event_with_activation_key(key_event, /*activation_key*/ None);
|
||||
}
|
||||
|
||||
fn handle_key_event_with_activation_key(
|
||||
&mut self,
|
||||
key_event: KeyEvent,
|
||||
activation_key: Option<KeyBinding>,
|
||||
) {
|
||||
// Printable characters always feed search. Movement aliases such as
|
||||
// plain j/k only apply through non-text events or modified bindings.
|
||||
let allow_plain_char_navigation = !is_plain_text_key_event(key_event);
|
||||
@@ -540,7 +580,9 @@ impl BottomPaneView for MultiSelectPicker {
|
||||
modifiers: KeyModifiers::NONE,
|
||||
..
|
||||
} => self.toggle_selected(),
|
||||
_ if self.keymap.accept.is_pressed(key_event) => self.confirm_selection(),
|
||||
_ if self.keymap.accept.is_pressed(key_event) => self.confirm_selection(
|
||||
activation_key.unwrap_or_else(|| KeyBinding::from_event(key_event)),
|
||||
),
|
||||
_ if self.keymap.cancel.is_pressed(key_event) => self.close(),
|
||||
KeyEvent {
|
||||
code: KeyCode::Char(c),
|
||||
@@ -807,6 +849,7 @@ impl MultiSelectPickerBuilder {
|
||||
app_event_tx: self.app_event_tx,
|
||||
header: Box::new(header),
|
||||
footer_hint: Line::from(instructions),
|
||||
action_footer_hint: super::popup_consts::picker_hint_line_for_keymap(&self.keymap),
|
||||
ordering_enabled: self.ordering_enabled,
|
||||
require_selection: self.require_selection,
|
||||
keymap: self.keymap,
|
||||
|
||||
@@ -37,6 +37,7 @@ use crate::bottom_pane::multi_select_picker::MultiSelectItem;
|
||||
use crate::bottom_pane::multi_select_picker::MultiSelectPicker;
|
||||
use crate::bottom_pane::status_surface_preview::StatusSurfacePreviewData;
|
||||
use crate::bottom_pane::status_surface_preview::StatusSurfacePreviewItem;
|
||||
use crate::key_hint::KeyBinding;
|
||||
use crate::keymap::ListKeymap;
|
||||
use crate::render::renderable::Renderable;
|
||||
|
||||
@@ -293,6 +294,8 @@ pub(crate) struct StatusLineSetupView {
|
||||
}
|
||||
|
||||
impl StatusLineSetupView {
|
||||
pub(crate) const VIEW_ID: &'static str = "status-line-setup";
|
||||
|
||||
/// Creates a new status line setup view.
|
||||
///
|
||||
/// # Arguments
|
||||
@@ -308,19 +311,31 @@ impl StatusLineSetupView {
|
||||
pub(crate) fn new(
|
||||
status_line_items: Option<&[String]>,
|
||||
use_theme_colors: bool,
|
||||
provider_actions: bool,
|
||||
preview_data: StatusSurfacePreviewData,
|
||||
app_event_tx: AppEventSender,
|
||||
list_keymap: ListKeymap,
|
||||
) -> Self {
|
||||
let mut used_ids = HashSet::new();
|
||||
let mut items = vec![MultiSelectItem {
|
||||
let mut items = Vec::new();
|
||||
if provider_actions {
|
||||
items.push(MultiSelectItem {
|
||||
name: "Choose a statusline plugin".into(),
|
||||
orderable: false,
|
||||
section_break_after: true,
|
||||
on_activate: Some(|tx, key| tx.send(AppEvent::OpenStatuslinePicker(key))),
|
||||
..Default::default()
|
||||
});
|
||||
}
|
||||
items.push(MultiSelectItem {
|
||||
id: STATUS_LINE_USE_THEME_COLORS_ITEM_ID.to_string(),
|
||||
name: "Use theme colors".to_string(),
|
||||
description: Some("Apply colors from the active /theme".to_string()),
|
||||
enabled: use_theme_colors,
|
||||
orderable: false,
|
||||
section_break_after: true,
|
||||
}];
|
||||
on_activate: None,
|
||||
});
|
||||
|
||||
if let Some(selected_items) = status_line_items.as_ref() {
|
||||
for id in *selected_items {
|
||||
@@ -417,11 +432,16 @@ impl StatusLineSetupView {
|
||||
enabled,
|
||||
orderable: true,
|
||||
section_break_after: false,
|
||||
on_activate: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl BottomPaneView for StatusLineSetupView {
|
||||
fn view_id(&self) -> Option<&'static str> {
|
||||
Some(Self::VIEW_ID)
|
||||
}
|
||||
|
||||
fn keymap_contexts(&self) -> crate::keymap::KeymapContextSet {
|
||||
crate::keymap::KeymapContextSet::new(crate::keymap::KeymapContext::List)
|
||||
}
|
||||
@@ -434,6 +454,15 @@ impl BottomPaneView for StatusLineSetupView {
|
||||
self.picker.handle_key_event(key_event);
|
||||
}
|
||||
|
||||
fn handle_key_event_with_activation_key(
|
||||
&mut self,
|
||||
key_event: crossterm::event::KeyEvent,
|
||||
activation_key: Option<KeyBinding>,
|
||||
) {
|
||||
self.picker
|
||||
.handle_key_event_with_activation_key(key_event, activation_key);
|
||||
}
|
||||
|
||||
fn is_complete(&self) -> bool {
|
||||
self.picker.complete
|
||||
}
|
||||
@@ -600,6 +629,7 @@ mod tests {
|
||||
enabled: true,
|
||||
orderable: true,
|
||||
section_break_after: false,
|
||||
on_activate: None,
|
||||
},
|
||||
MultiSelectItem {
|
||||
id: StatusLineItem::CurrentDir.to_string(),
|
||||
@@ -608,6 +638,7 @@ mod tests {
|
||||
enabled: true,
|
||||
orderable: true,
|
||||
section_break_after: false,
|
||||
on_activate: None,
|
||||
},
|
||||
];
|
||||
|
||||
@@ -638,6 +669,7 @@ mod tests {
|
||||
enabled: true,
|
||||
orderable: true,
|
||||
section_break_after: false,
|
||||
on_activate: None,
|
||||
},
|
||||
MultiSelectItem {
|
||||
id: StatusLineItem::GitBranch.to_string(),
|
||||
@@ -646,6 +678,7 @@ mod tests {
|
||||
enabled: true,
|
||||
orderable: true,
|
||||
section_break_after: false,
|
||||
on_activate: None,
|
||||
},
|
||||
];
|
||||
|
||||
@@ -682,6 +715,7 @@ mod tests {
|
||||
enabled: true,
|
||||
orderable: true,
|
||||
section_break_after: false,
|
||||
on_activate: None,
|
||||
},
|
||||
MultiSelectItem {
|
||||
id: StatusLineItem::ThreadTitle.to_string(),
|
||||
@@ -690,6 +724,7 @@ mod tests {
|
||||
enabled: true,
|
||||
orderable: true,
|
||||
section_break_after: false,
|
||||
on_activate: None,
|
||||
},
|
||||
];
|
||||
|
||||
@@ -719,6 +754,7 @@ mod tests {
|
||||
let mut view = StatusLineSetupView::new(
|
||||
Some(&[StatusLineItem::PullRequestNumber.to_string()]),
|
||||
use_theme_colors,
|
||||
/*provider_actions*/ false,
|
||||
preview,
|
||||
AppEventSender::new(tx),
|
||||
crate::keymap::RuntimeKeymap::defaults().list,
|
||||
@@ -743,6 +779,7 @@ mod tests {
|
||||
StatusLineItem::GitBranch.to_string(),
|
||||
]),
|
||||
/*use_theme_colors*/ true,
|
||||
/*provider_actions*/ false,
|
||||
StatusSurfacePreviewData::from_iter([
|
||||
(
|
||||
StatusLineItem::ModelName.preview_item(),
|
||||
@@ -777,6 +814,7 @@ mod tests {
|
||||
StatusLineItem::EstimatedThreadCost.to_string(),
|
||||
]),
|
||||
/*use_theme_colors*/ true,
|
||||
/*provider_actions*/ false,
|
||||
StatusSurfacePreviewData::from_iter([
|
||||
(
|
||||
StatusLineItem::ThreadCredits.preview_item(),
|
||||
@@ -803,6 +841,7 @@ mod tests {
|
||||
StatusLineItem::CurrentDir.to_string(),
|
||||
]),
|
||||
/*use_theme_colors*/ true,
|
||||
/*provider_actions*/ false,
|
||||
StatusSurfacePreviewData::from_iter([
|
||||
(
|
||||
StatusLineItem::Hostname.preview_item(),
|
||||
|
||||
@@ -362,6 +362,7 @@ impl TerminalTitleSetupView {
|
||||
enabled,
|
||||
orderable: true,
|
||||
section_break_after: false,
|
||||
on_activate: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+8
-8
@@ -7,14 +7,14 @@ expression: status_line_popup_snapshot(&mut chat)
|
||||
|
||||
Type to search
|
||||
|
||||
› [x] Use theme colors Apply colors from the active /theme
|
||||
› Choose a statusline plugin
|
||||
───────────────────────
|
||||
[x] project-name Project name (omitted when unavailable)
|
||||
[x] git-branch Current Git branch (omitted when unavailable)
|
||||
[x] thread-title Current thread title, or thread identifier when unnamed
|
||||
[ ] model Current model name
|
||||
[ ] model-with-reasoning Current model name with reasoning level
|
||||
[ ] reasoning Current reasoning level
|
||||
[x] Use theme colors Apply colors from the active /theme
|
||||
───────────────────────
|
||||
[x] project-name Project name (omitted when unavailable)
|
||||
[x] git-branch Current Git branch (omitted when unavailable)
|
||||
[x] thread-title Current thread title, or thread identifier when unnamed
|
||||
[ ] model Current model name
|
||||
↓
|
||||
preview-live-root · feature/live-preview-branch · Live preview thread
|
||||
space toggle · ←/→ reorder · enter save · esc cancel
|
||||
enter select · esc back
|
||||
|
||||
@@ -332,6 +332,9 @@ impl ChatWidget {
|
||||
let view = StatusLineSetupView::new(
|
||||
Some(configured_status_line_items.as_slice()),
|
||||
self.local_settings.tui.status_line_use_colors,
|
||||
self.config
|
||||
.features
|
||||
.enabled(codex_features::Feature::TuiExtensionsStatusLine),
|
||||
self.status_surface_preview_data(),
|
||||
self.app_event_tx.clone(),
|
||||
self.bottom_pane.list_keymap(),
|
||||
|
||||
@@ -85,6 +85,10 @@ impl ChatWidget {
|
||||
{
|
||||
return None;
|
||||
}
|
||||
self.configured_statusline_provider()
|
||||
}
|
||||
|
||||
pub(crate) fn configured_statusline_provider(&self) -> Option<&StatusLineProviderId> {
|
||||
match self.local_settings.tui.status_line_provider.as_deref()? {
|
||||
StatusLineSelection::Builtin(_) => None,
|
||||
StatusLineSelection::Mcp(id) => Some(id),
|
||||
|
||||
@@ -80,6 +80,15 @@ impl From<&codex_config::types::StatusLineProviderId> for ProviderId {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&ProviderId> for codex_config::types::StatusLineProviderId {
|
||||
fn from(id: &ProviderId) -> Self {
|
||||
Self {
|
||||
server: id.server.0.clone(),
|
||||
tool: id.tool.0.clone(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) enum ProviderSelection<'a> {
|
||||
Saved(&'a ProviderId),
|
||||
/// A provider advertised during the current picker refresh.
|
||||
|
||||
@@ -21,18 +21,16 @@ const INVENTORY_HEAD_START: Duration = Duration::from_secs(2);
|
||||
const MAX_CONCURRENT_PROBES: usize = 4;
|
||||
|
||||
#[derive(Debug)]
|
||||
#[cfg_attr(not(test), expect(dead_code, reason = "staged picker"))]
|
||||
pub(crate) enum DiscoveryUpdate {
|
||||
Server(
|
||||
McpServerName,
|
||||
Result<Vec<StatuslineProvider>, ProviderLookupError>,
|
||||
),
|
||||
#[cfg_attr(not(test), expect(dead_code, reason = "picker diagnostics are staged"))]
|
||||
InventoryFailed(ProviderLookupError),
|
||||
}
|
||||
|
||||
/// Pass the saved and previously observed server names. Dropping the stream stops the TUI's
|
||||
/// outstanding waits. The host may finish requests it already received.
|
||||
#[cfg_attr(not(test), expect(dead_code, reason = "staged picker"))]
|
||||
/// Probe known servers by name if inventory stalls. Dropping the stream stops the TUI's waits.
|
||||
pub(crate) fn refresh_statusline_providers(
|
||||
client: AppServerRequestHandle,
|
||||
known: Vec<McpServerName>,
|
||||
|
||||
@@ -20,7 +20,7 @@ pub(super) fn test_client() -> (AppServerRequestHandle, Requests) {
|
||||
(AppServerClient::Cloud(cloud).request_handle(), commands)
|
||||
}
|
||||
|
||||
pub(super) async fn reply(commands: &mut Requests, method: &str, params: Value, result: Value) {
|
||||
pub(crate) async fn reply(commands: &mut Requests, method: &str, params: Value, result: Value) {
|
||||
let command = commands.recv().await.unwrap();
|
||||
let CloudOperation::Request(request) = command.operation else {
|
||||
panic!("expected {method}");
|
||||
|
||||
@@ -5,6 +5,7 @@ mod render;
|
||||
mod theme;
|
||||
|
||||
pub(crate) use render::PreparedUiTree;
|
||||
pub(crate) use render::sanitize_leaf;
|
||||
use theme::Color;
|
||||
use theme::TextWeight;
|
||||
|
||||
|
||||
@@ -274,7 +274,7 @@ fn layout_band<'a>(
|
||||
ends.len()
|
||||
}
|
||||
|
||||
fn sanitize_leaf(mut raw: String) -> String {
|
||||
pub(crate) fn sanitize_leaf(mut raw: String) -> String {
|
||||
// Directly constructed trees can bypass the wire decoder's text limit.
|
||||
if raw.len() > MAX_TEXT_BYTES {
|
||||
raw.truncate(raw.floor_char_boundary(MAX_TEXT_BYTES));
|
||||
|
||||
@@ -132,11 +132,27 @@ async fn statusline_reads_the_selected_stdio_resource_on_the_displayed_thread()
|
||||
terminal.write_input(b"/raw off\r")?;
|
||||
terminal.wait_for_screen("Raw output mode off")?;
|
||||
terminal.wait_for_screen(&format!("Provider thread {thread} (standard)"))?;
|
||||
let config = fs::read_to_string(&local_config)?;
|
||||
fs::write(
|
||||
&local_config,
|
||||
config.replace("tool='sandbox_meta'", "tool='replacement'"),
|
||||
)?;
|
||||
terminal.write_input(b"/statusline\r")?;
|
||||
terminal.wait_for_screen("Choose a statusline plugin")?;
|
||||
// This PTY reports presses only. Navigate back to the action before pressing Enter again.
|
||||
terminal.write_input(b"\x1b[B\x1b[A")?;
|
||||
for row in ["Default status line", "fixture / sandbox_meta"] {
|
||||
terminal.write_input(b"\r")?;
|
||||
terminal.wait_for_screen(row)?;
|
||||
terminal.write_input(b"2")?;
|
||||
terminal.wait_for_screen("Configure Status Line")?;
|
||||
}
|
||||
terminal.write_input(b"\x1b")?;
|
||||
terminal.wait_for_screen(&format!("Provider thread {thread} (standard)"))?;
|
||||
|
||||
let mut config: toml::Value = toml::from_str(&fs::read_to_string(&local_config)?)?;
|
||||
assert_eq!(
|
||||
config["tui"]["status_line_provider"]["tool"].as_str(),
|
||||
Some("sandbox_meta")
|
||||
);
|
||||
config["tui"]["status_line_provider"]["tool"] =
|
||||
toml::Value::String("replacement".into());
|
||||
fs::write(&local_config, toml::to_string(&config)?)?;
|
||||
terminal.write_input(b"/new\r")?;
|
||||
terminal.wait_for_screen("Error loading statusline contents from replacement")?;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user