diff options
| author | 魏曹先生 <1992414357@qq.com> | 2026-03-12 19:58:53 +0800 |
|---|---|---|
| committer | 魏曹先生 <1992414357@qq.com> | 2026-03-12 19:58:53 +0800 |
| commit | b99398fb18b209143554ee936592f129610b90ca (patch) | |
| tree | f28561136264ed2639bc37a2707614014fa1de0f /utils/src/display/str_width.rs | |
| parent | 72c57380883a1c1cc796dea6d35048ab5bed5f53 (diff) | |
Update helpdoc viewer UI and improve text handling
- Add title localization for helpdoc viewer
- Implement ANSI-aware string truncation for proper display
- Improve focus indication with color highlighting
- Move display_width utility to shared module
- Update welcome and command helpdoc formatting
- Bump copyright year to 2026
Diffstat (limited to 'utils/src/display/str_width.rs')
| -rw-r--r-- | utils/src/display/str_width.rs | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/utils/src/display/str_width.rs b/utils/src/display/str_width.rs new file mode 100644 index 0000000..a725bdb --- /dev/null +++ b/utils/src/display/str_width.rs @@ -0,0 +1,18 @@ +pub fn display_width(s: &str) -> usize { + // Filter out ANSI escape sequences before calculating width + let filtered_bytes = strip_ansi_escapes::strip(s); + let filtered_str = match std::str::from_utf8(&filtered_bytes) { + Ok(s) => s, + Err(_) => s, // Fallback to original string if UTF-8 conversion fails + }; + + let mut width = 0; + for c in filtered_str.chars() { + if c.is_ascii() { + width += 1; + } else { + width += 2; + } + } + width +} |
