mirror of
https://github.com/openai/codex.git
synced 2026-11-16 22:00:36 +00:00
Preserve prompt contrast when terminal colors are unavailable (#59257)
## Why Submitted prompts need readable foreground and background colors when the terminal does not report its default colors. ## What changed - Use a contrasting gray pair for truecolor and 256-color terminals when default colors are unavailable. Keep terminal defaults for 16-color terminals and unknown color support. - Preserve voice markers, inline element accents, and asynchronous reply code colors when applying prompt styles to native history. ## Testing Add contrast coverage for each color level and terminal rendering regressions for inline elements and asynchronous reply code colors. Update prompt snapshots to cover the fallback colors. GitOrigin-RevId: dcda0fc3e2b12a5dc9046322a4d82c61986e3ecd
This commit is contained in:
@@ -52,9 +52,13 @@ fn prompt_margin_and_blank_background_survive_resize_without_changing_copy() {
|
||||
let message =
|
||||
"1234567890123456789012345678901234567890123456789012345678\n\n 界e\u{301}👩💻 trailing";
|
||||
let cell = new_user_prompt(message.into(), Vec::new(), Vec::new(), Vec::new());
|
||||
// Fix the inherited style without changing the process-wide terminal palette.
|
||||
let style = Style::default().on_dark_gray();
|
||||
let initial_lines = styled_prompt_lines(&cell, /*width*/ 60, style);
|
||||
let prompt_lines = |width| {
|
||||
crate::terminal_palette::with_test_default_colors(/*colors*/ None, || {
|
||||
cell.display_hyperlink_lines(width)
|
||||
})
|
||||
};
|
||||
let initial_lines = prompt_lines(/*width*/ 60);
|
||||
let style = initial_lines[0].line.style;
|
||||
let mut layout = TextLayout::new(initial_lines, /*width*/ 60);
|
||||
let expected_copy = format!("\n{message}\n");
|
||||
|
||||
@@ -64,7 +68,7 @@ fn prompt_margin_and_blank_background_survive_resize_without_changing_copy() {
|
||||
("prompt_margin_restored", 60),
|
||||
] {
|
||||
layout = layout.rewrap(width);
|
||||
let fresh_lines = styled_prompt_lines(&cell, width, style);
|
||||
let fresh_lines = prompt_lines(width);
|
||||
let area = Rect::new(
|
||||
/*x*/ 0,
|
||||
/*y*/ 0,
|
||||
@@ -129,13 +133,3 @@ fn reserved_margin_uses_the_same_alignment_for_painting_and_selection() {
|
||||
vec![0, 0, 0, 0, 0, 1, 2, 2],
|
||||
);
|
||||
}
|
||||
|
||||
fn styled_prompt_lines(cell: &dyn HistoryCell, width: u16, style: Style) -> Vec<HyperlinkLine> {
|
||||
cell.display_hyperlink_lines(width)
|
||||
.into_iter()
|
||||
.map(|mut line| {
|
||||
line.line.style = style;
|
||||
line
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
+3
-3
@@ -15,8 +15,8 @@ Buffer {
|
||||
" ",
|
||||
],
|
||||
styles: [
|
||||
x: 0, y: 0, fg: Reset, bg: DarkGray, underline: Reset, modifier: NONE,
|
||||
x: 0, y: 1, fg: Reset, bg: DarkGray, underline: Reset, modifier: BOLD | DIM,
|
||||
x: 2, y: 1, fg: Reset, bg: DarkGray, underline: Reset, modifier: NONE,
|
||||
x: 0, y: 0, fg: Rgb(238, 238, 238), bg: Rgb(68, 68, 68), underline: Reset, modifier: NONE,
|
||||
x: 0, y: 1, fg: Rgb(238, 238, 238), bg: Rgb(68, 68, 68), underline: Reset, modifier: BOLD | DIM,
|
||||
x: 2, y: 1, fg: Rgb(238, 238, 238), bg: Rgb(68, 68, 68), underline: Reset, modifier: NONE,
|
||||
]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user