chore(viewport): deprecate performance rendering stuff

This commit is contained in:
Christian Rocha
2024-09-12 10:43:36 -04:00
parent d019ed3cc9
commit 2caa9d4bdf
+17 -2
View File
@@ -50,6 +50,8 @@ type Model struct {
// //
// This should only be used in program occupying the entire terminal, // This should only be used in program occupying the entire terminal,
// which is usually via the alternate screen buffer. // which is usually via the alternate screen buffer.
//
// Deprecated: high performance rendering is now deprecated in Bubble Tea.
HighPerformanceRendering bool HighPerformanceRendering bool
initialized bool initialized bool
@@ -97,8 +99,7 @@ func (m Model) ScrollPercent() float64 {
return math.Max(0.0, math.Min(1.0, v)) return math.Max(0.0, math.Min(1.0, v))
} }
// SetContent set the pager's text content. For high performance rendering the // SetContent set the pager's text content.
// Sync command should also be called.
func (m *Model) SetContent(s string) { func (m *Model) SetContent(s string) {
s = strings.ReplaceAll(s, "\r\n", "\n") // normalize line endings s = strings.ReplaceAll(s, "\r\n", "\n") // normalize line endings
m.lines = strings.Split(s, "\n") m.lines = strings.Split(s, "\n")
@@ -126,6 +127,8 @@ func (m Model) visibleLines() (lines []string) {
} }
// scrollArea returns the scrollable boundaries for high performance rendering. // 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) { func (m Model) scrollArea() (top, bottom int) {
top = max(0, m.YPosition) top = max(0, m.YPosition)
bottom = max(top, top+m.Height) bottom = max(top, top+m.Height)
@@ -189,6 +192,8 @@ func (m *Model) LineDown(n int) (lines []string) {
m.SetYOffset(m.YOffset + n) m.SetYOffset(m.YOffset + n)
// Gather lines to send off for performance scrolling. // 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)) bottom := clamp(m.YOffset+m.Height, 0, len(m.lines))
top := clamp(m.YOffset+m.Height-n, 0, bottom) top := clamp(m.YOffset+m.Height-n, 0, bottom)
return m.lines[top:bottom] return m.lines[top:bottom]
@@ -206,6 +211,8 @@ func (m *Model) LineUp(n int) (lines []string) {
m.SetYOffset(m.YOffset - n) m.SetYOffset(m.YOffset - n)
// Gather lines to send off for performance scrolling. // Gather lines to send off for performance scrolling.
//
// XXX: high performance rendering is deprecated in Bubble Tea.
top := max(0, m.YOffset) top := max(0, m.YOffset)
bottom := clamp(m.YOffset+n, 0, m.maxYOffset()) bottom := clamp(m.YOffset+n, 0, m.maxYOffset())
return m.lines[top:bottom] return m.lines[top:bottom]
@@ -242,6 +249,8 @@ func (m *Model) GotoBottom() (lines []string) {
// first render and after a window resize. // first render and after a window resize.
// //
// For high performance rendering only. // For high performance rendering only.
//
// Deprecated: high performance rendering is deprecated in Bubble Tea.
func Sync(m Model) tea.Cmd { func Sync(m Model) tea.Cmd {
if len(m.lines) == 0 { if len(m.lines) == 0 {
return nil return nil
@@ -261,6 +270,9 @@ func ViewDown(m Model, lines []string) tea.Cmd {
return nil return nil
} }
top, bottom := m.scrollArea() 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) return tea.ScrollDown(lines, top, bottom)
} }
@@ -272,6 +284,9 @@ func ViewUp(m Model, lines []string) tea.Cmd {
return nil return nil
} }
top, bottom := m.scrollArea() 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) return tea.ScrollUp(lines, top, bottom)
} }