feat: add support for /diff command (#1389)

Adds support for a `/diff` command comparable to the one available in
the TypeScript CLI.

<img width="1103" alt="Screenshot 2025-06-26 at 12 31 33 PM"
src="https://github.com/user-attachments/assets/5dc646ca-301f-41ff-92a7-595c68db64b6"
/>

While here, changed the `SlashCommand` enum so the declared variant
order is the order the commands appear in the popup menu. This way,
`/toggle-mouse-mode` is listed last, as it is the least likely to be
used.

Fixes https://github.com/openai/codex/issues/1253.
This commit is contained in:
Michael Bolin
2025-06-26 13:03:31 -07:00
committed by GitHub
parent a339a7bcce
commit fa0e17f83a
8 changed files with 190 additions and 24 deletions

View File

@@ -1,5 +1,3 @@
use std::collections::HashMap;
use ratatui::buffer::Buffer;
use ratatui::layout::Rect;
use ratatui::style::Color;
@@ -25,7 +23,7 @@ use ratatui::style::Modifier;
pub(crate) struct CommandPopup {
command_filter: String,
all_commands: HashMap<&'static str, SlashCommand>,
all_commands: Vec<(&'static str, SlashCommand)>,
selected_idx: Option<usize>,
}
@@ -84,23 +82,20 @@ impl CommandPopup {
/// Return the list of commands that match the current filter. Matching is
/// performed using a *prefix* comparison on the command name.
fn filtered_commands(&self) -> Vec<&SlashCommand> {
let mut cmds: Vec<&SlashCommand> = self
.all_commands
.values()
.filter(|cmd| {
if self.command_filter.is_empty() {
true
} else {
cmd.command()
self.all_commands
.iter()
.filter_map(|(_name, cmd)| {
if self.command_filter.is_empty()
|| cmd
.command()
.starts_with(&self.command_filter.to_ascii_lowercase())
{
Some(cmd)
} else {
None
}
})
.collect();
// Sort the commands alphabetically so the order is stable and
// predictable.
cmds.sort_by(|a, b| a.command().cmp(b.command()));
cmds
.collect::<Vec<&SlashCommand>>()
}
/// Move the selection cursor one step up.