mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-06-08 02:31:18 -03:00
Reuse wcswidth logic for rendered characters
This commit is contained in:
@@ -63,15 +63,19 @@ pub fn fish_wcwidth(c: char) -> isize {
|
||||
}
|
||||
}
|
||||
|
||||
/// fish's internal versions of wcwidth and wcswidth
|
||||
pub fn fish_wcswidth(s: &wstr) -> isize {
|
||||
// ascii fast path; empty iterator returns true for .all()
|
||||
if s.chars().all(|c| c.is_ascii() && !c.is_ascii_control()) {
|
||||
fish_wcswidth_canonicalizing(s, std::convert::identity)
|
||||
}
|
||||
|
||||
pub fn fish_wcswidth_canonicalizing(s: &wstr, canonicalize: fn(char) -> char) -> isize {
|
||||
// ascii fast path
|
||||
let chars = s.chars().map(canonicalize);
|
||||
if chars.clone().all(|c| c.is_ascii() && !c.is_ascii_control()) {
|
||||
return s.len() as isize;
|
||||
}
|
||||
|
||||
let mut result = 0;
|
||||
for c in s.chars() {
|
||||
for c in chars {
|
||||
let w = fish_wcwidth(c);
|
||||
if w < 0 {
|
||||
return -1;
|
||||
|
||||
Reference in New Issue
Block a user