mirror of
https://github.com/openai/codex.git
synced 2026-11-01 16:17:58 +00:00
Introduces support for slash commands like in the TypeScript CLI. We do not support the full set of commands yet, but the core abstraction is there now. In particular, we have a `SlashCommand` enum and due to thoughtful use of the [strum](https://crates.io/crates/strum) crate, it requires minimal boilerplate to add a new command to the list. The key new piece of UI is `CommandPopup`, though the keyboard events are still handled by `ChatComposer`. The behavior is roughly as follows: * if the first character in the composer is `/`, the command popup is displayed (if you really want to send a message to Codex that starts with a `/`, simply put a space before the `/`) * while the popup is displayed, up/down can be used to change the selection of the popup * if there is a selection, hitting tab completes the command, but does not send it * if there is a selection, hitting enter sends the command * if the prefix of the composer matches a command, the command will be visible in the popup so the user can see the description (commands could take arguments, so additional text may appear after the command name itself) https://github.com/user-attachments/assets/39c3e6ee-eeb7-4ef7-a911-466d8184975f Incidentally, Codex wrote almost all the code for this PR!
32 lines
864 B
Rust
32 lines
864 B
Rust
use codex_core::protocol::Event;
|
|
use crossterm::event::KeyEvent;
|
|
|
|
use crate::slash_command::SlashCommand;
|
|
|
|
#[allow(clippy::large_enum_variant)]
|
|
pub(crate) enum AppEvent {
|
|
CodexEvent(Event),
|
|
|
|
Redraw,
|
|
|
|
KeyEvent(KeyEvent),
|
|
|
|
/// Scroll event with a value representing the "scroll delta" as the net
|
|
/// scroll up/down events within a short time window.
|
|
Scroll(i32),
|
|
|
|
/// Request to exit the application gracefully.
|
|
ExitRequest,
|
|
|
|
/// Forward an `Op` to the Agent. Using an `AppEvent` for this avoids
|
|
/// bubbling channels through layers of widgets.
|
|
CodexOp(codex_core::protocol::Op),
|
|
|
|
/// Latest formatted log line emitted by `tracing`.
|
|
LatestLog(String),
|
|
|
|
/// Dispatch a recognized slash command from the UI (composer) to the app
|
|
/// layer so it can be handled centrally.
|
|
DispatchCommand(SlashCommand),
|
|
}
|