Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions codex-rs/tui/src/app/config_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,13 @@ impl App {
} else {
None
};
self.chat_widget
.refresh_config_panel(notice.map(str::to_string));
let notice = notice.map(str::to_string);
if effective {
self.chat_widget
.refresh_config_panel_after_effective_save(notice, preference);
} else {
self.chat_widget.refresh_config_panel(notice);
}
tui.frame_requester().schedule_frame();
}
}
Expand Down
136 changes: 122 additions & 14 deletions codex-rs/tui/src/app/config_panel_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,26 @@ use crate::config_panel::ConfigEditorHandoff;
use crate::local_settings::LocalSettings;
use codex_protocol::config_types::TrustLevel;
use pretty_assertions::assert_eq;
use tokio::sync::mpsc::UnboundedReceiver;

fn open_effects_editor(app: &mut App) {
let handoff = ConfigEditorHandoff::new(
ConfigEditor::Effects,
crate::key_hint::plain(KeyCode::Enter),
);
handoff.mark_activation_inactive();
app.chat_widget.open_config_editor(
handoff,
crate::config_panel::ResumeCurrentAvailability::Available,
);
}

fn next_config_preference(rx: &mut UnboundedReceiver<AppEvent>) -> Result<ConfigPreference> {
let AppEvent::SaveConfigPreference(preference) = rx.try_recv()? else {
panic!("expected config preference save");
};
Ok(preference)
}

#[tokio::test]
async fn config_toggle_save_uses_host_config_and_applies_live_while_offline() -> Result<()> {
Expand Down Expand Up @@ -124,32 +144,120 @@ async fn config_toggle_save_uses_host_config_and_applies_live_while_offline() ->
}

