From 0957c58e0553b0921c1e5a2bb9314e2b3bf069e6 Mon Sep 17 00:00:00 2001 From: Christian Muehlhaeuser Date: Mon, 25 May 2020 14:02:46 +0200 Subject: [PATCH] Make type documentation godoc-compliant --- boba.go | 22 +++++++++++----------- key.go | 12 ++++++------ paginator/paginator.go | 12 ++++++------ spinner/spinner.go | 6 +++--- textinput/textinput.go | 30 +++++++++++++++--------------- viewport/viewport.go | 14 +++++++------- 6 files changed, 48 insertions(+), 48 deletions(-) diff --git a/boba.go b/boba.go index ee03f2e..a01bc96 100644 --- a/boba.go +++ b/boba.go @@ -31,17 +31,17 @@ func Batch(cmds ...Cmd) Cmd { } // Init is the first function that will be called. It returns your initial -// model and runs an optional command +// model and runs an optional command. type Init func() (Model, Cmd) // Update is called when a message is received. It may update the model and/or // send a command. type Update func(Msg, Model) (Model, Cmd) -// View produces a string which will be rendered to the terminal +// View produces a string which will be rendered to the terminal. type View func(Model) string -// Program is a terminal user interface +// Program is a terminal user interface. type Program struct { init Init update Update @@ -50,18 +50,18 @@ type Program struct { mutex sync.Mutex } -// Quit is a command that tells the program to exit +// Quit is a command that tells the program to exit. func Quit() Msg { return quitMsg{} } -// Signals that the program should quit +// Signals that the program should quit. type quitMsg struct{} -// batchMsg is used to perform a bunch of commands +// batchMsg is used to perform a bunch of commands. type batchMsg []Cmd -// NewProgram creates a new Program +// NewProgram creates a new Program. func NewProgram(init Init, update Update, view View) *Program { return &Program{ init: init, @@ -72,7 +72,7 @@ func NewProgram(init Init, update Update, view View) *Program { } } -// Start initializes the program +// Start initializes the program. func (p *Program) Start() error { var ( model Model @@ -164,7 +164,7 @@ func (p *Program) render(model Model, linesRendered int) int { p.mutex.Lock() // We need to add carriage returns to ensure that the cursor travels to the - // start of a column after a newline + // start of a column after a newline. view = strings.Replace(view, "\n", "\r\n", -1) if linesRendered > 0 { @@ -177,13 +177,13 @@ func (p *Program) render(model Model, linesRendered int) int { } // AltScreen exits the altscreen. This is just a wrapper around the termenv -// function +// function. func AltScreen() { termenv.AltScreen() } // ExitAltScreen exits the altscreen. This is just a wrapper around the termenv -// function +// function. func ExitAltScreen() { termenv.ExitAltScreen() } diff --git a/key.go b/key.go index eff9e95..d7f2458 100644 --- a/key.go +++ b/key.go @@ -7,10 +7,10 @@ import ( "unicode/utf8" ) -// KeyPressMsg contains information about a keypress +// KeyMsg contains information about a keypress. type KeyMsg Key -// String returns a friendly name for a key +// String returns a friendly name for a key. func (k *KeyMsg) String() (str string) { if k.Alt { str += "alt+" @@ -25,19 +25,19 @@ func (k *KeyMsg) String() (str string) { return "" } -// IsRune returns weather or not the key is a rune +// IsRune returns weather or not the key is a rune. func (k *KeyMsg) IsRune() bool { return k.Type == KeyRune } -// Key contains information about a keypress +// Key contains information about a keypress. type Key struct { Type KeyType Rune rune Alt bool } -// KeyType indicates the key pressed +// KeyType indicates the key pressed. type KeyType int // Control keys. I know we could do this with an iota, but the values are very @@ -228,7 +228,7 @@ var hexes = map[string]Key{ } // ReadKey reads keypress input from a TTY and returns a string representation -// of a key +// of a key. func ReadKey(r io.Reader) (Key, error) { var buf [256]byte diff --git a/paginator/paginator.go b/paginator/paginator.go index 85dd266..d1f8dc7 100644 --- a/paginator/paginator.go +++ b/paginator/paginator.go @@ -10,7 +10,7 @@ import ( "github.com/charmbracelet/boba" ) -// Type specifies the way we render pagination +// Type specifies the way we render pagination. type Type int // Pagination rendering options @@ -19,7 +19,7 @@ const ( Dots ) -// Model is the Boba model for this user interface +// Model is the Boba model for this user interface. type Model struct { Type Type Page int @@ -87,7 +87,7 @@ func (m *Model) NextPage() { } } -// LastPage returns whether or not we're on the last page +// LastPage returns whether or not we're on the last page. func (m Model) OnLastPage() bool { if m.Page == m.TotalPages-1 { return true @@ -95,7 +95,7 @@ func (m Model) OnLastPage() bool { return false } -// NewModel creates a new model with defaults +// NewModel creates a new model with defaults. func NewModel() Model { return Model{ Type: Arabic, @@ -112,7 +112,7 @@ func NewModel() Model { } } -// Update is the Boba update function which binds keystrokes to pagination +// Update is the Boba update function which binds keystrokes to pagination. func Update(msg boba.Msg, m Model) (Model, boba.Cmd) { switch msg := msg.(type) { case boba.KeyMsg: @@ -153,7 +153,7 @@ func Update(msg boba.Msg, m Model) (Model, boba.Cmd) { return m, nil } -// View renders the pagination to a string +// View renders the pagination to a string. func View(model boba.Model) string { m, ok := model.(Model) if !ok { diff --git a/spinner/spinner.go b/spinner/spinner.go index 7a5008d..1b75d07 100644 --- a/spinner/spinner.go +++ b/spinner/spinner.go @@ -57,7 +57,7 @@ type Model struct { frame int } -// NewModel returns a model with default values +// NewModel returns a model with default values. func NewModel() Model { return Model{ Type: Line, @@ -65,7 +65,7 @@ func NewModel() Model { } } -// TickMsg indicates that the timer has ticked and we should render a frame +// TickMsg indicates that the timer has ticked and we should render a frame. type TickMsg struct{} // Update is the Boba update function. This will advance the spinner one frame @@ -82,7 +82,7 @@ func Update(msg boba.Msg, m Model) (Model, boba.Cmd) { return m, Tick(m) } -// View renders the model's view +// View renders the model's view. func View(model Model) string { s := spinners[model.Type] if model.frame >= len(s) { diff --git a/textinput/textinput.go b/textinput/textinput.go index 624c7ba..a0a5674 100644 --- a/textinput/textinput.go +++ b/textinput/textinput.go @@ -18,7 +18,7 @@ var ( // this text input. type ErrMsg error -// Model is the Boba model for this text input element +// Model is the Boba model for this text input element. type Model struct { Err error Prompt string @@ -57,7 +57,7 @@ type Model struct { offset int } -// SetValue sets the value of the text input +// SetValue sets the value of the text input. func (m *Model) SetValue(s string) { if m.CharLimit > 0 && len(s) > m.CharLimit { m.value = s[:m.CharLimit] @@ -70,7 +70,7 @@ func (m *Model) SetValue(s string) { m.handleOverflow() } -// Value returns the value of the text input +// Value returns the value of the text input. func (m Model) Value() string { return m.value } @@ -82,30 +82,30 @@ func (m *Model) SetCursor(pos int) { m.handleOverflow() } -// CursorStart moves the cursor to the start of the field +// CursorStart moves the cursor to the start of the field. func (m *Model) CursorStart() { m.pos = 0 m.handleOverflow() } -// CursorEnd moves the cursor to the end of the field +// CursorEnd moves the cursor to the end of the field. func (m *Model) CursorEnd() { m.pos = len(m.value) m.handleOverflow() } -// Focused returns the focus state on the model +// Focused returns the focus state on the model. func (m Model) Focused() bool { return m.focus } -// Focus sets the focus state on the model +// Focus sets the focus state on the model. func (m *Model) Focus() { m.focus = true m.blink = false } -// Blur removes the focus state on the model +// Blur removes the focus state on the model. func (m *Model) Blur() { m.focus = false m.blink = true @@ -134,7 +134,7 @@ func (m *Model) handleOverflow() { } // colorText colorizes a given string according to the TextColor value of the -// model +// model. func (m *Model) colorText(s string) string { return termenv. String(s). @@ -144,7 +144,7 @@ func (m *Model) colorText(s string) string { } // colorPlaceholder colorizes a given string according to the TextColor value -// of the model +// of the model. func (m *Model) colorPlaceholder(s string) string { return termenv. String(s). @@ -153,10 +153,10 @@ func (m *Model) colorPlaceholder(s string) string { String() } -// BlinkMsg is sent when the cursor should alternate it's blinking state +// BlinkMsg is sent when the cursor should alternate it's blinking state. type BlinkMsg struct{} -// NewModel creates a new model with default settings +// NewModel creates a new model with default settings. func NewModel() Model { return Model{ Prompt: "> ", @@ -174,7 +174,7 @@ func NewModel() Model { } } -// Update is the Boba update loop +// Update is the Boba update loop. func Update(msg boba.Msg, m Model) (Model, boba.Cmd) { if !m.focus { m.blink = true @@ -239,7 +239,7 @@ func Update(msg boba.Msg, m Model) (Model, boba.Cmd) { return m, nil } -// View renders the textinput in its current state +// View renders the textinput in its current state. func View(model boba.Model) string { m, ok := model.(Model) if !ok { @@ -309,7 +309,7 @@ func placeholderView(m Model) string { return m.Prompt + v } -// cursorView styles the cursor +// cursorView styles the cursor. func cursorView(s string, m Model) string { if m.blink { if m.TextColor != "" || m.BackgroundColor != "" { diff --git a/viewport/viewport.go b/viewport/viewport.go index 56a3d68..72b93c3 100644 --- a/viewport/viewport.go +++ b/viewport/viewport.go @@ -17,7 +17,7 @@ type Model struct { lines []string } -// Scrollpercent returns the amount scrolled as a float between 0 and 1 +// Scrollpercent returns the amount scrolled as a float between 0 and 1. func (m Model) ScrollPercent() float64 { if m.Height >= len(m.lines) { return 1.0 @@ -28,7 +28,7 @@ func (m Model) ScrollPercent() float64 { return y / (t - h) } -// SetContent set the pager's text content +// SetContent set the pager's text content. func (m *Model) SetContent(s string) { s = strings.Replace(s, "\r\n", "\n", -1) // normalize line endings m.lines = strings.Split(s, "\n") @@ -43,22 +43,22 @@ func NewModel(width, height int) Model { } // ViewDown moves the view down by the number of lines in the viewport. -// Basically, "page down." +// Basically, "page down". func (m *Model) ViewDown() { m.Y = min(len(m.lines)-m.Height, m.Y+m.Height) } -// ViewUp moves the view up by one height of the viewport. Basically, "page up." +// ViewUp moves the view up by one height of the viewport. Basically, "page up". func (m *Model) ViewUp() { m.Y = max(0, m.Y-m.Height) } -// HalfViewUp moves the view up by half the height of the viewport +// HalfViewUp moves the view up by half the height of the viewport. func (m *Model) HalfViewUp() { m.Y = max(0, m.Y-m.Height/2) } -// HalfViewDown moves the view down by half the height of the viewport +// HalfViewDown moves the view down by half the height of the viewport. func (m *Model) HalfViewDown() { m.Y = min(len(m.lines)-m.Height, m.Y+m.Height/2) } @@ -131,7 +131,7 @@ func Update(msg boba.Msg, m Model) (Model, boba.Cmd) { // VIEW -// View renders the viewport into a string +// View renders the viewport into a string. func View(m Model) string { if m.Err != nil { return m.Err.Error()