mirror of
https://github.com/openai/codex.git
synced 2026-11-27 23:31:09 +00:00
## What changed Replace duplicated footer wrapping in the MCP elicitation and request-user-input overlays with `wrap_hint_rows`. Preserve whole-hint grouping, display-width and separator accounting, oversized hints, and the single empty row for empty input. ## Testing Add unit tests for Unicode display widths, whole-hint wrapping, oversized hints at zero width, and empty input. GitOrigin-RevId: 4d8ead0acbfa3bf9241baedb86d2476566d26ebc
41 lines
1.1 KiB
Rust
41 lines
1.1 KiB
Rust
//! Packs footer hints into rows without separating a shortcut from its label.
|
|
//! Callers retain ownership of styling and of clipping or wrapping oversized hints.
|
|
|
|
pub(crate) fn wrap_hint_rows<T>(
|
|
hints: impl IntoIterator<Item = T>,
|
|
width: u16,
|
|
separator_width: usize,
|
|
hint_width: impl Fn(&T) -> usize,
|
|
) -> Vec<Vec<T>> {
|
|
let width = usize::from(width.max(1));
|
|
let mut rows = Vec::new();
|
|
let mut row = Vec::new();
|
|
let mut used = 0usize;
|
|
for hint in hints {
|
|
let hint_width = hint_width(&hint).min(width);
|
|
let extra = if row.is_empty() {
|
|
hint_width
|
|
} else {
|
|
separator_width.saturating_add(hint_width)
|
|
};
|
|
if !row.is_empty() && used.saturating_add(extra) > width {
|
|
rows.push(std::mem::take(&mut row));
|
|
used = 0;
|
|
}
|
|
if row.is_empty() {
|
|
used = hint_width;
|
|
} else {
|
|
used = used
|
|
.saturating_add(separator_width)
|
|
.saturating_add(hint_width);
|
|
}
|
|
row.push(hint);
|
|
}
|
|
rows.push(row);
|
|
rows
|
|
}
|
|
|
|
#[cfg(test)]
|
|
#[path = "footer_hint_tests.rs"]
|
|
mod tests;
|