Skip to content

Commit

Permalink
fix: initialize Program fields in init method
Browse files Browse the repository at this point in the history
  • Loading branch information
aymanbagabas committed Dec 12, 2024
1 parent ee1a613 commit 215d776
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions tea.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,12 +275,7 @@ func Interrupt() Msg {

// NewProgram creates a new Program.
func NewProgram[T any](model Model[T], opts ...ProgramOption[T]) *Program[T] {
p := &Program[T]{
msgs: make(chan Msg),
rendererDone: make(chan struct{}),
modes: make(map[ansi.DECMode]bool),
exp: experimentalOptions{},
}
p := &Program[T]{}

p.Init = model.Init
p.Update = func(t T, msg Msg) (T, Cmd) {
Expand All @@ -297,6 +292,15 @@ func NewProgram[T any](model Model[T], opts ...ProgramOption[T]) *Program[T] {
opt(p)
}

return p
}

func (p *Program[T]) init() {
p.msgs = make(chan Msg)
p.rendererDone = make(chan struct{})
p.modes = make(map[ansi.DECMode]bool)
p.exp = experimentalOptions{}

// A context can be provided with a ProgramOption, but if none was provided
// we'll use the default background context.
if p.ctx == nil {
Expand Down Expand Up @@ -344,8 +348,6 @@ func NewProgram[T any](model Model[T], opts ...ProgramOption[T]) *Program[T] {
if exp := p.getenv("TEA_EXPERIMENTAL"); exp != "" {
p.exp = strings.Split(exp, ",")
}

return p
}

func (p *Program[T]) handleSignals() chan struct{} {
Expand Down Expand Up @@ -686,6 +688,8 @@ func (p *Program[T]) Run() error {
}

func (p *Program[T]) Start() error {

Check failure on line 690 in tea.go

View workflow job for this annotation

GitHub Actions / lint / lint (ubuntu-latest)

exported: exported method Program.Start should have comment or be unexported (revive)
p.init()

p.handlers = channelHandlers{}
cmds := make(chan Cmd)
p.errs = make(chan error)
Expand Down

0 comments on commit 215d776

Please sign in to comment.