Skip to content
Myr

(feat): Add option to set max FPS (#578)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

* (feat): add option for setting FPS on renderer

authored by tomfeigin · committed by GitHub · parent 44f17fa · Browse files · 3 files+23 added−4 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Trailers

  • Co-authored-by: Christian Rocha <christian@rocha.is>

Diff stats

3 files+23 added−4 removed

  • other:+23 added−4 removed

3 files+23 added−4 removed

modified:options.go+9 added
198 unmodified lines
199 return func(p *Program) {200 p.filter = filter201 }202}203204// WithMaxFPS sets a custom maximum FPS at which the renderer should run. If205// less than 1, the default value of 60 will be used. If over 120, the FPS206// will be capped at 120.207func WithFPS(fps int) ProgramOption {208 return func(p *Program) {209 p.fps = fps210 }211}
modified:standard_renderer.go+9 added-3 removed
14 unmodified lines
1516const (17 // defaultFramerate specifies the maximum interval at which we should18 // update the view.19 defaultFramerate = time.Second / 6019 defaultFPS = 6020 maxFPS = 12021)2223// standardRenderer is a framerate-based terminal renderer, updating the view24// at a given framerate to avoid overloading the terminal emulator.
29 unmodified lines
54}5556// newRenderer creates a new renderer. Normally you'll want to initialize it57// with os.Stdout as the first argument.57func newRenderer(out *termenv.Output, useANSICompressor bool) renderer {58func newRenderer(out *termenv.Output, useANSICompressor bool, fps int) renderer {59 if fps < 1 {60 fps = defaultFPS61 } else if fps > maxFPS {62 fps = maxFPS63 }64 r := &standardRenderer{65 out: out,66 mtx: &sync.Mutex{},67 done: make(chan struct{}),62 framerate: defaultFramerate,68 framerate: time.Second / time.Duration(fps),69 useANSICompressor: useANSICompressor,70 queuedMessageLines: []string{},71 }72 if r.useANSICompressor {
595 unmodified lines
modified:tea.go+5 added-1 removed
142 unmodified lines
143 // below.144 windowsStdin *os.File //nolint:golint,structcheck,unused145146 filter func(Model, Msg) Msg147148 // fps is the frames per second we should set on the renderer, if149 // applicable,150 fps int151}152153// Quit is a special command that tells the Bubble Tea program to exit.154func Quit() Msg {
293 unmodified lines
448 }449450 // If no renderer is set use the standard one.451 if p.renderer == nil {448 p.renderer = newRenderer(p.output, p.startupOptions.has(withANSICompressor))452 p.renderer = newRenderer(p.output, p.startupOptions.has(withANSICompressor), p.fps)453 }454455 // Check if output is a TTY before entering raw mode, hiding the cursor and456 // so on.
243 unmodified lines