on main help sign in
fix(ui): ansi.truncate instead of byte slicing in todos
3a99992Kieran Klukas
internal/ui/model/pills.go+5−4
@@ -9,6 +9,7 @@ import (
9 "github.com/charmbracelet/crush/internal/session"
9 "github.com/charmbracelet/crush/internal/session"
10 "github.com/charmbracelet/crush/internal/ui/chat"
10 "github.com/charmbracelet/crush/internal/ui/chat"
11 "github.com/charmbracelet/crush/internal/ui/styles"
11 "github.com/charmbracelet/crush/internal/ui/styles"
12+ "github.com/charmbracelet/x/ansi"
12)
13)
13
14
14// pillStyle returns the appropriate style for a pill based on focus state.
15// 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
98 if currentTodo.ActiveForm != "" {
99 if currentTodo.ActiveForm != "" {
99 taskText = currentTodo.ActiveForm
100 taskText = currentTodo.ActiveForm
100 }
101 }
101− if len(taskText) > maxTaskDisplayLength {
102+ if ansi.StringWidth(taskText) > maxTaskDisplayLength {
102− taskText = taskText[:maxTaskDisplayLength-1] + "…"
103+ taskText = ansi.Truncate(taskText, maxTaskDisplayLength-1, "…")
103 }
104 }
104 task := t.Pills.TodoCurrentTask.Render(taskText)
105 task := t.Pills.TodoCurrentTask.Render(taskText)
105 content = fmt.Sprintf("%s %s %s %s", spinnerView, label, progress, task)
106 content = fmt.Sprintf("%s %s %s %s", spinnerView, label, progress, task)
@@ -124,8 +125,8 @@ func queueList(queueItems []string, t *styles.Styles) string {
124 var lines []string
125 var lines []string
125 for _, item := range queueItems {
126 for _, item := range queueItems {
126 text := item
127 text := item
127− if len(text) > maxQueueDisplayLength {
128+ if ansi.StringWidth(text) > maxQueueDisplayLength {
128− text = text[:maxQueueDisplayLength-1] + "…"
129+ text = ansi.Truncate(text, maxQueueDisplayLength-1, "…")
129 }
130 }
130 prefix := t.Pills.QueueItemPrefix.Render() + " "
131 prefix := t.Pills.QueueItemPrefix.Render() + " "
131 lines = append(lines, prefix+t.Pills.QueueItemText.Render(text))
132 lines = append(lines, prefix+t.Pills.QueueItemText.Render(text))