Skip to content

Commit

Permalink
feat: add experimental features (#1183)
Browse files Browse the repository at this point in the history
Right now, we only have one experimental feature to use the new cell buffer as a default renderer.
Use `TEA_EXPERIMENTAL=cellbuf` environment variable to enable the use of the cell buffer as the default renderer.
  • Loading branch information
aymanbagabas authored Oct 11, 2024
1 parent 7f3bb8e commit 24a8f0e
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
21 changes: 21 additions & 0 deletions options.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,3 +268,24 @@ func WithoutGraphemeClustering() ProgramOption {
p.startupOptions |= withoutGraphemeClustering
}
}

// experimentalOptions are experimental features that are not yet stable. These
// features may change or be removed in future versions.
type experimentalOptions []string

// has returns true if the experimental option is enabled.
func (e experimentalOptions) has(option string) bool {
for _, o := range e {
if o == option {
return true
}
}
return false
}

const (
// experimentalCellbuf is an experimental feature that enables a cell buffer
// for the renderer. This can be useful for rendering performance and
// efficiency.
experimentalCellbuf = "cellbuf"
)
18 changes: 16 additions & 2 deletions tea.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"runtime"
"runtime/debug"
"strconv"
"strings"
"sync"
"sync/atomic"
"syscall"
Expand Down Expand Up @@ -212,6 +213,9 @@ type Program struct {

// tracer is used to trace the program's output and input.
tracer tracer

// exp stores program experimental features.
exp experimentalOptions
}

// Quit is a special command that tells the Bubble Tea program to exit.
Expand Down Expand Up @@ -246,6 +250,7 @@ func NewProgram(model Model, opts ...ProgramOption) *Program {
msgs: make(chan Msg),
rendererDone: make(chan struct{}),
modes: make(map[string]bool),
exp: experimentalOptions{},
}

// Apply all options to the program.
Expand Down Expand Up @@ -298,6 +303,12 @@ func NewProgram(model Model, opts ...ProgramOption) *Program {
p.output.trace = true
}

// Experimental features. Right now, we only have one experimental feature
// to use the new cell buffer as a default renderer.
if exp := p.getenv("TEA_EXPERIMENTAL"); exp != "" {
p.exp = strings.Split(exp, ",")
}

return p
}

Expand Down Expand Up @@ -683,8 +694,11 @@ func (p *Program) Run() (Model, error) {
var output io.Writer
output = p.output
if p.renderer == nil {
// p.renderer = newStandardRenderer()
p.renderer = newCellRenderer()
if p.exp.has(experimentalCellbuf) {
p.renderer = newCellRenderer()
} else {
p.renderer = newStandardRenderer()
}
}

// Set the renderer output.
Expand Down

0 comments on commit 24a8f0e

Please sign in to comment.