Skip to content
Myr

Remove extraneous select{} and improve comments

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Christian Rocha · committed by Christian Rocha · parent 466d16b · Browse files · 2 files+13 added−12 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+13 added−12 removed

  • other:+13 added−12 removed

2 files+13 added−12 removed

modified:key.go+1 added-1 removed
13 unmodified lines
14 keyETX = 3 // break, ctrl+c15 keyLF = 9 // line-feed, \n16 keyCR = 13 // carriage return, \r17 keyESC = 2718 keyUS = 3118 keyUS = 31 // unit separator19)2021var controlNames = map[int]string{22 keyETX: "ctrl+c",
45 unmodified lines
modified:tea.go+12 added-11 removed
12 unmodified lines
1314// Msg represents an action. It's used by Update to update the UI.15type Msg interface{}1617// Model contains the data for an application17// Model contains the updatable data for an application18type Model interface{}1920// Cmd is an IO operation. If it's nil it's considered a no-op.21type Cmd func() Msg2223// Sub is an event subscription. If it's nil it's considered a no-op. But why24// would you subscribe to nil?23// Sub is an event subscription. If it returns nil it's considered a no-op.24type Sub func(Model) Msg2526// Update is called when a message is received. It may update the model and/or27// send a command.
10 unmodified lines
38 subscriptions []Sub39 rw io.ReadWriter40}4143// Quit command42// Quit is a command that tells the program to exit43func Quit() Msg {44 return quitMsg{}45}46
42 unmodified lines
89 // here, since it blocks nicely and user input will probably be something90 // users typically need?91 go func() {92 for {94 select {95 default:96 msg, _ := ReadKey(p.rw)97 msgs <- KeyPressMsg(msg)93 msg, _ := ReadKey(p.rw)94 msgs <- KeyPressMsg(msg)98 }95 }96 }()97102 // Process subscriptions98 // Initialize subscriptions99 go func() {100 if len(p.subscriptions) > 0 {101 for _, sub := range p.subscriptions {102 go func(s Sub) {
37 unmodified lines
140 }141 }142}143148// Render a view144// Render a view to the terminal145func (p *Program) render(model Model, init bool) {146 view := p.view(model)147148 // We need to add carriage returns to ensure that the cursor travels to the
5 unmodified lines
154 }155 io.WriteString(p.rw, view)156}157158// Hide the cursor159func hideCursor() {160 fmt.Printf(esc + "?25l")161}162163// Show the cursor164func showCursor() {165 fmt.Printf(esc + "?25h")166}167168// Move the cursor up a given number of lines169func cursorUp(n int) {170 fmt.Printf(esc+"%dF", n)171}172173// Clear the current line174func clearLine() {175 fmt.Printf(esc + "2K")176}177178// Clear a given number of lines179func clearLines(n int) {180 for i := 0; i < n; i++ {181 cursorUp(1)182 clearLine()
7 unmodified lines