use unicode_width::UnicodeWidthStr;
pub(super) const SELECTION_MARKER_ACTIVE: &str = "→";
pub(super) const SELECTION_MARKER_INACTIVE: &str = " ";
pub(super) const FOOTER_SEPARATOR: &str = " · ";
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub(super) enum ComposerDividerSlot {
Top,
Bottom,
}
pub(super) fn join_footer_parts<'a>(parts: impl IntoIterator<Item = &'a str>) -> String {
wrap_footer_parts(parts, usize::MAX)
.into_iter()
.next()
.unwrap_or_default()
}
pub(super) fn wrap_footer_parts<'a>(
parts: impl IntoIterator<Item = &'a str>,
width: usize,
) -> Vec<String> {
let width = width.max(1);
let sep_width = UnicodeWidthStr::width(FOOTER_SEPARATOR);
let mut lines = Vec::new();
let mut current = String::new();
let mut current_width = 0usize;
for part in parts.into_iter().filter(|part| !part.is_empty()) {
let part_width = UnicodeWidthStr::width(part);
if current.is_empty() {
current.push_str(part);
current_width = part_width;
continue;
}
if current_width
.saturating_add(sep_width)
.saturating_add(part_width)
<= width
{
current.push_str(FOOTER_SEPARATOR);
current.push_str(part);
current_width = current_width
.saturating_add(sep_width)
.saturating_add(part_width);
continue;
}
lines.push(std::mem::take(&mut current));
current.push_str(part);
current_width = part_width;
}
if !current.is_empty() {
lines.push(current);
}
lines
}
#[cfg(test)]
#[path = "composer_chrome_tests.rs"]
mod tests;