mirror of
https://github.com/openai/codex.git
synced 2026-11-28 07:32:19 +00:00
## What changed - Accept two-stroke bindings such as `ctrl-x ctrl-s` in TUI keymap configuration while preserving arrays as alternative bindings. - Route chords through the active TUI context, show pending and configured chord hints, and cancel pending chords on `esc`, context changes, or a one-second timeout. - Extend `/keymap` to capture, add, replace, and display key chords. - Reject chords that conflict with active single-key bindings, overlapping-context chords, or reserved terminal shortcuts. ## Testing - Add coverage for chord parsing, validation, matching, timeout and cancellation behavior, context dispatch, key capture, and rendered shortcut hints. GitOrigin-RevId: dfdede03f518d4936ad8621ebf5537026f2b282e
62 lines
1.8 KiB
Rust
62 lines
1.8 KiB
Rust
//! Shared popup-related constants for bottom pane widgets.
|
|
|
|
use ratatui::text::Line;
|
|
|
|
use crate::key_hint;
|
|
use crate::key_hint::ShortcutHint;
|
|
use crate::keymap::ListAction;
|
|
use crate::keymap::ListKeymap;
|
|
use crossterm::event::KeyCode;
|
|
|
|
/// Maximum number of rows any popup should attempt to display.
|
|
/// Keep this consistent across all popups for a uniform feel.
|
|
pub(crate) const MAX_POPUP_ROWS: usize = 8;
|
|
|
|
/// Standard footer hint text used by popups.
|
|
pub(crate) fn standard_popup_hint_line() -> Line<'static> {
|
|
Line::from(vec![
|
|
"Press ".into(),
|
|
key_hint::plain(KeyCode::Enter).into(),
|
|
" to confirm or ".into(),
|
|
key_hint::plain(KeyCode::Esc).into(),
|
|
" to go back".into(),
|
|
])
|
|
}
|
|
|
|
pub(crate) fn standard_popup_hint_line_for_keymap(list_keymap: &ListKeymap) -> Line<'static> {
|
|
accept_cancel_hint_line(
|
|
list_keymap.primary_hint(ListAction::Accept),
|
|
"to confirm",
|
|
list_keymap.primary_hint(ListAction::Cancel),
|
|
"to go back",
|
|
)
|
|
}
|
|
|
|
pub(crate) fn accept_cancel_hint_line(
|
|
accept: Option<ShortcutHint>,
|
|
accept_label: &'static str,
|
|
cancel: Option<ShortcutHint>,
|
|
cancel_label: &'static str,
|
|
) -> Line<'static> {
|
|
match (accept, cancel) {
|
|
(Some(accept), Some(cancel)) => Line::from(vec![
|
|
"Press ".into(),
|
|
accept.into(),
|
|
format!(" {accept_label} or ").into(),
|
|
cancel.into(),
|
|
format!(" {cancel_label}").into(),
|
|
]),
|
|
(Some(accept), None) => Line::from(vec![
|
|
"Press ".into(),
|
|
accept.into(),
|
|
format!(" {accept_label}").into(),
|
|
]),
|
|
(None, Some(cancel)) => Line::from(vec![
|
|
"Press ".into(),
|
|
cancel.into(),
|
|
format!(" {cancel_label}").into(),
|
|
]),
|
|
(None, None) => Line::from(""),
|
|
}
|
|
}
|