Commit 81d66d7
authored
fix: proper Unicode/Chinese character handling in UI (#234)
## Summary
Fix garbled display and incorrect backspace behavior for Chinese/Unicode
characters in the TUI.
Closes #233
## Problem
Chinese and other multi-byte Unicode characters were displaying as
garbled text (e.g., `是的分身艺术�`) because:
1. **String truncation used byte slicing** (`str[:n]`), which cuts UTF-8
characters in the middle
2. **Backspace deleted only 1 byte** instead of 1 character, corrupting
multi-byte characters
3. **Width calculations used `len()`** which returns byte count, not
display width
## Solution
Use `github.com/mattn/go-runewidth` (already a dependency) for proper
Unicode handling:
- `runewidth.StringWidth()` - calculate actual display width
- `runewidth.Truncate()` - safely truncate strings without breaking
characters
- `[]rune()` conversion - for character-based operations like backspace
## Changes
| File | Change |
|------|--------|
| `ui/list.go` | Use `runewidth` for title/branch truncation and width
calculation |
| `ui/err.go` | Use `runewidth` for error message truncation |
| `app/app.go` | Convert to `[]rune` for backspace, use `runewidth` for
length check |
## Testing
- [x] Tested with Chinese characters in instance names
- [x] Tested backspace deletion of Chinese characters
- [x] All existing tests pass (`go test ./...`)
- [x] Build succeeds (`go build .`)
## Screenshots
**Before (Bug):**
Instance names with Chinese characters show garbled text when truncated
or after backspace.
**After (Fixed):**
Chinese characters display correctly and backspace removes whole
characters.1 parent fc1b967 commit 81d66d7
3 files changed
+21
-15
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| 18 | + | |
18 | 19 | | |
19 | 20 | | |
20 | 21 | | |
| |||
360 | 361 | | |
361 | 362 | | |
362 | 363 | | |
363 | | - | |
| 364 | + | |
364 | 365 | | |
365 | 366 | | |
366 | 367 | | |
367 | 368 | | |
368 | 369 | | |
369 | 370 | | |
370 | | - | |
| 371 | + | |
| 372 | + | |
371 | 373 | | |
372 | 374 | | |
373 | | - | |
| 375 | + | |
374 | 376 | | |
375 | 377 | | |
376 | 378 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
5 | 4 | | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
6 | 8 | | |
7 | 9 | | |
8 | 10 | | |
| |||
38 | 40 | | |
39 | 41 | | |
40 | 42 | | |
41 | | - | |
42 | | - | |
| 43 | + | |
| 44 | + | |
43 | 45 | | |
44 | 46 | | |
45 | 47 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
12 | 13 | | |
13 | 14 | | |
14 | 15 | | |
| |||
139 | 140 | | |
140 | 141 | | |
141 | 142 | | |
142 | | - | |
143 | | - | |
144 | | - | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
145 | 146 | | |
146 | 147 | | |
147 | 148 | | |
| |||
171 | 172 | | |
172 | 173 | | |
173 | 174 | | |
174 | | - | |
175 | | - | |
| 175 | + | |
| 176 | + | |
176 | 177 | | |
177 | | - | |
| 178 | + | |
178 | 179 | | |
179 | 180 | | |
180 | 181 | | |
| |||
192 | 193 | | |
193 | 194 | | |
194 | 195 | | |
| 196 | + | |
195 | 197 | | |
196 | 198 | | |
197 | | - | |
| 199 | + | |
198 | 200 | | |
199 | 201 | | |
200 | 202 | | |
201 | 203 | | |
202 | | - | |
| 204 | + | |
203 | 205 | | |
204 | 206 | | |
205 | | - | |
| 207 | + | |
206 | 208 | | |
207 | 209 | | |
208 | 210 | | |
| |||
0 commit comments