mod cells;
mod parser;
mod segment;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
pub enum WidthMethod {
#[default]
WcWidth,
GraphemeWidth,
}
impl WidthMethod {
#[must_use]
pub fn string_width(self, text: &str) -> usize {
parser::string_width(text, self)
}
fn cluster_width(self, cluster: &str) -> usize {
match self {
Self::WcWidth => cells::wc_width(cluster),
Self::GraphemeWidth => cells::cluster_width(cluster),
}
}
}
pub(crate) fn first_cluster(s: &str, method: WidthMethod) -> (&str, usize) {
let cluster = &s[..segment::first_len(s)];
(cluster, method.cluster_width(cluster))
}
#[cfg(test)]
mod tests;