Skip to content

Commit b423c61

Browse files
committed
refactor!: viewport: remove deprecated HighPerformanceRendering
This breaks the API and removes high performance rendering and its related methods from the viewport package. It changes the API and makes the methods return nothing instead of lines to render.
1 parent f81fd52 commit b423c61

File tree

3 files changed

+23
-120
lines changed

3 files changed

+23
-120
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ go 1.18
55
require (
66
github.com/MakeNowJust/heredoc v1.0.0
77
github.com/atotto/clipboard v0.1.4
8-
github.com/charmbracelet/bubbletea/v2 v2.0.0-alpha.1
8+
github.com/charmbracelet/bubbletea/v2 v2.0.0-alpha.1.0.20240919172237-265996c29bea
99
github.com/charmbracelet/harmonica v0.2.0
1010
github.com/charmbracelet/lipgloss v0.13.0
1111
github.com/charmbracelet/x/ansi v0.3.2

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ github.com/aymanbagabas/go-udiff v0.2.0 h1:TK0fH4MteXUDspT88n8CKzvK0X9O2xu9yQjWp
88
github.com/aymanbagabas/go-udiff v0.2.0/go.mod h1:RE4Ex0qsGkTAJoQdQQCA0uG+nAzJO/pI/QwceO5fgrA=
99
github.com/charmbracelet/bubbletea/v2 v2.0.0-alpha.1 h1:OZtpLCsuuPplC+1oyUo+/eAN7e9MC2UyZWKlKrVlUnw=
1010
github.com/charmbracelet/bubbletea/v2 v2.0.0-alpha.1/go.mod h1:j0gn4ft5CE7NDYNZjAA3hBM8t2OPjI8urxuAD0oR4w8=
11+
github.com/charmbracelet/bubbletea/v2 v2.0.0-alpha.1.0.20240919172237-265996c29bea h1:i32Z8pIQujNjR2BffDviAnai2L9oLMW7jMd7aCD8Jqg=
12+
github.com/charmbracelet/bubbletea/v2 v2.0.0-alpha.1.0.20240919172237-265996c29bea/go.mod h1:j0gn4ft5CE7NDYNZjAA3hBM8t2OPjI8urxuAD0oR4w8=
1113
github.com/charmbracelet/harmonica v0.2.0 h1:8NxJWRWg/bzKqqEaaeFNipOu77YR5t8aSwG4pgaUBiQ=
1214
github.com/charmbracelet/harmonica v0.2.0/go.mod h1:KSri/1RMQOZLbw7AHqgcBycp8pgJnQMYYT8QZRqZ1Ao=
1315
github.com/charmbracelet/lipgloss v0.13.0 h1:4X3PPeoWEDCMvzDvGmTajSyYPcZM4+y8sCA/SsA3cjw=

viewport/viewport.go

Lines changed: 20 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,6 @@ type Model struct {
4242
// useful for setting borders, margins and padding.
4343
Style lipgloss.Style
4444

45-
// HighPerformanceRendering bypasses the normal Bubble Tea renderer to
46-
// provide higher performance rendering. Most of the time the normal Bubble
47-
// Tea rendering methods will suffice, but if you're passing content with
48-
// a lot of ANSI escape codes you may see improved rendering in certain
49-
// terminals with this enabled.
50-
//
51-
// This should only be used in program occupying the entire terminal,
52-
// which is usually via the alternate screen buffer.
53-
//
54-
// Deprecated: high performance rendering is now deprecated in Bubble Tea.
55-
HighPerformanceRendering bool
56-
5745
initialized bool
5846
lines []string
5947
}
@@ -145,12 +133,12 @@ func (m *Model) SetYOffset(n int) {
145133

146134
// ViewDown moves the view down by the number of lines in the viewport.
147135
// Basically, "page down".
148-
func (m *Model) ViewDown() []string {
136+
func (m *Model) ViewDown() {
149137
if m.AtBottom() {
150-
return nil
138+
return
151139
}
152140

153-
return m.LineDown(m.Height)
141+
m.LineDown(m.Height)
154142
}
155143

156144
// ViewUp moves the view up by one height of the viewport. Basically, "page up".
@@ -163,40 +151,33 @@ func (m *Model) ViewUp() []string {
163151
}
164152

165153
// HalfViewDown moves the view down by half the height of the viewport.
166-
func (m *Model) HalfViewDown() (lines []string) {
154+
func (m *Model) HalfViewDown() {
167155
if m.AtBottom() {
168-
return nil
156+
return
169157
}
170158

171-
return m.LineDown(m.Height / 2)
159+
m.LineDown(m.Height / 2)
172160
}
173161

174162
// HalfViewUp moves the view up by half the height of the viewport.
175-
func (m *Model) HalfViewUp() (lines []string) {
163+
func (m *Model) HalfViewUp() {
176164
if m.AtTop() {
177-
return nil
165+
return
178166
}
179167

180-
return m.LineUp(m.Height / 2)
168+
m.LineUp(m.Height / 2)
181169
}
182170

183171
// LineDown moves the view down by the given number of lines.
184-
func (m *Model) LineDown(n int) (lines []string) {
172+
func (m *Model) LineDown(n int) {
185173
if m.AtBottom() || n == 0 || len(m.lines) == 0 {
186-
return nil
174+
return
187175
}
188176

189177
// Make sure the number of lines by which we're going to scroll isn't
190178
// greater than the number of lines we actually have left before we reach
191179
// the bottom.
192180
m.SetYOffset(m.YOffset + n)
193-
194-
// Gather lines to send off for performance scrolling.
195-
//
196-
// XXX: high performance rendering is deprecated in Bubble Tea.
197-
bottom := clamp(m.YOffset+m.Height, 0, len(m.lines))
198-
top := clamp(m.YOffset+m.Height-n, 0, bottom)
199-
return m.lines[top:bottom]
200181
}
201182

202183
// LineUp moves the view down by the given number of lines. Returns the new
@@ -244,52 +225,6 @@ func (m *Model) GotoBottom() (lines []string) {
244225
return m.visibleLines()
245226
}
246227

247-
// Sync tells the renderer where the viewport will be located and requests
248-
// a render of the current state of the viewport. It should be called for the
249-
// first render and after a window resize.
250-
//
251-
// For high performance rendering only.
252-
//
253-
// Deprecated: high performance rendering is deprecated in Bubble Tea.
254-
func Sync(m Model) tea.Cmd {
255-
if len(m.lines) == 0 {
256-
return nil
257-
}
258-
top, bottom := m.scrollArea()
259-
return tea.SyncScrollArea(m.visibleLines(), top, bottom)
260-
}
261-
262-
// ViewDown is a high performance command that moves the viewport up by a given
263-
// number of lines. Use Model.ViewDown to get the lines that should be rendered.
264-
// For example:
265-
//
266-
// lines := model.ViewDown(1)
267-
// cmd := ViewDown(m, lines)
268-
func ViewDown(m Model, lines []string) tea.Cmd {
269-
if len(lines) == 0 {
270-
return nil
271-
}
272-
top, bottom := m.scrollArea()
273-
274-
// XXX: high performance rendering is deprecated in Bubble Tea. In a v2 we
275-
// won't need to return a command here.
276-
return tea.ScrollDown(lines, top, bottom)
277-
}
278-
279-
// ViewUp is a high performance command the moves the viewport down by a given
280-
// number of lines height. Use Model.ViewUp to get the lines that should be
281-
// rendered.
282-
func ViewUp(m Model, lines []string) tea.Cmd {
283-
if len(lines) == 0 {
284-
return nil
285-
}
286-
top, bottom := m.scrollArea()
287-
288-
// XXX: high performance rendering is deprecated in Bubble Tea. In a v2 we
289-
// won't need to return a command here.
290-
return tea.ScrollUp(lines, top, bottom)
291-
}
292-
293228
// Update handles standard message-based viewport updates.
294229
func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) {
295230
var cmd tea.Cmd
@@ -304,46 +239,26 @@ func (m Model) updateAsModel(msg tea.Msg) (Model, tea.Cmd) {
304239
m.setInitialValues()
305240
}
306241

307-
var cmd tea.Cmd
308-
309242
switch msg := msg.(type) {
310243
case tea.KeyPressMsg:
311244
switch {
312245
case key.Matches(msg, m.KeyMap.PageDown):
313-
lines := m.ViewDown()
314-
if m.HighPerformanceRendering {
315-
cmd = ViewDown(m, lines)
316-
}
246+
m.ViewDown()
317247

318248
case key.Matches(msg, m.KeyMap.PageUp):
319-
lines := m.ViewUp()
320-
if m.HighPerformanceRendering {
321-
cmd = ViewUp(m, lines)
322-
}
249+
m.ViewUp()
323250

324251
case key.Matches(msg, m.KeyMap.HalfPageDown):
325-
lines := m.HalfViewDown()
326-
if m.HighPerformanceRendering {
327-
cmd = ViewDown(m, lines)
328-
}
252+
m.HalfViewDown()
329253

330254
case key.Matches(msg, m.KeyMap.HalfPageUp):
331-
lines := m.HalfViewUp()
332-
if m.HighPerformanceRendering {
333-
cmd = ViewUp(m, lines)
334-
}
255+
m.HalfViewUp()
335256

336257
case key.Matches(msg, m.KeyMap.Down):
337-
lines := m.LineDown(1)
338-
if m.HighPerformanceRendering {
339-
cmd = ViewDown(m, lines)
340-
}
258+
m.LineDown(1)
341259

342260
case key.Matches(msg, m.KeyMap.Up):
343-
lines := m.LineUp(1)
344-
if m.HighPerformanceRendering {
345-
cmd = ViewUp(m, lines)
346-
}
261+
m.LineUp(1)
347262
}
348263

349264
case tea.MouseWheelMsg:
@@ -353,32 +268,18 @@ func (m Model) updateAsModel(msg tea.Msg) (Model, tea.Cmd) {
353268

354269
switch msg.Button {
355270
case tea.MouseWheelDown:
356-
lines := m.LineDown(m.MouseWheelDelta)
357-
if m.HighPerformanceRendering {
358-
cmd = ViewDown(m, lines)
359-
}
271+
m.LineDown(m.MouseWheelDelta)
360272

361273
case tea.MouseWheelUp:
362-
lines := m.LineUp(m.MouseWheelDelta)
363-
if m.HighPerformanceRendering {
364-
cmd = ViewUp(m, lines)
365-
}
274+
m.LineUp(m.MouseWheelDelta)
366275
}
367276
}
368277

369-
return m, cmd
278+
return m, nil
370279
}
371280

372281
// View renders the viewport into a string.
373282
func (m Model) View() string {
374-
if m.HighPerformanceRendering {
375-
// Just send newlines since we're going to be rendering the actual
376-
// content separately. We still need to send something that equals the
377-
// height of this view so that the Bubble Tea standard renderer can
378-
// position anything below this view properly.
379-
return strings.Repeat("\n", max(0, m.Height-1))
380-
}
381-
382283
w, h := m.Width, m.Height
383284
if sw := m.Style.GetWidth(); sw != 0 {
384285
w = min(w, sw)

0 commit comments

Comments
 (0)