fix(tui): add extra newline after thinking block for better readability

This commit is contained in:
Luxferre
2026-03-22 18:52:10 +02:00
parent d06ad6263a
commit da1cb97c9b
2 changed files with 63 additions and 2 deletions
+2 -2
View File
@@ -245,7 +245,7 @@ func (m model) renderMessage(msg sidekick.Message) string {
if m.renderer != nil {
if reasoning != "" {
if r, err := m.renderer.Render(m.formatReasoning(reasoning)); err == nil {
reasoning = strings.TrimSpace(r) + "\n"
reasoning = strings.TrimSpace(r) + "\n\n"
}
}
if content != "" {
@@ -281,7 +281,7 @@ func (m *model) updateViewportContent() {
if m.renderer != nil {
if reasoning != "" {
if r, err := m.renderer.Render(m.formatReasoning(reasoning)); err == nil {
reasoning = strings.TrimSpace(r) + "\n"
reasoning = strings.TrimSpace(r) + "\n\n"
}
}
if content != "" {
+61
View File
@@ -0,0 +1,61 @@
package main
import (
"strings"
"testing"
"github.com/charmbracelet/glamour"
"sidekick"
)
func TestRenderMessageNewlines(t *testing.T) {
r, _ := glamour.NewTermRenderer(
glamour.WithStandardStyle("dark"),
glamour.WithWordWrap(80),
)
m := model{renderer: r}
msg := sidekick.Message{
Role: sidekick.MessageRoleUser,
Content: "Line 1\nLine 2",
}
rendered := m.renderMessage(msg)
if !strings.Contains(rendered, "Line 1") || !strings.Contains(rendered, "Line 2") {
t.Errorf("rendered message missing content: %s", rendered)
}
// Check if newline is preserved. If squashed, it might be "Line 1 Line 2"
if strings.Contains(rendered, "Line 1 Line 2") {
t.Error("newlines were squashed in user message")
}
}
func TestRenderMessageReasoningGap(t *testing.T) {
r, _ := glamour.NewTermRenderer(
glamour.WithStandardStyle("dark"),
glamour.WithWordWrap(80),
)
m := model{renderer: r}
msg := sidekick.Message{
Role: sidekick.MessageRoleAssistant,
Reasoning: "Thinking about it",
Content: "Actual response",
}
rendered := m.renderMessage(msg)
// Check if there is a gap between Thinking and Response
if !strings.Contains(rendered, "Thinking") || !strings.Contains(rendered, "Actual") || !strings.Contains(rendered, "response") {
t.Errorf("rendered message missing content: %s", rendered)
}
// If there's no blank line between reasoning and content, they might be too close.
// We want to see if they are on adjacent lines or have a gap.
// The user says "next one begins immediately while it should start from a new line"
// This might mean it's on the SAME line if glamour messed up, or just next line.
// Let's print it to see
t.Logf("Rendered Assistant:\n%s", rendered)
}