@@ -780,13 +780,21 @@ func renderPlainContent(v *toolCallCmp, content string) string {
780 return strings.Join(out, "\n")
780 return strings.Join(out, "\n")
783−func pad(v any, width int) string {
783+func getDigits(n int) int {
784− s := fmt.Sprintf("%v", v)
784+ if n == 0 {
785− w := ansi.StringWidth(s)
787− return s
785+ return 1
789− return strings.Repeat(" ", width-w) + s
787+ if n < 0 {
792func renderCodeContent(v *toolCallCmp, path, content string, offset int) string {
800func renderCodeContent(v *toolCallCmp, path, content string, offset int) string {
@@ -800,30 +808,37 @@ func renderCodeContent(v *toolCallCmp, path, content string, offset int) string
800 lines[i] = ansiext.Escape(ln)
808 lines[i] = ansiext.Escape(ln)
803− highlighted, _ := highlight.SyntaxHighlight(strings.Join(lines, "\n"), path, t.BgBase)
812+ highlighted, _ := highlight.SyntaxHighlight(strings.Join(lines, "\n"), path, bg)
804 lines = strings.Split(highlighted, "\n")
813 lines = strings.Split(highlighted, "\n")
806 if len(strings.Split(content, "\n")) > responseContextHeight {
815 if len(strings.Split(content, "\n")) > responseContextHeight {
807 lines = append(lines, t.S().Muted.
816 lines = append(lines, t.S().Muted.
808− Background(t.BgBase).
817+ Background(bg).
809 Render(fmt.Sprintf(" …(%d lines)", len(strings.Split(content, "\n"))-responseContextHeight)))
818 Render(fmt.Sprintf(" …(%d lines)", len(strings.Split(content, "\n"))-responseContextHeight)))
812 maxLineNumber := len(lines) + offset
821 maxLineNumber := len(lines) + offset
813− padding := lipgloss.Width(fmt.Sprintf("%d", maxLineNumber))
822+ maxDigits := getDigits(maxLineNumber)
823+ numFmt := fmt.Sprintf("%%%dd", maxDigits)
824+ const numPR, numPL, codePR, codePL = 1, 1, 1, 2
825+ w := v.textWidth() - maxDigits - numPL - numPR - 2 // -2 for left padding
814 for i, ln := range lines {
826 for i, ln := range lines {
815 num := t.S().Base.
827 num := t.S().Base.
816 Foreground(t.FgMuted).
828 Foreground(t.FgMuted).
817 Background(t.BgBase).
829 Background(t.BgBase).
818 PaddingRight(1).
830 PaddingRight(1).
819 PaddingLeft(1).
831 PaddingLeft(1).
820− Render(pad(i+1+offset, padding))
832+ Render(fmt.Sprintf(numFmt, i+1+offset))
821− w := v.textWidth() - 10 - lipgloss.Width(num) // -4 for left padding
822 lines[i] = lipgloss.JoinHorizontal(lipgloss.Left,
833 lines[i] = lipgloss.JoinHorizontal(lipgloss.Left,
824 t.S().Base.
835 t.S().Base.
825− PaddingLeft(1).
839+ PaddingLeft(2).
826− Render(v.fit(ln, w-1)))
840+ Render(v.fit(ln, w-codePL-codePR)),
829 return lipgloss.JoinVertical(lipgloss.Left, lines...)
844 return lipgloss.JoinVertical(lipgloss.Left, lines...)