Skip to content

Commit

Permalink
add continuation to multilinebuffer
Browse files Browse the repository at this point in the history
  • Loading branch information
robinovitch61 committed Feb 11, 2025
1 parent e1d84d1 commit 245cbf7
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
16 changes: 16 additions & 0 deletions internal/viewport/linebuffer/multilinebuffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,22 @@ func (m MultiLineBuffer) Take(
currentBufferIdx++
}

// apply continuation indicators if needed
if len(continuation) > 0 {
contentToLeft := startWidth > 0
contentToRight := m.totalWidth-startWidth > takeWidth-remainingWidth

if contentToLeft || contentToRight {
continuationRunes := []rune(continuation)
if contentToLeft {
result = replaceStartWithContinuation(result, continuationRunes)
}
if contentToRight {
result = replaceEndWithContinuation(result, continuationRunes)
}
}
}

return result, takeWidth - remainingWidth
}

Expand Down
32 changes: 31 additions & 1 deletion internal/viewport/linebuffer/multlinebuffer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,37 @@ func TestMultiLineBuffer_Take(t *testing.T) {
highlightStyle: lipgloss.NewStyle(),
expected: "",
},
// TODO LEO: continuation, highlight style, other keys
{
name: "hello world with continuation at end",
key: "hello world",
startWidth: 0,
takeWidth: 7,
continuation: "...",
toHighlight: "",
highlightStyle: lipgloss.NewStyle(),
expected: "hell...",
},
{
name: "hello world with continuation at start",
key: "hello world",
startWidth: 4,
takeWidth: 7,
continuation: "...",
toHighlight: "",
highlightStyle: lipgloss.NewStyle(),
expected: "...orld",
},
{
name: "hello world with continuation both ends",
key: "hello world",
startWidth: 2,
takeWidth: 7,
continuation: "...",
toHighlight: "",
highlightStyle: lipgloss.NewStyle(),
expected: "... ...",
},
// TODO LEO: highlight style, other keys
}

for _, tt := range tests {
Expand Down

0 comments on commit 245cbf7

Please sign in to comment.