Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions internal/tui/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,8 +320,15 @@ func (m Model) viewObservationDetail() string {
b.WriteString(sectionHeadingStyle.Render(" Content"))
b.WriteString("\n")

// Split content into lines and apply scroll
contentLines := strings.Split(obs.Content, "\n")
// Wrap content based on terminal width
wrapWidth := m.Width - 6 // basic padding
if wrapWidth < 20 {
wrapWidth = 20
}
wrappedContent := detailContentStyle.Width(wrapWidth).Render(obs.Content)

// Split wrapped content into lines
contentLines := strings.Split(wrappedContent, "\n")
maxLines := m.Height - 16
if maxLines < 5 {
maxLines = 5
Expand All @@ -342,7 +349,7 @@ func (m Model) viewObservationDetail() string {
}

for i := m.DetailScroll; i < end; i++ {
b.WriteString(detailContentStyle.Render(contentLines[i]))
b.WriteString(contentLines[i])
b.WriteString("\n")
}

Expand Down
45 changes: 45 additions & 0 deletions internal/tui/wrap_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package tui

import (
"strings"
"testing"

"github.com/Gentleman-Programming/engram/internal/store"
)

func TestViewObservationDetailWrapping(t *testing.T) {
m := Model{
Width: 40,
Height: 20,
Screen: ScreenObservationDetail,
SelectedObservation: &store.Observation{
ID: 1,
Type: "note",
Title: "Test",
Content: "This is a very long line of text that should definitely be wrapped when the width is only forty characters wide.",
},
}

view := m.viewObservationDetail()

// The line "This is a very long line of text that should definitely be wrapped when the width is only forty characters wide."
// is much longer than 40 chars. With wrapWidth = Width - 6 = 34, it should split.

lines := strings.Split(view, "\n")
contentStarted := false
contentLines := 0

for _, line := range lines {
if strings.Contains(line, "Content") {
contentStarted = true
continue
}
if contentStarted && strings.TrimSpace(line) != "" && !strings.Contains(line, "scroll") {
contentLines++
}
}

if contentLines <= 1 {
t.Errorf("Expected content to be wrapped into multiple lines, but got %d content lines", contentLines)
}
}