Skip to content

armgit / codex

Public Imported from GitHub
0

Lightweight coding agent that runs in your terminal

Rust

fix: dont quit on 'q' in onboarding ApiKeyEntry state (#7869)

sayan-oai703bf12b36ce
diff --git a/codex-rs/tui/src/onboarding/onboarding_screen.rs b/codex-rs/tui/src/onboarding/onboarding_screen.rs
index 47c7811a3b..14999b2229 100644
--- a/codex-rs/tui/src/onboarding/onboarding_screen.rs
+++ b/codex-rs/tui/src/onboarding/onboarding_screen.rs
@@ -195,11 +195,24 @@ impl OnboardingScreen {
pub fn should_exit(&self) -> bool {
self.should_exit
}
+
+ fn is_api_key_entry_active(&self) -> bool {
+ self.steps.iter().any(|step| {
+ if let Step::Auth(widget) = step {
+ return widget
+ .sign_in_state
+ .read()
+ .is_ok_and(|g| matches!(&*g, SignInState::ApiKeyEntry(_)));
+ }
+ false
+ })
+ }
}
impl KeyboardHandler for OnboardingScreen {
fn handle_key_event(&mut self, key_event: KeyEvent) {
- match key_event {
+ let is_api_key_entry_active = self.is_api_key_entry_active();
+ let should_quit = match key_event {
KeyEvent {
code: KeyCode::Char('d'),
modifiers: crossterm::event::KeyModifiers::CONTROL,
@@ -211,32 +224,33 @@ impl KeyboardHandler for OnboardingScreen {
modifiers: crossterm::event::KeyModifiers::CONTROL,
kind: KeyEventKind::Press,
..
- }
- | KeyEvent {
+ } => true,
+ KeyEvent {
code: KeyCode::Char('q'),
kind: KeyEventKind::Press,
..
- } => {
- if self.is_auth_in_progress() {
- // If the user cancels the auth menu, exit the app rather than
- // leave the user at a prompt in an unauthed state.
- self.should_exit = true;
- }
- self.is_done = true;
+ } => !is_api_key_entry_active,
+ _ => false,
+ };
+ if should_quit {
+ if self.is_auth_in_progress() {
+ // If the user cancels the auth menu, exit the app rather than
+ // leave the user at a prompt in an unauthed state.
+ self.should_exit = true;
}
- _ => {
- if let Some(Step::Welcome(widget)) = self
- .steps
- .iter_mut()
- .find(|step| matches!(step, Step::Welcome(_)))
- {
- widget.handle_key_event(key_event);
- }
- if let Some(active_step) = self.current_steps_mut().into_iter().last() {
- active_step.handle_key_event(key_event);
- }
+ self.is_done = true;
+ } else {
+ if let Some(Step::Welcome(widget)) = self
+ .steps
+ .iter_mut()
+ .find(|step| matches!(step, Step::Welcome(_)))
+ {
+ widget.handle_key_event(key_event);
}
- };
+ if let Some(active_step) = self.current_steps_mut().into_iter().last() {
+ active_step.handle_key_event(key_event);
+ }
+ }
self.request_frame.schedule_frame();
}