Skip to content

fix insert_history modifier handling #1774

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 10 additions & 17 deletions codex-rs/tui/src/history_cell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -545,24 +545,17 @@ impl HistoryCell {
} else {
for (idx, PlanItemArg { step, status }) in plan.into_iter().enumerate() {
let num = idx + 1;
let (icon, style): (&str, Style) = match status {
StepStatus::Completed => ("✓", Style::default().fg(Color::Green)),
StepStatus::InProgress => (
"▶",
Style::default()
.fg(Color::Yellow)
.add_modifier(Modifier::BOLD),
),
StepStatus::Pending => ("○", Style::default().fg(Color::Gray)),
let icon_span: Span = match status {
StepStatus::Completed => Span::from("✓").fg(Color::Green),
StepStatus::InProgress => Span::from("▶").fg(Color::Yellow).bold(),
StepStatus::Pending => Span::from("○").fg(Color::Gray),
};
let prefix = vec![
Span::raw(format!("{num:>2}. [")),
Span::styled(icon.to_string(), style),
Span::raw("] "),
];
let mut spans = prefix;
spans.push(Span::raw(step));
lines.push(Line::from(spans));
lines.push(Line::from(vec![
format!("{num:>2}. [").into(),
icon_span,
"] ".into(),
step.into(),
]));
Comment on lines -548 to +558
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is semantically unchanged, just refactored to be more readable.

}
}

Expand Down
50 changes: 42 additions & 8 deletions codex-rs/tui/src/insert_history.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,18 +216,18 @@ where
{
let mut fg = Color::Reset;
let mut bg = Color::Reset;
let mut modifier = Modifier::empty();
let mut last_modifier = Modifier::empty();
for span in content {
let mut next_modifier = modifier;
next_modifier.insert(span.style.add_modifier);
next_modifier.remove(span.style.sub_modifier);
if next_modifier != modifier {
let mut modifier = Modifier::empty();
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the bugfix.

modifier.insert(span.style.add_modifier);
modifier.remove(span.style.sub_modifier);
if modifier != last_modifier {
let diff = ModifierDiff {
from: modifier,
to: next_modifier,
from: last_modifier,
to: modifier,
};
diff.queue(&mut writer)?;
modifier = next_modifier;
last_modifier = modifier;
}
let next_fg = span.style.fg.unwrap_or(Color::Reset);
let next_bg = span.style.bg.unwrap_or(Color::Reset);
Expand All @@ -250,3 +250,37 @@ where
SetAttribute(crossterm::style::Attribute::Reset),
)
}

#[cfg(test)]
mod tests {
#![allow(clippy::unwrap_used)]
use super::*;

#[test]
fn writes_bold_then_regular_spans() {
use ratatui::style::Stylize;

let spans = ["A".bold(), "B".into()];

let mut actual: Vec<u8> = Vec::new();
write_spans(&mut actual, spans.iter()).unwrap();

let mut expected: Vec<u8> = Vec::new();
queue!(
expected,
SetAttribute(crossterm::style::Attribute::Bold),
Print("A"),
SetAttribute(crossterm::style::Attribute::NormalIntensity),
Print("B"),
SetForegroundColor(CColor::Reset),
SetBackgroundColor(CColor::Reset),
SetAttribute(crossterm::style::Attribute::Reset),
)
.unwrap();

assert_eq!(
String::from_utf8(actual).unwrap(),
String::from_utf8(expected).unwrap()
);
}
}