summaryrefslogtreecommitdiffstats
path: root/src/client
diff options
context:
space:
mode:
Diffstat (limited to 'src/client')
-rw-r--r--src/client/ui.rs24
1 files changed, 23 insertions, 1 deletions
diff --git a/src/client/ui.rs b/src/client/ui.rs
index 11cedc7..1a35db1 100644
--- a/src/client/ui.rs
+++ b/src/client/ui.rs
@@ -159,7 +159,29 @@ pub fn parse_bet_arg(raw: &str) -> Result<u64, String> {
159/// ASCII, Latin diacritics, combining marks, CJK, and the common emoji ranges 159/// ASCII, Latin diacritics, combining marks, CJK, and the common emoji ranges
160/// without adding a dependency. 160/// without adding a dependency.
161pub fn display_width(text: &str) -> usize { 161pub fn display_width(text: &str) -> usize {
162 text.chars().map(char_width).sum() 162 let mut width = 0;
163 let mut chars = text.chars().peekable();
164
165 while let Some(character) = chars.next() {
166 if character == '\x1b' {
167 if chars.peek() == Some(&'[') {
168 chars.next();
169 // Skip CSI parameters until the final byte (@ through ~).
170 for character in chars.by_ref() {
171 if ('@'..='~').contains(&character) {
172 break;
173 }
174 }
175 } else {
176 // Two-character escape sequence.
177 chars.next();
178 }
179 continue;
180 }
181 width += char_width(character);
182 }
183
184 width
163} 185}
164 186
165fn char_width(c: char) -> usize { 187fn char_width(c: char) -> usize {