on main help sign in
fix(ui): ansi.truncate instead of byte slicing in todos
commit3a99992e863a5fe82266f9eec6433affac956b12 authorKieran Klukas <kieran@dunkirk.sh> dateFri 26 Jun 2026, 08:52 (4 months ago) parentf75435a
1 file changed+5−4
internal/ui/model/pills.go+5−4
internal/ui/model/pills.go+5−4
@@ -9,6 +9,7 @@ import (
99 "github.com/charmbracelet/crush/internal/session"
1010 "github.com/charmbracelet/crush/internal/ui/chat"
1111 "github.com/charmbracelet/crush/internal/ui/styles"
12+ "github.com/charmbracelet/x/ansi"
1213)
1314
1415// pillStyle returns the appropriate style for a pill based on focus state.
@@ -98,8 +99,8 @@ func todoPill(todos []session.Todo, spinnerView string, focused, panelFocused bo
9899 if currentTodo.ActiveForm != "" {
99100 taskText = currentTodo.ActiveForm
100101 }
101− if len(taskText) > maxTaskDisplayLength {
102− taskText = taskText[:maxTaskDisplayLength-1] + "…"
102+ if ansi.StringWidth(taskText) > maxTaskDisplayLength {
103+ taskText = ansi.Truncate(taskText, maxTaskDisplayLength-1, "…")
103104 }
104105 task := t.Pills.TodoCurrentTask.Render(taskText)
105106 content = fmt.Sprintf("%s %s %s %s", spinnerView, label, progress, task)
@@ -124,8 +125,8 @@ func queueList(queueItems []string, t *styles.Styles) string {
124125 var lines []string
125126 for _, item := range queueItems {
126127 text := item
127− if len(text) > maxQueueDisplayLength {
128− text = text[:maxQueueDisplayLength-1] + "…"
128+ if ansi.StringWidth(text) > maxQueueDisplayLength {
129+ text = ansi.Truncate(text, maxQueueDisplayLength-1, "…")
129130 }
130131 prefix := t.Pills.QueueItemPrefix.Render() + " "
131132 lines = append(lines, prefix+t.Pills.QueueItemText.Render(text))