Skip to content
Myr

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

4 files+64 added−19 removed

modified:key.go+40 added-5 removed
5 unmodified lines
6 "io"7 "unicode/utf8"8)910// 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// }29type KeyMsg Key3031// String returns a friendly name for a key.32//33// k := KeyType{Type: KeyEnter}34// fmt.Println(k)35// // Output: enter36func (k *KeyMsg) String() (str string) {37 if k.Alt {38 str += "alt+"39 }
6 unmodified lines
46 }47 return ""48}4928// IsRune returns weather or not the key is a rune.50// IsRune returns whether or not the key is a rune.51func (k *KeyMsg) IsRune() bool {52 return k.Type == KeyRune53}54
3 unmodified lines
58 Rune rune59 Alt bool60}6140// 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// }76type KeyType int7778// 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 lines
116 keySP = 32 // space117 keyDEL = 127 // delete. on most systems this is mapped to backspace, I hear118)11985// Aliases120// Control key aliases:121const (122 KeyNull = keyNUL123 KeyBreak = keyETX124 KeyEnter = keyCR
38 unmodified lines
163 KeyCtrlUnderscore = keyUS // ctrl+_164 KeyCtrlQuestionMark = keyDEL // ctrl+?165)166132// Other keys we track167// Other keys:168const (169 KeyRune = -(iota + 1)170 KeyUp171 KeyDown
149 unmodified lines
modified:logging.go+1 added-1 removed
3 unmodified lines
4 "log"5 "os"6)78// 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 lines
modified:renderer.go+9 added-8 removed
324 unmodified lines
325 topBoundary int326 bottomBoundary int327}328329// 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.334func SyncScrollArea(lines []string, topBoundary int, bottomBoundary int) Cmd {335 return func() Msg {
20 unmodified lines
356 topBoundary int357 bottomBoundary int358}359360// 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.365func ScrollUp(newLines []string, topBoundary, bottomBoundary int) Cmd {366 return func() Msg {
10 unmodified lines
377 topBoundary int378 bottomBoundary int379}380380// 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.386func ScrollDown(newLines []string, topBoundary, bottomBoundary int) Cmd {387 return func() Msg {
7 unmodified lines
modified: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/examples9package tea1011import (12 "fmt"
53 unmodified lines
66 renderer *renderer67 altScreenActive bool68}6962// 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.71func Quit() Msg {72 return quitMsg{}73}74
126 unmodified lines
201 }202 }203}204197// 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.207func (p *Program) EnterAltScreen() {208 p.mtx.Lock()209 defer p.mtx.Unlock()210 fmt.Fprintf(p.output, te.CSI+te.AltScreenSeq)
16 unmodified lines
227 p.renderer.altScreenActive = p.altScreenActive228 }229}230222// 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.233func (p *Program) EnableMouseCellMotion() {234 p.mtx.Lock()235 defer p.mtx.Unlock()236 fmt.Fprintf(p.output, te.CSI+te.EnableMouseCellMotionSeq)237}238230// 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!242func (p *Program) DisableMouseCellMotion() {243 p.mtx.Lock()
21 unmodified lines