@@ -42,18 +42,6 @@ type Model struct {
42
42
// useful for setting borders, margins and padding.
43
43
Style lipgloss.Style
44
44
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
-
57
45
initialized bool
58
46
lines []string
59
47
}
@@ -126,96 +114,70 @@ func (m Model) visibleLines() (lines []string) {
126
114
return lines
127
115
}
128
116
129
- // scrollArea returns the scrollable boundaries for high performance rendering.
130
- //
131
- // XXX: high performance rendering is deprecated in Bubble Tea.
132
- func (m Model ) scrollArea () (top , bottom int ) {
133
- top = max (0 , m .YPosition )
134
- bottom = max (top , top + m .Height )
135
- if top > 0 && bottom > top {
136
- bottom --
137
- }
138
- return top , bottom
139
- }
140
-
141
117
// SetYOffset sets the Y offset.
142
118
func (m * Model ) SetYOffset (n int ) {
143
119
m .YOffset = clamp (n , 0 , m .maxYOffset ())
144
120
}
145
121
146
122
// ViewDown moves the view down by the number of lines in the viewport.
147
123
// Basically, "page down".
148
- func (m * Model ) ViewDown () [] string {
124
+ func (m * Model ) ViewDown () {
149
125
if m .AtBottom () {
150
- return nil
126
+ return
151
127
}
152
128
153
- return m .LineDown (m .Height )
129
+ m .LineDown (m .Height )
154
130
}
155
131
156
132
// ViewUp moves the view up by one height of the viewport. Basically, "page up".
157
- func (m * Model ) ViewUp () [] string {
133
+ func (m * Model ) ViewUp () {
158
134
if m .AtTop () {
159
- return nil
135
+ return
160
136
}
161
137
162
- return m .LineUp (m .Height )
138
+ m .LineUp (m .Height )
163
139
}
164
140
165
141
// HalfViewDown moves the view down by half the height of the viewport.
166
- func (m * Model ) HalfViewDown () ( lines [] string ) {
142
+ func (m * Model ) HalfViewDown () {
167
143
if m .AtBottom () {
168
- return nil
144
+ return
169
145
}
170
146
171
- return m .LineDown (m .Height / 2 )
147
+ m .LineDown (m .Height / 2 )
172
148
}
173
149
174
150
// HalfViewUp moves the view up by half the height of the viewport.
175
- func (m * Model ) HalfViewUp () ( lines [] string ) {
151
+ func (m * Model ) HalfViewUp () {
176
152
if m .AtTop () {
177
- return nil
153
+ return
178
154
}
179
155
180
- return m .LineUp (m .Height / 2 )
156
+ m .LineUp (m .Height / 2 )
181
157
}
182
158
183
159
// LineDown moves the view down by the given number of lines.
184
- func (m * Model ) LineDown (n int ) ( lines [] string ) {
160
+ func (m * Model ) LineDown (n int ) {
185
161
if m .AtBottom () || n == 0 || len (m .lines ) == 0 {
186
- return nil
162
+ return
187
163
}
188
164
189
165
// Make sure the number of lines by which we're going to scroll isn't
190
166
// greater than the number of lines we actually have left before we reach
191
167
// the bottom.
192
168
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 ]
200
169
}
201
170
202
171
// LineUp moves the view down by the given number of lines. Returns the new
203
172
// lines to show.
204
- func (m * Model ) LineUp (n int ) ( lines [] string ) {
173
+ func (m * Model ) LineUp (n int ) {
205
174
if m .AtTop () || n == 0 || len (m .lines ) == 0 {
206
- return nil
175
+ return
207
176
}
208
177
209
178
// Make sure the number of lines by which we're going to scroll isn't
210
179
// greater than the number of lines we are from the top.
211
180
m .SetYOffset (m .YOffset - n )
212
-
213
- // Gather lines to send off for performance scrolling.
214
- //
215
- // XXX: high performance rendering is deprecated in Bubble Tea.
216
- top := max (0 , m .YOffset )
217
- bottom := clamp (m .YOffset + n , 0 , m .maxYOffset ())
218
- return m .lines [top :bottom ]
219
181
}
220
182
221
183
// TotalLineCount returns the total number of lines (both hidden and visible) within the viewport.
@@ -244,106 +206,39 @@ func (m *Model) GotoBottom() (lines []string) {
244
206
return m .visibleLines ()
245
207
}
246
208
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
-
293
209
// Update handles standard message-based viewport updates.
294
210
func (m Model ) Update (msg tea.Msg ) (Model , tea.Cmd ) {
295
- var cmd tea.Cmd
296
- m , cmd = m .updateAsModel (msg )
297
- return m , cmd
211
+ m = m .updateAsModel (msg )
212
+ return m , nil
298
213
}
299
214
300
215
// Author's note: this method has been broken out to make it easier to
301
216
// potentially transition Update to satisfy tea.Model.
302
- func (m Model ) updateAsModel (msg tea.Msg ) ( Model , tea. Cmd ) {
217
+ func (m Model ) updateAsModel (msg tea.Msg ) Model {
303
218
if ! m .initialized {
304
219
m .setInitialValues ()
305
220
}
306
221
307
- var cmd tea.Cmd
308
-
309
222
switch msg := msg .(type ) {
310
223
case tea.KeyPressMsg :
311
224
switch {
312
225
case key .Matches (msg , m .KeyMap .PageDown ):
313
- lines := m .ViewDown ()
314
- if m .HighPerformanceRendering {
315
- cmd = ViewDown (m , lines )
316
- }
226
+ m .ViewDown ()
317
227
318
228
case key .Matches (msg , m .KeyMap .PageUp ):
319
- lines := m .ViewUp ()
320
- if m .HighPerformanceRendering {
321
- cmd = ViewUp (m , lines )
322
- }
229
+ m .ViewUp ()
323
230
324
231
case key .Matches (msg , m .KeyMap .HalfPageDown ):
325
- lines := m .HalfViewDown ()
326
- if m .HighPerformanceRendering {
327
- cmd = ViewDown (m , lines )
328
- }
232
+ m .HalfViewDown ()
329
233
330
234
case key .Matches (msg , m .KeyMap .HalfPageUp ):
331
- lines := m .HalfViewUp ()
332
- if m .HighPerformanceRendering {
333
- cmd = ViewUp (m , lines )
334
- }
235
+ m .HalfViewUp ()
335
236
336
237
case key .Matches (msg , m .KeyMap .Down ):
337
- lines := m .LineDown (1 )
338
- if m .HighPerformanceRendering {
339
- cmd = ViewDown (m , lines )
340
- }
238
+ m .LineDown (1 )
341
239
342
240
case key .Matches (msg , m .KeyMap .Up ):
343
- lines := m .LineUp (1 )
344
- if m .HighPerformanceRendering {
345
- cmd = ViewUp (m , lines )
346
- }
241
+ m .LineUp (1 )
347
242
}
348
243
349
244
case tea.MouseWheelMsg :
@@ -353,32 +248,18 @@ func (m Model) updateAsModel(msg tea.Msg) (Model, tea.Cmd) {
353
248
354
249
switch msg .Button {
355
250
case tea .MouseWheelDown :
356
- lines := m .LineDown (m .MouseWheelDelta )
357
- if m .HighPerformanceRendering {
358
- cmd = ViewDown (m , lines )
359
- }
251
+ m .LineDown (m .MouseWheelDelta )
360
252
361
253
case tea .MouseWheelUp :
362
- lines := m .LineUp (m .MouseWheelDelta )
363
- if m .HighPerformanceRendering {
364
- cmd = ViewUp (m , lines )
365
- }
254
+ m .LineUp (m .MouseWheelDelta )
366
255
}
367
256
}
368
257
369
- return m , cmd
258
+ return m
370
259
}
371
260
372
261
// View renders the viewport into a string.
373
262
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
-
382
263
w , h := m .Width , m .Height
383
264
if sw := m .Style .GetWidth (); sw != 0 {
384
265
w = min (w , sw )
0 commit comments