Skip to content

Commit

Permalink
allow viewport to wrap lines
Browse files Browse the repository at this point in the history
  • Loading branch information
IllusionMan1212 committed Dec 25, 2021
1 parent 0f500d5 commit 5c7a0b5
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions viewport/viewport.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"strings"

tea "github.com/charmbracelet/bubbletea"
"github.com/muesli/reflow/wordwrap"
)

const (
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 5c7a0b5

Please sign in to comment.