Improve GoDocs
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 a784aa3 · Browse files · 4 files·+64 added−19 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
4 files+64 added−19 removed
- other:+64 added−19 removed
Provenance
- Commit
c0f67a2- Tree
fd4f16b- Author
Christian Rocha <christian@rocha.is>- Committer
Christian Rocha <christian@rocha.is>- Parent
a784aa3
4 files changed+64 added−19 removed
modified:key.go+40 added-5 removed
5 unmodified lines6 "io"7 "unicode/utf8"8 )9 10-// KeyMsg contains information about a keypress.10+// KeyMsg contains information about a keypress. KeyMsgs are always sent to11+// the program's update function. There are a couple general patterns you could12+// use to check for keypresses:13+//14+// switch msg := msg.(type) {15+// case KeyMsg:16+// switch msg.Type {17+// case KeyEnter:18+// fmt.Println("you pressed enter!")19+// }20+// }21+//22+// switch msg := msg.(type) {23+// case KeyMsg:24+// switch msg.String() {25+// case "enter":26+// fmt.Println("you pressed enter!")27+// }28+// }29 type KeyMsg Key30 31 // String returns a friendly name for a key.32+//33+// k := KeyType{Type: KeyEnter}34+// fmt.Println(k)35+// // Output: enter36 func (k *KeyMsg) String() (str string) {37 if k.Alt {38 str += "alt+"39 }6 unmodified lines46 }47 return ""48 }49 28-// IsRune returns weather or not the key is a rune.50+// IsRune returns whether or not the key is a rune.51 func (k *KeyMsg) IsRune() bool {52 return k.Type == KeyRune53 }54 3 unmodified lines58 Rune rune59 Alt bool60 }61 40-// KeyType indicates the key pressed.62+// KeyType indicates the key pressed, such as KeyEnter or KeyBreak or63+// KeyCtrlC. All other keys will be type KeyRune. To get the rune value, check64+// the Rune method on a Key struct, or use the Key.String() method:65+//66+// k := Key{Type: KeyRune, Rune: 'a', Alt: true}67+// if k.Type == KeyRune {68+//69+// fmt.Println(k.Rune)70+// // Output: a71+//72+// fmt.Println(k.String())73+// // Output: alt+a74+//75+// }76 type KeyType int77 78 // Control keys. I know we could do this with an iota, but the values are very79 // specific, so we set the values explicitly to avoid any confusion.36 unmodified lines116 keySP = 32 // space117 keyDEL = 127 // delete. on most systems this is mapped to backspace, I hear118 )119 85-// Aliases120+// Control key aliases:121 const (122 KeyNull = keyNUL123 KeyBreak = keyETX124 KeyEnter = keyCR38 unmodified lines163 KeyCtrlUnderscore = keyUS // ctrl+_164 KeyCtrlQuestionMark = keyDEL // ctrl+?165 )166 132-// Other keys we track167+// Other keys:168 const (169 KeyRune = -(iota + 1)170 KeyUp171 KeyDown149 unmodified linesmodified:logging.go+1 added-1 removed
3 unmodified lines4 "log"5 "os"6 )7 8-// LogToFile sets up default logging to log to a file This is helpful as we8+// LogToFile sets up default logging to log to a file. This is helpful as we9 // can't print to the terminal since our TUI is occupying it. If the file10 // doesn't exist it will be created.11 //12 // Don't forget to close the file when you're done with it.15 unmodified linesmodified:renderer.go+9 added-8 removed
324 unmodified lines325 topBoundary int326 bottomBoundary int327 }328 329-// SyncScrollArea performs a paint of the entire scroll area. This is required330-// to initialize the scrollable region and should also be called on resize331-// (WindowSizeMsg).329+// SyncScrollArea performs a paint of the entire region designated to be the330+// scrollable area. This is required to initialize the scrollable region and331+// should also be called on resize (WindowSizeMsg).332 //333 // For high-performance, scroll-based rendering only.334 func SyncScrollArea(lines []string, topBoundary int, bottomBoundary int) Cmd {335 return func() Msg {20 unmodified lines356 topBoundary int357 bottomBoundary int358 }359 360-// ScrollUp adds lines to the top of the scrollable region, pushing lines below361-// down. Lines that are pushed out the scrollable region disappear from view.360+// ScrollUp adds lines to the top of the scrollable region, pushing existing361+// lines below down. Lines that are pushed out the scrollable region disappear362+// from view.363 //364 // For high-performance, scroll-based rendering only.365 func ScrollUp(newLines []string, topBoundary, bottomBoundary int) Cmd {366 return func() Msg {10 unmodified lines377 topBoundary int378 bottomBoundary int379 }380 380-// ScrollDown adds lines to the bottom of the scrollable region, pushing lines381-// above up. Lines that are pushed out of the scrollable region disappear from382-// view.381+// ScrollDown adds lines to the bottom of the scrollable region, pushing382+// existing lines above up. Lines that are pushed out of the scrollable region383+// disappear from view.384 //385 // For high-performance, scroll-based rendering only.386 func ScrollDown(newLines []string, topBoundary, bottomBoundary int) Cmd {387 return func() Msg {7 unmodified linesmodified:tea.go+14 added-5 removed
1+// Package tea provides an Elm-inspired framework for building rich terminal2+// user interfaces. It's well-suited for simple and complex terminal3+// applications, either inline, full-window, or a mix of both. It's been4+// battle-tested in several large projects and is production-ready.5+//6+// A tutorial is available at https://github.com/charmbracelet/bubbletea/tree/master/tutorials7+//8+// Example programs can be found at https://github.com/charmbracelet/bubbletea/tree/master/examples9 package tea10 11 import (12 "fmt"53 unmodified lines66 renderer *renderer67 altScreenActive bool68 }69 62-// Quit is a special command that tells the program to exit.70+// Quit is a special command that tells the Bubble Tea program to exit.71 func Quit() Msg {72 return quitMsg{}73 }74 126 unmodified lines201 }202 }203 }204 197-// EnterAltScreen enters the alternate screen buffer.205+// EnterAltScreen enters the alternate screen buffer, which consumes the entire206+// terminal window. ExitAltScreen will return the terminal to its former state.207 func (p *Program) EnterAltScreen() {208 p.mtx.Lock()209 defer p.mtx.Unlock()210 fmt.Fprintf(p.output, te.CSI+te.AltScreenSeq)16 unmodified lines227 p.renderer.altScreenActive = p.altScreenActive228 }229 }230 222-// EnableMouseCellMotion enables mouse click, release, wheel and motion events if a223-// button is pressed.231+// EnableMouseCellMotion enables mouse click, release, wheel and motion events232+// if a button is pressed.233 func (p *Program) EnableMouseCellMotion() {234 p.mtx.Lock()235 defer p.mtx.Unlock()236 fmt.Fprintf(p.output, te.CSI+te.EnableMouseCellMotionSeq)237 }238 230-// DisableMouseCellMotino disables Mouse Cell Motion tracking. If you've239+// DisableMouseCellMotion disables Mouse Cell Motion tracking. If you've240 // enabled Cell Motion mouse trakcing be sure to call this as your program is241 // exiting or your users will be very upset!242 func (p *Program) DisableMouseCellMotion() {243 p.mtx.Lock()21 unmodified lines