Skip to content

Commit

Permalink
Tidy up comments
Browse files Browse the repository at this point in the history
  • Loading branch information
meowgorithm committed Sep 28, 2021
1 parent 860f623 commit 0e7cd09
Showing 1 changed file with 25 additions and 24 deletions.
49 changes: 25 additions & 24 deletions tea.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ import (
"golang.org/x/term"
)

// Msg represents an action and is usually the result of an IO operation. It
// triggers the Update function, and henceforth, the UI.
// Msg contain data from the result of a IO operation. Msgs trigger the update
// function and, henceforth, the UI.
type Msg interface{}

// Model contains the program's state as well as it's core functions.
// Model contains the program's state as well as its core functions.
type Model interface {
// Init is the first function that will be called. It returns an optional
// initial command. To not perform an initial command return nil.
Expand All @@ -46,12 +46,13 @@ type Model interface {
View() string
}

// Cmd is an IO operation. If it's nil it's considered a no-op. Use it for
// things like HTTP requests, timers, saving and loading from disk, and so on.
// Cmd is an IO operation that returns a message when it's complete. If it's
// nil it's considered a no-op. Use it for things like HTTP requests, timers,
// saving and loading from disk, and so on.
//
// There's almost never a need to use a command to send a message to another
// part of your program. Instead, it can almost always be done in the update
// function.
// Note that there's almost never a reason to use a command to send a message
// to another part of your program. That can almost always be done in the
// update function.
type Cmd func() Msg

// Options to customize the program during its initialization. These are
Expand Down Expand Up @@ -139,7 +140,7 @@ func Quit() Msg {
type quitMsg struct{}

// EnterAltScreen is a special command that tells the Bubble Tea program to
// enter alternate screen buffer.
// enter the alternate screen buffer.
//
// Because commands run asynchronously, this command should not be used in your
// model's Init function. To initialize your program with the altscreen enabled
Expand Down Expand Up @@ -240,7 +241,7 @@ func NewProgram(model Model, opts ...ProgramOption) *Program {
CatchPanics: true,
}

// Apply all options to program
// Apply all options to the program.
for _, opt := range opts {
opt(p)
}
Expand All @@ -257,7 +258,7 @@ func (p *Program) Start() error {
errs = make(chan error)
)

// channels for managing goroutine lifecycles
// Channels for managing goroutine lifecycles.
var (
readLoopDone = make(chan struct{})
sigintLoopDone = make(chan struct{})
Expand All @@ -270,9 +271,9 @@ func (p *Program) Start() error {
select {
case <-readLoopDone:
case <-time.After(500 * time.Millisecond):
// the read loop hangs, which means the input cancelReader's
// cancel function has returned true even though it was not
// able to cancel the read
// The read loop hangs, which means the input
// cancelReader's cancel function has returned true even
// though it was not able to cancel the read.
}
}
<-cmdLoopDone
Expand Down Expand Up @@ -372,7 +373,7 @@ func (p *Program) Start() error {
p.EnableMouseAllMotion()
}

// Initialize program
// Initialize the program.
model := p.initialModel
if initCmd := model.Init(); initCmd != nil {
go func() {
Expand All @@ -386,11 +387,11 @@ func (p *Program) Start() error {
close(initSignalDone)
}

// Start renderer
// Start the renderer.
p.renderer.start()
p.renderer.setAltScreen(p.altScreenActive)

// Render initial view
// Render the initial view.
p.renderer.write(model.View())

cancelReader, err := newCancelReader(p.input)
Expand All @@ -400,7 +401,7 @@ func (p *Program) Start() error {

defer cancelReader.Close() // nolint:errcheck

// Subscribe to user input
// Subscribe to user input.
if p.input != nil {
go func() {
defer close(readLoopDone)
Expand All @@ -427,7 +428,7 @@ func (p *Program) Start() error {
}

if f, ok := p.output.(*os.File); ok {
// Get initial terminal size and send it to the program
// Get the initial terminal size and send it to the program.
go func() {
w, h, err := term.GetSize(int(f.Fd()))
if err != nil {
Expand All @@ -440,13 +441,13 @@ func (p *Program) Start() error {
}
}()

// Listen for window resizes
// Listen for window resizes.
go listenForResize(ctx, f, p.msgs, errs, resizeLoopDone)
} else {
close(resizeLoopDone)
}

// Process commands
// Process commands.
go func() {
defer close(cmdLoopDone)

Expand Down Expand Up @@ -475,7 +476,7 @@ func (p *Program) Start() error {
}
}()

// Handle updates and draw
// Handle updates and draw.
for {
select {
case err := <-errs:
Expand All @@ -486,7 +487,7 @@ func (p *Program) Start() error {
return err
case msg := <-p.msgs:

// Handle special internal messages
// Handle special internal messages.
switch msg := msg.(type) {
case quitMsg:
cancelContext()
Expand Down Expand Up @@ -523,7 +524,7 @@ func (p *Program) Start() error {
hideCursor(p.output)
}

// Process internal messages for the renderer
// Process internal messages for the renderer.
if r, ok := p.renderer.(*standardRenderer); ok {
r.handleMessages(msg)
}
Expand Down

0 comments on commit 0e7cd09

Please sign in to comment.