Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(viewport): deprecate performance rendering stuff #612

Merged
merged 2 commits into from
Sep 12, 2024
Merged
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
4 changes: 2 additions & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ issues:
linters:
enable:
- bodyclose
- exportloopref
- copyloopvar
- gofumpt
- goimports
- gosec
Expand All @@ -28,6 +28,6 @@ linters:
- unconvert
- unparam
- whitespace
# We're isabling predeclared because the linter is running a newer version
# We're disabling predeclared because the linter is running a newer version
# of Go than then Go module.
# - predeclared
19 changes: 17 additions & 2 deletions viewport/viewport.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ type Model struct {
//
// This should only be used in program occupying the entire terminal,
// which is usually via the alternate screen buffer.
//
// Deprecated: high performance rendering is now deprecated in Bubble Tea.
HighPerformanceRendering bool

initialized bool
Expand Down Expand Up @@ -97,8 +99,7 @@ func (m Model) ScrollPercent() float64 {
return math.Max(0.0, math.Min(1.0, v))
}

// SetContent set the pager's text content. For high performance rendering the
// Sync command should also be called.
// SetContent set the pager's text content.
func (m *Model) SetContent(s string) {
s = strings.ReplaceAll(s, "\r\n", "\n") // normalize line endings
m.lines = strings.Split(s, "\n")
Expand Down Expand Up @@ -126,6 +127,8 @@ func (m Model) visibleLines() (lines []string) {
}

// scrollArea returns the scrollable boundaries for high performance rendering.
//
// XXX: high performance rendering is deprecated in Bubble Tea.
func (m Model) scrollArea() (top, bottom int) {
top = max(0, m.YPosition)
bottom = max(top, top+m.Height)
Expand Down Expand Up @@ -189,6 +192,8 @@ func (m *Model) LineDown(n int) (lines []string) {
m.SetYOffset(m.YOffset + n)

// Gather lines to send off for performance scrolling.
//
// XXX: high performance rendering is deprecated in Bubble Tea.
bottom := clamp(m.YOffset+m.Height, 0, len(m.lines))
top := clamp(m.YOffset+m.Height-n, 0, bottom)
return m.lines[top:bottom]
Expand All @@ -206,6 +211,8 @@ func (m *Model) LineUp(n int) (lines []string) {
m.SetYOffset(m.YOffset - n)

// Gather lines to send off for performance scrolling.
//
// XXX: high performance rendering is deprecated in Bubble Tea.
top := max(0, m.YOffset)
bottom := clamp(m.YOffset+n, 0, m.maxYOffset())
return m.lines[top:bottom]
Expand Down Expand Up @@ -242,6 +249,8 @@ func (m *Model) GotoBottom() (lines []string) {
// first render and after a window resize.
//
// For high performance rendering only.
//
// Deprecated: high performance rendering is deprecated in Bubble Tea.
func Sync(m Model) tea.Cmd {
if len(m.lines) == 0 {
return nil
Expand All @@ -261,6 +270,9 @@ func ViewDown(m Model, lines []string) tea.Cmd {
return nil
}
top, bottom := m.scrollArea()

// XXX: high performance rendering is deprecated in Bubble Tea. In a v2 we
// won't need to return a command here.
return tea.ScrollDown(lines, top, bottom)
}

Expand All @@ -272,6 +284,9 @@ func ViewUp(m Model, lines []string) tea.Cmd {
return nil
}
top, bottom := m.scrollArea()

// XXX: high performance rendering is deprecated in Bubble Tea. In a v2 we
// won't need to return a command here.
return tea.ScrollUp(lines, top, bottom)
}

Expand Down
Loading