#[tokio::test]
async fn effects_editor_refreshes_after_animation_save() -> Result<()> {
async fn effects_editor_refresh_preserves_pending_toggles() -> Result<()> {
let (mut app, mut rx, _ops) = crate::app::tests::make_test_app_with_channels().await;
let mut tui = crate::tui::test_support::make_test_tui()?;
app.local_settings.tui.animations = false;
app.chat_widget.local_settings.tui.animations = false;
app.chat_widget.config_panel_tui.animations = false;
let handoff = ConfigEditorHandoff::new(
ConfigEditor::Effects,
crate::key_hint::plain(KeyCode::Enter),
);
handoff.mark_activation_inactive();
app.chat_widget.open_config_editor(
handoff,
crate::config_panel::ResumeCurrentAvailability::Available,
);
open_effects_editor(&mut app);

app.chat_widget.handle_key_event(KeyCode::Enter.into());
let AppEvent::SaveConfigPreference(preference) = rx.try_recv()? else {
panic!("expected animation save");
};
app.save_config_preference(&mut tui, preference).await;
app.chat_widget.handle_key_event(KeyCode::Enter.into());
let first_preference = next_config_preference(&mut rx)?;
app.save_config_preference(&mut tui, first_preference).await;

insta::assert_snapshot!(
"effects_picker_after_animation_save",
render_bottom_popup(&app.chat_widget, /*width*/ 80)
);

app.chat_widget.handle_key_event(KeyCode::Enter.into());
let second_preference = next_config_preference(&mut rx)?;
app.save_config_preference(&mut tui, second_preference)
.await;
let third_preference = next_config_preference(&mut rx)?;
assert_eq!(
third_preference,
ConfigPreference::Toggle {
setting: ConfigToggle::Animations,
enabled: true,
}
);
app.save_config_preference(&mut tui, third_preference).await;
assert!(app.chat_widget.config_panel_tui.animations);
Ok(())
}

#[tokio::test]
async fn effects_editor_preserves_pending_stars_while_disabled() -> Result<()> {
let (mut app, mut rx, _ops) = crate::app::tests::make_test_app_with_channels().await;
let mut tui = crate::tui::test_support::make_test_tui()?;
app.local_settings.tui.animations = true;
app.local_settings.tui.effects.starfield = true;
app.chat_widget.local_settings.tui.animations = true;
app.chat_widget.local_settings.tui.effects.starfield = true;
app.chat_widget.config_panel_tui.animations = true;
app.chat_widget.config_panel_tui.effects.starfield = true;
open_effects_editor(&mut app);

for shortcut in ['1', '2', '2'] {
app.chat_widget
.handle_key_event(KeyCode::Char(shortcut).into());
}
let animations_off = next_config_preference(&mut rx)?;
assert_eq!(
animations_off,
ConfigPreference::Toggle {
setting: ConfigToggle::Animations,
enabled: false,
}
);
app.save_config_preference(&mut tui, animations_off).await;

app.chat_widget.handle_key_event(KeyCode::Char('1').into());
for _ in 0..3 {
let preference = next_config_preference(&mut rx)?;
app.save_config_preference(&mut tui, preference).await;
}

assert_eq!(
(
app.chat_widget.config_panel_tui.animations,
app.chat_widget.config_panel_tui.effects.starfield,
),
(true, true),
);
app.chat_widget.handle_key_event(KeyCode::Char('2').into());
assert_eq!(
next_config_preference(&mut rx)?,
ConfigPreference::Toggle {
setting: ConfigToggle::ComposerStars,
enabled: false,
}
);
Ok(())
}

#[tokio::test]
async fn effects_editor_reset_clears_pending_toggle_state() -> Result<()> {
let (mut app, mut rx, _ops) = crate::app::tests::make_test_app_with_channels().await;
let mut tui = crate::tui::test_support::make_test_tui()?;
app.local_settings.tui.animations = true;
app.local_settings.tui.effects.starfield = true;
app.chat_widget.local_settings.tui.animations = true;
app.chat_widget.local_settings.tui.effects.starfield = true;
app.chat_widget.config_panel_tui.animations = true;
app.chat_widget.config_panel_tui.effects.starfield = true;
open_effects_editor(&mut app);

app.chat_widget.handle_key_event(KeyCode::Char('1').into());
app.chat_widget.handle_key_event(KeyCode::Char('2').into());
let _animations_off = next_config_preference(&mut rx)?;
let stars_off = next_config_preference(&mut rx)?;

app.chat_widget.refresh_config_panel(/*notice*/ None);
app.save_config_preference(&mut tui, stars_off).await;

assert!(!app.chat_widget.config_panel_tui.effects.starfield);
app.chat_widget.handle_key_event(KeyCode::Char('2').into());
assert_eq!(
next_config_preference(&mut rx)?,
ConfigPreference::Toggle {
setting: ConfigToggle::ComposerStars,
enabled: true,
}
);
Ok(())
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ expression: "render_bottom_popup(&app.chat_widget, 80)"
Configure visual effects


› 1. [x] Animations Animate the welcome screen, working indicator, and
transitions
2. [x] Composer stars Show stars briefly for new Astra tasks
› 1. [ ] Animations Animate the welcome screen, working
indicator, and transitions
[-] Composer stars (disabled) Turn on Animations to show Astra task stars

enter toggle · esc back
8 changes: 8 additions & 0 deletions codex-rs/tui/src/bottom_pane/bottom_pane_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,14 @@ pub(crate) trait BottomPaneView: Renderable {
None
}

/// Current toggle values for list items that preserve local choices across refreshes.
fn selection_toggle_states(&self) -> Vec<Option<super::SelectionToggleState>> {
Vec::new()
}

/// Mark one previously emitted toggle action as complete.
fn complete_selection_toggle(&mut self, _index: usize) {}

/// Current query for searchable list views that preserve filtering across refreshes.
fn search_query(&self) -> Option<&str> {
None
Expand Down
99 changes: 93 additions & 6 deletions codex-rs/tui/src/bottom_pane/list_selection_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,13 @@ pub(crate) struct SelectionToggle {
pub action: Box<SelectionToggleAction>,
}

/// A displayed toggle value with the number of its save actions still in flight.
#[derive(Clone, Copy)]
pub(crate) struct SelectionToggleState {
pub is_on: bool,
pub pending_actions: usize,
}

/// Callback invoked whenever the highlighted item changes (arrow keys, search
/// filter, number-key jump). Receives the *actual* index into the unfiltered
/// `items` list and the event sender. Used by the theme picker for live preview.
Expand All @@ -165,6 +172,10 @@ pub(crate) struct SelectionItem {
pub child_label: Option<char>,
pub name_prefix_spans: Vec<Span<'static>>,
pub toggle: Option<SelectionToggle>,
/// Render `[x]` and treat the primary accept key as a toggle action.
pub checkbox_toggle: bool,
/// Toggle actions sent from this row that have not finished saving yet.
pub pending_toggle_actions: usize,
pub toggle_placeholder: Option<&'static str>,
pub display_shortcut: Option<ShortcutHint>,
/// Required row metadata retained when the secondary description hides.
Expand Down Expand Up @@ -378,23 +389,29 @@ pub(crate) struct ListSelectionView {
}

const SELECTION_TOGGLE_ON_PREFIX: &str = "[*] ";
const SELECTION_CHECKBOX_ON_PREFIX: &str = "[x] ";
const SELECTION_TOGGLE_OFF_PREFIX: &str = "[ ] ";
pub(crate) const SELECTION_TOGGLE_UNAVAILABLE_PREFIX: &str = "[-] ";
pub(crate) const SELECTION_TOGGLE_BLOCKED_PREFIX: &str = "[!] ";

fn selection_toggle_prefix(toggle: &SelectionToggle) -> &'static str {
fn selection_toggle_prefix(item: &SelectionItem, toggle: &SelectionToggle) -> &'static str {
if toggle.is_on {
SELECTION_TOGGLE_ON_PREFIX
if item.checkbox_toggle {
SELECTION_CHECKBOX_ON_PREFIX
} else {
SELECTION_TOGGLE_ON_PREFIX
}
} else {
SELECTION_TOGGLE_OFF_PREFIX
}
}

fn selection_item_toggle_prefix(item: &SelectionItem) -> Option<&'static str> {
item.toggle
.as_ref()
.map(selection_toggle_prefix)
.or(item.toggle_placeholder)
item.toggle_placeholder.or_else(|| {
item.toggle
.as_ref()
.map(|toggle| selection_toggle_prefix(item, toggle))
})
}

impl ListSelectionView {
Expand Down Expand Up @@ -430,6 +447,7 @@ impl ListSelectionView {
};

toggle.is_on = !toggle.is_on;
item.pending_toggle_actions = item.pending_toggle_actions.saturating_add(/*rhs*/ 1);
(toggle.action)(toggle.is_on, &app_event_tx);
}
}
Expand Down Expand Up @@ -941,6 +959,15 @@ impl ListSelectionView {

fn accept(&mut self, kind: SelectionActionKind) {
let selected_actual_idx = self.selected_actual_idx();
if matches!(kind, SelectionActionKind::Primary)
&& selected_actual_idx
.and_then(|idx| self.active_items().get(idx))
.is_some_and(|item| item.checkbox_toggle)
{
self.toggle_selected();
self.last_selected_actual_idx = selected_actual_idx;
return;
}
if let Some(item) = selected_actual_idx.and_then(|idx| self.active_items().get(idx)) {
if item.is_disabled || item.disabled_reason.is_some() {
return;
Expand Down Expand Up @@ -1317,6 +1344,7 @@ impl BottomPaneView for ListSelectionView {
modifiers: KeyModifiers::NONE,
..
} if self.selected_item_has_toggle()
&& self.keymap.action_for(key_event).is_none()
&& (!search_field_visible
|| matches!(self.search_mode, SearchMode::Immediate)
&& self.search_query.is_empty()) =>
Expand Down Expand Up @@ -1438,6 +1466,28 @@ impl BottomPaneView for ListSelectionView {
self.selected_actual_idx()
}

fn selection_toggle_states(&self) -> Vec<Option<SelectionToggleState>> {
self.active_items()
.iter()
.map(|item| {
item.toggle
.as_ref()
.filter(|_| item.pending_toggle_actions > 0)
.map(|toggle| SelectionToggleState {
is_on: toggle.is_on,
pending_actions: item.pending_toggle_actions,
})
})
.collect()
}

fn complete_selection_toggle(&mut self, index: usize) {
if let Some(item) = self.active_items_mut().get_mut(index) {
item.pending_toggle_actions =
item.pending_toggle_actions.saturating_sub(/*rhs*/ 1);
}
}

fn search_query(&self) -> Option<&str> {
self.is_searchable.then_some(self.search_query.as_str())
}
Expand Down Expand Up @@ -2530,6 +2580,43 @@ mod tests {
);
}

#[test]
fn configured_cancel_binding_takes_precedence_over_space_toggle() {
let (tx_raw, mut rx) = unbounded_channel::<AppEvent>();
let tx = AppEventSender::new(tx_raw);
let mut keymap = crate::keymap::RuntimeKeymap::defaults().list;
keymap.cancel = vec![crate::key_hint::plain(KeyCode::Char(' '))];
let mut view = ListSelectionView::new(
SelectionViewParams {
items: vec![SelectionItem {
name: "Animations".to_string(),
toggle: Some(SelectionToggle {
is_on: true,
action: Box::new(|_enabled, tx: &_| {
tx.send(AppEvent::OpenApprovalsPopup);
}),
}),
checkbox_toggle: true,
..Default::default()
}],
..Default::default()
},
tx,
keymap,
);

view.handle_key_event(KeyEvent::new(KeyCode::Char(' '), KeyModifiers::NONE));

assert_eq!(view.completion, Some(ViewCompletion::Cancelled));
assert!(
view.active_items()[0]
.toggle
.as_ref()
.is_some_and(|toggle| toggle.is_on)
);
assert!(rx.try_recv().is_err());
}

#[test]
fn single_line_row_display_truncates_instead_of_wrapping() {
let (tx_raw, _rx) = unbounded_channel::<AppEvent>();
Expand Down
Loading
Loading