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:
@@ -104,6 +104,9 @@ pub(crate) enum HistoryCell {
|
||||
/// Background event.
|
||||
BackgroundEvent { view: TextBlock },
|
||||
|
||||
/// Output from the `/diff` command.
|
||||
GitDiffOutput { view: TextBlock },
|
||||
|
||||
/// Error event from the backend.
|
||||
ErrorEvent { view: TextBlock },
|
||||
|
||||
@@ -453,13 +456,29 @@ impl HistoryCell {
|
||||
pub(crate) fn new_background_event(message: String) -> Self {
|
||||
let mut lines: Vec<Line<'static>> = Vec::new();
|
||||
lines.push(Line::from("event".dim()));
|
||||
lines.extend(message.lines().map(|l| Line::from(l.to_string()).dim()));
|
||||
lines.extend(message.lines().map(|line| ansi_escape_line(line).dim()));
|
||||
lines.push(Line::from(""));
|
||||
HistoryCell::BackgroundEvent {
|
||||
view: TextBlock::new(lines),
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn new_diff_output(message: String) -> Self {
|
||||
let mut lines: Vec<Line<'static>> = Vec::new();
|
||||
lines.push(Line::from("/diff".magenta()));
|
||||
|
||||
if message.trim().is_empty() {
|
||||
lines.push(Line::from("No changes detected.".italic()));
|
||||
} else {
|
||||
lines.extend(message.lines().map(ansi_escape_line));
|
||||
}
|
||||
|
||||
lines.push(Line::from(""));
|
||||
HistoryCell::GitDiffOutput {
|
||||
view: TextBlock::new(lines),
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn new_error_event(message: String) -> Self {
|
||||
let lines: Vec<Line<'static>> = vec![
|
||||
vec!["ERROR: ".red().bold(), message.into()].into(),
|
||||
@@ -549,6 +568,7 @@ impl CellWidget for HistoryCell {
|
||||
| HistoryCell::AgentMessage { view }
|
||||
| HistoryCell::AgentReasoning { view }
|
||||
| HistoryCell::BackgroundEvent { view }
|
||||
| HistoryCell::GitDiffOutput { view }
|
||||
| HistoryCell::ErrorEvent { view }
|
||||
| HistoryCell::SessionInfo { view }
|
||||
| HistoryCell::CompletedExecCommand { view }
|
||||
@@ -570,6 +590,7 @@ impl CellWidget for HistoryCell {
|
||||
| HistoryCell::AgentMessage { view }
|
||||
| HistoryCell::AgentReasoning { view }
|
||||
| HistoryCell::BackgroundEvent { view }
|
||||
| HistoryCell::GitDiffOutput { view }
|
||||
| HistoryCell::ErrorEvent { view }
|
||||
| HistoryCell::SessionInfo { view }
|
||||
| HistoryCell::CompletedExecCommand { view }
|
||||
|
||||
Reference in New Issue
Block a user