Skip to content

Commit

Permalink
fix: tidy and error on missing functions
Browse files Browse the repository at this point in the history
  • Loading branch information
aymanbagabas committed Jan 29, 2025
1 parent 46f89ce commit 8f62296
Showing 1 changed file with 19 additions and 15 deletions.
34 changes: 19 additions & 15 deletions tea.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ import (
"log"
"os"
"os/signal"
"path/filepath"
"runtime"
"runtime/debug"
"strconv"
"strings"
"sync"
"sync/atomic"
"syscall"
Expand Down Expand Up @@ -282,6 +284,8 @@ func (p *Program[T]) init() {
p.rendererDone = make(chan struct{})
p.keyboardc = make(chan struct{})
p.modes = ansi.Modes{}
p.handlers = channelHandlers{}
p.errs = make(chan error, 1)

// Initialize context and teardown channel.
p.ctx, p.cancel = context.WithCancel(context.Background())
Expand All @@ -291,6 +295,10 @@ func (p *Program[T]) init() {
p.Output = os.Stdout
}

if p.Input == nil {
p.Input = os.Stdin
}

// if no environment was set, set it to os.Environ()
if p.Env == nil {
p.Env = os.Environ()
Expand Down Expand Up @@ -686,16 +694,7 @@ func (p *Program[T]) eventLoop(cmds chan Cmd) {
var cmd Cmd
p.Model, cmd = p.Update(p.Model, msg) // run update
cmds <- cmd // process command (if any)

view := p.View(p.Model)
switch view := view.(type) {
case Frame:
// Ensure we reset the cursor color on exit.
if view.Cursor != nil {
p.setCc = view.Cursor.Color
}
}

p.renderer.render(view) //nolint:errcheck // send view to renderer
}
}
Expand All @@ -718,14 +717,18 @@ func (p *Program[T]) Run() error {
func (p *Program[T]) Start() error {
p.init()

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

if p.Input == nil {
p.Input = os.Stdin
if p.Init == nil {
return errors.New("no Init function set")
}
if p.Update == nil {
return errors.New("no Update function set")
}
if p.View == nil {
return errors.New("no View function set")
}

cmds := make(chan Cmd)

// The user has not set a custom input, so we need to check whether or
// not standard input is a terminal. If it's not, we open a new TTY for
// input. This will allow things to "just work" in cases where data was
Expand Down Expand Up @@ -803,6 +806,7 @@ func (p *Program[T]) Start() error {
p.modes.Reset(ansi.TextCursorEnableMode)
p.renderer.hideCursor()

// Always enable bracketed paste mode.
p.execute(ansi.SetBracketedPasteMode)
p.modes.Set(ansi.BracketedPasteMode)

Expand Down

0 comments on commit 8f62296

Please sign in to comment.