Skip to content

Commit

Permalink
feat: make the ferocious renderer opt-in
Browse files Browse the repository at this point in the history
The ferocious renderer is now opt-in. This commit adds a new option
`WithFerociousRenderer` that enables the ferocious renderer.
  • Loading branch information
aymanbagabas committed Nov 12, 2024
1 parent 29a3c0d commit 3c0961f
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 17 deletions.
3 changes: 0 additions & 3 deletions examples/simple/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,6 @@ func TestApp(t *testing.T) {
}

func TestAppInteractive(t *testing.T) {
// TODO: Enable this test again
t.Skip("update this test to recognize the new renderer.")

m := model(10)
tm := teatest.NewTestModel(
t, m,
Expand Down
15 changes: 10 additions & 5 deletions options.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,8 @@ func (e experimentalOptions) has(option string) bool {
}

const (
// Unferocious disables the "ferocious" renderer.
experimentalUnferocious = "unferocious"
// Ferocious enables the "ferocious" renderer.
experimentalFerocious = "ferocious"
)

// WithColorProfile sets the color profile that the program will use. This is
Expand All @@ -302,9 +302,14 @@ func WithColorProfile(profile colorprofile.Profile) ProgramOption {
}
}

// withStandardRenderer tells Bubble Tea to use the standrad renderer.
func withStandardRenderer() ProgramOption { //nolint:unused
// WithFerociousRenderer tells Bubble Tea to use the new shiny "ferocious"
// renderer. This renderer is experimental and may change or be removed in
// future versions.
//
// The ferocious renderer is a new renderer that is faster and more efficient
// than the default renderer. It is also more ferocious ;)

Check failure on line 310 in options.go

View workflow job for this annotation

GitHub Actions / lint / lint-soft (ubuntu-latest)

Comment should end in a period (godot)

Check failure on line 310 in options.go

View workflow job for this annotation

GitHub Actions / lint / lint-soft (ubuntu-latest)

Comment should end in a period (godot)

Check failure on line 310 in options.go

View workflow job for this annotation

GitHub Actions / lint / lint-soft (windows-latest)

Comment should end in a period (godot)

Check failure on line 310 in options.go

View workflow job for this annotation

GitHub Actions / lint / lint-soft (windows-latest)

Comment should end in a period (godot)

Check failure on line 310 in options.go

View workflow job for this annotation

GitHub Actions / lint / lint-soft (macos-latest)

Comment should end in a period (godot)

Check failure on line 310 in options.go

View workflow job for this annotation

GitHub Actions / lint / lint-soft (macos-latest)

Comment should end in a period (godot)
func WithFerociousRenderer() ProgramOption { //nolint:unused
return func(p *Program) {
p.startupOptions |= avecStandardRenderer
p.startupOptions |= withFerociousRenderer
}
}
6 changes: 1 addition & 5 deletions screen_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,7 @@ func TestClearMsg(t *testing.T) {
m := &testModel{}
p := NewProgram(m, WithInput(&in), WithOutput(&buf),
// Use ANSI256 to increase test coverage.
WithColorProfile(colorprofile.ANSI256),

// XXX: Use the standard renderer, for now. Ultiamtely we want
// to update the tests to use the Ferocious Renderer.
withStandardRenderer())
WithColorProfile(colorprofile.ANSI256))

test.cmds = append([]Cmd{func() Msg { return WindowSizeMsg{80, 24} }}, test.cmds...)
test.cmds = append(test.cmds, Quit)
Expand Down
8 changes: 4 additions & 4 deletions tea.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ const (
withKeyboardEnhancements
withGraphemeClustering

avecStandardRenderer
withFerociousRenderer
)

// channelHandlers manages the series of channels returned by various processes.
Expand Down Expand Up @@ -708,10 +708,10 @@ func (p *Program) Run() (Model, error) {
go p.Send(ColorProfileMsg{p.profile})
if p.renderer == nil {
// If no renderer is set use the ferocious one.
if p.startupOptions&avecStandardRenderer != 0 || p.exp.has(experimentalUnferocious) {
p.renderer = newStandardRenderer(p.profile)
} else {
if p.startupOptions&withFerociousRenderer != 0 || p.exp.has(experimentalFerocious) {
p.renderer = newFerociousRenderer(p.profile)
} else {
p.renderer = newStandardRenderer(p.profile)
}
}

Expand Down

0 comments on commit 3c0961f

Please sign in to comment.