mirror of
https://github.com/openai/codex.git
synced 2026-11-27 23:31:09 +00:00
Make the voice mute shortcut configurable in the TUI (#43690)
## Why Voice mute used a hard-coded `Ctrl+X` shortcut and footer hint, so keymap customization could not change or disable it. ## What changed - Wire `tui.keymap.chat.toggle_voice_mute` into runtime keybindings and the keymap picker, supporting custom keys, chords, and unbinding. - Keep `Ctrl+X` as the default, but let existing configured shortcuts and overlapping chord prefixes take precedence. Validate explicitly configured mute bindings for conflicts. - Activate voice chords only when the microphone shortcut is available, excluding pagers and overlays. - Refresh the voice footer when bindings change, showing the configured shortcut or `/voice mute` when unbound. ## Testing Add regression tests for binding resolution, conflicts, voice chord context, and live keymap updates. Add footer snapshots covering custom keys, chords, and unbinding in muted and listening states at wide and narrow widths. GitOrigin-RevId: ec9385f3956aa268bba34dcf2cc2b0c92a31bfec
This commit is contained in:
1 parent
98c7c0415b
commit
45305dd229
20 files changed
+319
-45
No files matched your search
@@ -178,6 +178,7 @@ impl ChatWidget {
|
||||
self.bottom_pane
|
||||
.set_queued_message_edit_binding(self.queued_message_edit_hint_binding);
|
||||
self.bottom_pane.set_keymap_bindings(runtime_keymap);
|
||||
self.update_realtime_footer();
|
||||
self.request_redraw();
|
||||
}
|
||||
}
|
||||
@@ -13,7 +13,7 @@ use crate::app_event::AppEvent;
|
||||
use crate::bottom_pane::VoiceStripPhase;
|
||||
use crate::bottom_pane::VoiceStripState;
|
||||
use crate::history_cell;
|
||||
use crate::key_hint;
|
||||
use crate::key_hint::KeyBindingListExt;
|
||||
use crate::motion::MotionMode;
|
||||
use codex_app_server_protocol::ThreadItem;
|
||||
use codex_app_server_protocol::UserInput;
|
||||
@@ -23,7 +23,6 @@ use codex_protocol::models::MessagePhase;
|
||||
use codex_realtime_webrtc::RealtimeWebrtcSession;
|
||||
use codex_realtime_webrtc::RealtimeWebrtcSessionHandle;
|
||||
use codex_realtime_webrtc::StartedRealtimeWebrtcSession;
|
||||
use crossterm::event::KeyCode;
|
||||
use crossterm::event::KeyEvent;
|
||||
use crossterm::event::KeyEventKind;
|
||||
use futures::future::AbortHandle;
|
||||
@@ -57,7 +56,6 @@ const MAX_REALTIME_AUDIO_METER_FRAMES: usize = 12;
|
||||
const MICROPHONE_METER_INTERVAL: Duration = Duration::from_millis(100);
|
||||
const SPEAKER_ACTIVITY_HOLD: Duration = Duration::from_millis(500);
|
||||
const INTERRUPTION_ACKNOWLEDGMENT: Duration = Duration::from_millis(400);
|
||||
const REALTIME_MICROPHONE_SHORTCUT: key_hint::KeyBinding = key_hint::ctrl(KeyCode::Char('x'));
|
||||
static NEXT_REALTIME_ATTEMPT_ID: AtomicU64 = AtomicU64::new(1);
|
||||
static NEXT_REALTIME_SPEECH_DELIVERY_ID: AtomicU64 = AtomicU64::new(1);
|
||||
|
||||
|
||||
@@ -30,22 +30,22 @@ impl ChatWidget {
|
||||
self.refresh_terminal_title();
|
||||
}
|
||||
|
||||
pub(in crate::chatwidget) fn handle_realtime_microphone_shortcut(
|
||||
&mut self,
|
||||
key_event: KeyEvent,
|
||||
) -> bool {
|
||||
pub(crate) fn realtime_microphone_shortcut_available(&self) -> bool {
|
||||
(self.realtime_conversation.phase == RealtimeConversationPhase::Active
|
||||
|| (self.realtime_conversation.phase == RealtimeConversationPhase::Starting
|
||||
&& self.realtime_conversation.handle.is_some()))
|
||||
&& self.realtime_conversation.thread_id.is_some()
|
||||
&& self.realtime_conversation.thread_id == self.thread_id()
|
||||
&& self.bottom_pane.no_modal_or_popup_active()
|
||||
}
|
||||
|
||||
pub(crate) fn handle_realtime_microphone_shortcut(&mut self, key_event: KeyEvent) -> bool {
|
||||
if key_event.kind != KeyEventKind::Press
|
||||
|| !REALTIME_MICROPHONE_SHORTCUT.is_press(key_event)
|
||||
|| !(self.realtime_conversation.phase == RealtimeConversationPhase::Active
|
||||
|| (self.realtime_conversation.phase == RealtimeConversationPhase::Starting
|
||||
&& self.realtime_conversation.handle.is_some()))
|
||||
|| self.realtime_conversation.thread_id.is_none()
|
||||
|| self.realtime_conversation.thread_id != self.thread_id()
|
||||
|| !self.bottom_pane.no_modal_or_popup_active()
|
||||
|| !self.chat_keymap.toggle_voice_mute.is_pressed(key_event)
|
||||
|| !self.realtime_microphone_shortcut_available()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
self.toggle_realtime_microphone();
|
||||
true
|
||||
}
|
||||
@@ -185,7 +185,7 @@ impl ChatWidget {
|
||||
.schedule_frame_in(MICROPHONE_METER_INTERVAL);
|
||||
}
|
||||
|
||||
pub(super) fn update_realtime_footer(&mut self) {
|
||||
pub(in crate::chatwidget) fn update_realtime_footer(&mut self) {
|
||||
let microphone_live = self.realtime_microphone_is_listening();
|
||||
let active = self.realtime_conversation.phase == RealtimeConversationPhase::Active;
|
||||
if !matches!(
|
||||
@@ -218,6 +218,7 @@ impl ChatWidget {
|
||||
"listening"
|
||||
};
|
||||
self.bottom_pane.set_voice_strip(Some(VoiceStripState {
|
||||
mute_hint: self.chat_keymap.voice_mute_hint(),
|
||||
phase: if active {
|
||||
VoiceStripPhase::Active
|
||||
} else {
|
||||
|
||||
@@ -62,6 +62,32 @@ async fn voice_mute_shortcut_accepts_raw_terminal_control_bytes() {
|
||||
assert!(ops.try_recv().is_err());
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn voice_mute_keymap_updates_the_active_handler_and_composer_hint() {
|
||||
let (mut chat, _sender, mut events, _ops) = make_chatwidget_manual_with_sender().await;
|
||||
activate_voice(&mut chat);
|
||||
let custom = KeyEvent::new(KeyCode::F(8), KeyModifiers::NONE);
|
||||
for (binding, hint, handles_key) in [("'f8'", "f8 mute", true), ("[]", "/voice mute", false)] {
|
||||
let config = toml::from_str::<codex_config::types::TuiKeymap>(&format!(
|
||||
"[chat]\ntoggle_voice_mute = {binding}"
|
||||
))
|
||||
.unwrap();
|
||||
let runtime = crate::keymap::RuntimeKeymap::from_config(&config).unwrap();
|
||||
chat.apply_keymap_update(config, &runtime);
|
||||
assert!(render_bottom_popup(&chat, /*width*/ 80).contains(hint));
|
||||
assert!(!chat.handle_realtime_microphone_shortcut(KeyEvent::new(
|
||||
KeyCode::Char('x'),
|
||||
KeyModifiers::CONTROL
|
||||
)));
|
||||
assert_eq!(
|
||||
chat.handle_realtime_microphone_shortcut(custom),
|
||||
handles_key
|
||||
);
|
||||
assert_eq!(events.try_recv().is_ok(), handles_key);
|
||||
assert!(!chat.realtime_conversation.microphone_muted);
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn voice_composer_preserves_normal_colors_across_microphone_states() {
|
||||
use crate::render::renderable::Renderable;
|
||||
|
||||
Reference in new issue
Block a user