Make type documentation godoc-compliant
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Christian Muehlhaeuser · committed by Christian Muehlhaeuser · parent bb19d42 · Browse files · 6 files·+48 added−48 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
6 files+48 added−48 removed
- other:+48 added−48 removed
Provenance
- Commit
0957c58- Tree
e4c6022- Author
Christian Muehlhaeuser <muesli@gmail.com>- Committer
Christian Muehlhaeuser <muesli@gmail.com>- Parent
bb19d42
6 files changed+48 added−48 removed
modified:paginator/paginator.go+6 added-6 removed
8 unmodified lines9 10 "github.com/charmbracelet/boba"11 )12 13-// Type specifies the way we render pagination13+// Type specifies the way we render pagination.14 type Type int15 16 // Pagination rendering options17 const (18 Arabic Type = iota19 Dots20 )21 22-// Model is the Boba model for this user interface22+// Model is the Boba model for this user interface.23 type Model struct {24 Type Type25 Page int26 PerPage int59 unmodified lines86 m.Page++87 }88 }89 90-// LastPage returns whether or not we're on the last page90+// LastPage returns whether or not we're on the last page.91 func (m Model) OnLastPage() bool {92 if m.Page == m.TotalPages-1 {93 return true94 }95 return false96 }97 98-// NewModel creates a new model with defaults98+// NewModel creates a new model with defaults.99 func NewModel() Model {100 return Model{101 Type: Arabic,102 Page: 0,8 unmodified lines111 UseJKKeys: false,112 }113 }114 115-// Update is the Boba update function which binds keystrokes to pagination115+// Update is the Boba update function which binds keystrokes to pagination.116 func Update(msg boba.Msg, m Model) (Model, boba.Cmd) {117 switch msg := msg.(type) {118 case boba.KeyMsg:119 if m.UseLeftRightKeys {32 unmodified lines152 153 return m, nil154 }155 156-// View renders the pagination to a string156+// View renders the pagination to a string.157 func View(model boba.Model) string {158 m, ok := model.(Model)159 if !ok {160 return "could not perform assertion on model"31 unmodified linesmodified:spinner/spinner.go+3 added-3 removed
55 unmodified lines56 57 frame int58 }59 60-// NewModel returns a model with default values60+// NewModel returns a model with default values.61 func NewModel() Model {62 return Model{63 Type: Line,64 FPS: 9,65 }66 }67 68-// TickMsg indicates that the timer has ticked and we should render a frame68+// TickMsg indicates that the timer has ticked and we should render a frame.69 type TickMsg struct{}70 71 // Update is the Boba update function. This will advance the spinner one frame72 // every time it's called, regardless the message passed, so be sure the logic8 unmodified lines81 }82 return m, Tick(m)83 }84 85-// View renders the model's view85+// View renders the model's view.86 func View(model Model) string {87 s := spinners[model.Type]88 if model.frame >= len(s) {89 return "[error]"25 unmodified linesmodified:textinput/textinput.go+15 added-15 removed
16 unmodified lines17 // package; we're expecting errors to be handle in the program that implements18 // this text input.19 type ErrMsg error20 21-// Model is the Boba model for this text input element21+// Model is the Boba model for this text input element.22 type Model struct {23 Err error24 Prompt string25 Cursor string30 unmodified lines56 // overflowing57 offset int58 }59 60-// SetValue sets the value of the text input60+// SetValue sets the value of the text input.61 func (m *Model) SetValue(s string) {62 if m.CharLimit > 0 && len(s) > m.CharLimit {63 m.value = s[:m.CharLimit]64 } else {4 unmodified lines69 }70 m.handleOverflow()71 }72 73-// Value returns the value of the text input73+// Value returns the value of the text input.74 func (m Model) Value() string {75 return m.value76 }77 3 unmodified lines81 m.pos = max(0, min(len(m.value), pos))82 m.handleOverflow()83 }84 85-// CursorStart moves the cursor to the start of the field85+// CursorStart moves the cursor to the start of the field.86 func (m *Model) CursorStart() {87 m.pos = 088 m.handleOverflow()89 }90 91-// CursorEnd moves the cursor to the end of the field91+// CursorEnd moves the cursor to the end of the field.92 func (m *Model) CursorEnd() {93 m.pos = len(m.value)94 m.handleOverflow()95 }96 97-// Focused returns the focus state on the model97+// Focused returns the focus state on the model.98 func (m Model) Focused() bool {99 return m.focus100 }101 102-// Focus sets the focus state on the model102+// Focus sets the focus state on the model.103 func (m *Model) Focus() {104 m.focus = true105 m.blink = false106 }107 108-// Blur removes the focus state on the model108+// Blur removes the focus state on the model.109 func (m *Model) Blur() {110 m.focus = false111 m.blink = true112 }20 unmodified lines133 }134 }135 136 // colorText colorizes a given string according to the TextColor value of the137-// model137+// model.138 func (m *Model) colorText(s string) string {139 return termenv.140 String(s).141 Foreground(color(m.TextColor)).1 unmodified line143 String()144 }145 146 // colorPlaceholder colorizes a given string according to the TextColor value147-// of the model147+// of the model.148 func (m *Model) colorPlaceholder(s string) string {149 return termenv.150 String(s).151 Foreground(color(m.PlaceholderColor)).152 Background(color(m.BackgroundColor)).153 String()154 }155 156-// BlinkMsg is sent when the cursor should alternate it's blinking state156+// BlinkMsg is sent when the cursor should alternate it's blinking state.157 type BlinkMsg struct{}158 159-// NewModel creates a new model with default settings159+// NewModel creates a new model with default settings.160 func NewModel() Model {161 return Model{162 Prompt: "> ",163 BlinkSpeed: time.Millisecond * 600,9 unmodified lines173 pos: 0,174 }175 }176 177-// Update is the Boba update loop177+// Update is the Boba update loop.178 func Update(msg boba.Msg, m Model) (Model, boba.Cmd) {179 if !m.focus {180 m.blink = true181 return m, nil56 unmodified lines238 239 return m, nil240 }241 242-// View renders the textinput in its current state242+// View renders the textinput in its current state.243 func View(model boba.Model) string {244 m, ok := model.(Model)245 if !ok {246 return "could not perform assertion on model"61 unmodified lines308 309 return m.Prompt + v310 }311 312-// cursorView styles the cursor312+// cursorView styles the cursor.313 func cursorView(s string, m Model) string {314 if m.blink {315 if m.TextColor != "" || m.BackgroundColor != "" {316 return termenv.String(s).34 unmodified linesmodified:viewport/viewport.go+7 added-7 removed
15 unmodified lines16 17 lines []string18 }19 20-// Scrollpercent returns the amount scrolled as a float between 0 and 120+// Scrollpercent returns the amount scrolled as a float between 0 and 1.21 func (m Model) ScrollPercent() float64 {22 if m.Height >= len(m.lines) {23 return 1.024 }2 unmodified lines27 t := float64(len(m.lines))28 return y / (t - h)29 }30 31-// SetContent set the pager's text content31+// SetContent set the pager's text content.32 func (m *Model) SetContent(s string) {33 s = strings.Replace(s, "\r\n", "\n", -1) // normalize line endings34 m.lines = strings.Split(s, "\n")35 }6 unmodified lines42 }43 }44 45 // ViewDown moves the view down by the number of lines in the viewport.46-// Basically, "page down."46+// Basically, "page down".47 func (m *Model) ViewDown() {48 m.Y = min(len(m.lines)-m.Height, m.Y+m.Height)49 }50 51-// ViewUp moves the view up by one height of the viewport. Basically, "page up."51+// ViewUp moves the view up by one height of the viewport. Basically, "page up".52 func (m *Model) ViewUp() {53 m.Y = max(0, m.Y-m.Height)54 }55 56-// HalfViewUp moves the view up by half the height of the viewport56+// HalfViewUp moves the view up by half the height of the viewport.57 func (m *Model) HalfViewUp() {58 m.Y = max(0, m.Y-m.Height/2)59 }60 61-// HalfViewDown moves the view down by half the height of the viewport61+// HalfViewDown moves the view down by half the height of the viewport.62 func (m *Model) HalfViewDown() {63 m.Y = min(len(m.lines)-m.Height, m.Y+m.Height/2)64 }65 64 unmodified lines130 }131 132 // VIEW133 134-// View renders the viewport into a string134+// View renders the viewport into a string.135 func View(m Model) string {136 if m.Err != nil {137 return m.Err.Error()138 }33 unmodified linesmodified:boba.go+11 added-11 removed
29 unmodified lines30 }31 }32 33 // Init is the first function that will be called. It returns your initial34-// model and runs an optional command34+// model and runs an optional command.35 type Init func() (Model, Cmd)36 37 // Update is called when a message is received. It may update the model and/or38 // send a command.39 type Update func(Msg, Model) (Model, Cmd)40 41-// View produces a string which will be rendered to the terminal41+// View produces a string which will be rendered to the terminal.42 type View func(Model) string43 44-// Program is a terminal user interface44+// Program is a terminal user interface.45 type Program struct {46 init Init47 update Update48 view View49 50 mutex sync.Mutex51 }52 53-// Quit is a command that tells the program to exit53+// Quit is a command that tells the program to exit.54 func Quit() Msg {55 return quitMsg{}56 }57 58-// Signals that the program should quit58+// Signals that the program should quit.59 type quitMsg struct{}60 61-// batchMsg is used to perform a bunch of commands61+// batchMsg is used to perform a bunch of commands.62 type batchMsg []Cmd63 64-// NewProgram creates a new Program64+// NewProgram creates a new Program.65 func NewProgram(init Init, update Update, view View) *Program {66 return &Program{67 init: init,68 update: update,2 unmodified lines71 mutex: sync.Mutex{},72 }73 }74 75-// Start initializes the program75+// Start initializes the program.76 func (p *Program) Start() error {77 var (78 model Model79 cmd Cmd83 unmodified lines163 164 p.mutex.Lock()165 166 // We need to add carriage returns to ensure that the cursor travels to the167- // start of a column after a newline167+ // start of a column after a newline.168 view = strings.Replace(view, "\n", "\r\n", -1)169 170 if linesRendered > 0 {171 termenv.ClearLines(linesRendered)4 unmodified lines176 return strings.Count(view, "\r\n")177 }178 179 // AltScreen exits the altscreen. This is just a wrapper around the termenv180-// function180+// function.181 func AltScreen() {182 termenv.AltScreen()183 }184 185 // ExitAltScreen exits the altscreen. This is just a wrapper around the termenv186-// function186+// function.187 func ExitAltScreen() {188 termenv.ExitAltScreen()189 }modified:key.go+6 added-6 removed
5 unmodified lines6 "io"7 "unicode/utf8"8 )9 10-// KeyPressMsg contains information about a keypress10+// KeyMsg contains information about a keypress.11 type KeyMsg Key12 13-// String returns a friendly name for a key13+// String returns a friendly name for a key.14 func (k *KeyMsg) String() (str string) {15 if k.Alt {16 str += "alt+"17 }6 unmodified lines24 }25 return ""26 }27 28-// IsRune returns weather or not the key is a rune28+// IsRune returns weather or not the key is a rune.29 func (k *KeyMsg) IsRune() bool {30 return k.Type == KeyRune31 }32 33-// Key contains information about a keypress33+// Key contains information about a keypress.34 type Key struct {35 Type KeyType36 Rune rune37 Alt bool38 }39 40-// KeyType indicates the key pressed40+// KeyType indicates the key pressed.41 type KeyType int42 43 // Control keys. I know we could do this with an iota, but the values are very44 // specific, so we set the values explicitly to avoid any confusion.182 unmodified lines227 "1b5b313b3344": Key{Type: KeyLeft, Alt: true},228 }229 230 // ReadKey reads keypress input from a TTY and returns a string representation231-// of a key231+// of a key.232 func ReadKey(r io.Reader) (Key, error) {233 var buf [256]byte234 235 // Read and block43 unmodified lines