diff --git a/viewport/viewport.go b/viewport/viewport.go index 0d82ab93c..63c0b243a 100644 --- a/viewport/viewport.go +++ b/viewport/viewport.go @@ -5,6 +5,7 @@ import ( "strings" tea "github.com/charmbracelet/bubbletea" + "github.com/muesli/reflow/wordwrap" ) const ( @@ -34,6 +35,9 @@ type Model struct { // which is usually via the alternate screen buffer. HighPerformanceRendering bool + // Wrap toggles whether the viewport should wrap lines or not. + Wrap bool + lines []string } @@ -70,6 +74,11 @@ func (m Model) ScrollPercent() float64 { // Sync command should also be called. func (m *Model) SetContent(s string) { s = strings.ReplaceAll(s, "\r\n", "\n") // normalize line endings + + if m.Wrap { + s = wordwrap.String(s, m.Width) + } + m.lines = strings.Split(s, "\n") if m.YOffset > len(m.lines)-1 {