Skip to content

Commit

Permalink
chore: rename option WithMaxFPS to simply WithFPS
Browse files Browse the repository at this point in the history
  • Loading branch information
meowgorithm committed May 11, 2023
1 parent c2bb5bb commit 91b03ea
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 20 deletions.
13 changes: 5 additions & 8 deletions options.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package tea
import (
"context"
"io"
"time"

"github.com/muesli/termenv"
)
Expand Down Expand Up @@ -202,13 +201,11 @@ func WithFilter(filter func(Model, Msg) Msg) ProgramOption {
}
}

// WithMaxFPS sets a custom maximum FPS at which we should
// update the view.
func WithMaxFPS(fps uint) ProgramOption {
if fps > maxFPS {
fps = maxFPS
}
// WithMaxFPS sets a custom maximum FPS at which the renderer should run. If
// less than 1, the default value of 60 will be used. If over 120, the FPS
// will be capped at 120.
func WithFPS(fps int) ProgramOption {
return func(p *Program) {
p.framerate = time.Second / time.Duration(fps)
p.fps = fps
}
}
15 changes: 8 additions & 7 deletions standard_renderer.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@ import (
const (
// defaultFramerate specifies the maximum interval at which we should
// update the view.
defaultFramerate = time.Second / 60

maxFPS = 120
defaultFPS = 60
maxFPS = 120
)

// standardRenderer is a framerate-based terminal renderer, updating the view
Expand Down Expand Up @@ -56,15 +55,17 @@ type standardRenderer struct {

// newRenderer creates a new renderer. Normally you'll want to initialize it
// with os.Stdout as the first argument.
func newRenderer(out *termenv.Output, useANSICompressor bool, framerate time.Duration) renderer {
if framerate == 0 {
framerate = defaultFramerate
func newRenderer(out *termenv.Output, useANSICompressor bool, fps int) renderer {
if fps < 1 {
fps = defaultFPS
} else if fps > maxFPS {
fps = maxFPS
}
r := &standardRenderer{
out: out,
mtx: &sync.Mutex{},
done: make(chan struct{}),
framerate: framerate,
framerate: time.Second / time.Duration(fps),
useANSICompressor: useANSICompressor,
queuedMessageLines: []string{},
}
Expand Down
9 changes: 4 additions & 5 deletions tea.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"runtime/debug"
"sync"
"syscall"
"time"

"github.com/containerd/console"
isatty "github.com/mattn/go-isatty"
Expand Down Expand Up @@ -146,9 +145,9 @@ type Program struct {

filter func(Model, Msg) Msg

// framerate specifies a custom maximum interval at which we should
// update the view. If it is 0, the default value is used.
framerate time.Duration
// fps is the frames per second we should set on the renderer, if
// applicable,
fps int
}

// Quit is a special command that tells the Bubble Tea program to exit.
Expand Down Expand Up @@ -446,7 +445,7 @@ func (p *Program) Run() (Model, error) {

// If no renderer is set use the standard one.
if p.renderer == nil {
p.renderer = newRenderer(p.output, p.startupOptions.has(withANSICompressor), p.framerate)
p.renderer = newRenderer(p.output, p.startupOptions.has(withANSICompressor), p.fps)
}

// Check if output is a TTY before entering raw mode, hiding the cursor and
Expand Down

0 comments on commit 91b03ea

Please sign in to comment.