Skip to content

Commit 1ad8ae2

Browse files
color the status letter in apply patch summary (#2337)
<img width="440" height="77" alt="Screenshot 2025-08-14 at 8 30 30 PM" src="https://github.com/user-attachments/assets/c6169a3a-2e98-4ace-b7ee-918cf4368b7a" />
1 parent c1156a8 commit 1ad8ae2

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

AGENTS.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,15 @@ Before finalizing a change to `codex-rs`, run `just fmt` (in `codex-rs` director
1212
1. Run the test for the specific project that was changed. For example, if changes were made in `codex-rs/tui`, run `cargo test -p codex-tui`.
1313
2. Once those pass, if any changes were made in common, core, or protocol, run the complete test suite with `cargo test --all-features`.
1414

15+
## TUI code conventions
16+
17+
- Use concise styling helpers from ratatui’s Stylize trait.
18+
- Basic spans: use "text".into()
19+
- Styled spans: use "text".red(), "text".green(), "text".magenta(), "text".dim(), etc.
20+
- Prefer these over constructing styles with `Span::styled` and `Style` directly.
21+
- Example: patch summary file lines
22+
- Desired: vec![" └ ".into(), "M".red(), " ".dim(), "tui/src/app.rs".dim()]
23+
1524
## Snapshot tests
1625

1726
This repo uses snapshot tests (via `insta`), especially in `codex-rs/tui`, to validate rendered output. When UI or text output changes intentionally, update the snapshots as follows:

codex-rs/tui/src/history_cell.rs

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -818,8 +818,32 @@ pub(crate) fn new_patch_apply_success(stdout: String) -> PlainHistoryCell {
818818
let mut iter = stdout.lines();
819819
for (i, raw) in iter.by_ref().take(TOOL_CALL_MAX_LINES).enumerate() {
820820
let prefix = if i == 0 { " └ " } else { " " };
821-
let s = format!("{prefix}{raw}");
822-
lines.push(ansi_escape_line(&s).dim());
821+
822+
// First line is the header; dim it entirely.
823+
if i == 0 {
824+
let s = format!("{prefix}{raw}");
825+
lines.push(ansi_escape_line(&s).dim());
826+
continue;
827+
}
828+
829+
// Subsequent lines should look like: "M path/to/file".
830+
// Colorize the status letter like `git status` (e.g., M red).
831+
let status = raw.chars().next();
832+
let rest = raw.get(1..).unwrap_or("");
833+
834+
let status_span = match status {
835+
Some('M') => "M".red(),
836+
Some('A') => "A".green(),
837+
Some('D') => "D".red(),
838+
Some(other) => other.to_string().into(),
839+
None => "".into(),
840+
};
841+
842+
lines.push(Line::from(vec![
843+
prefix.into(),
844+
status_span,
845+
ansi_escape_line(rest).to_string().into(),
846+
]));
823847
}
824848
let remaining = iter.count();
825849
if remaining > 0 {

0 commit comments

Comments
 (0)