Skip to content
Myr

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

6 files+48 added−48 removed

modified:paginator/paginator.go+6 added-6 removed
8 unmodified lines
910 "github.com/charmbracelet/boba"11)1213// Type specifies the way we render pagination13// Type specifies the way we render pagination.14type Type int1516// Pagination rendering options17const (18 Arabic Type = iota19 Dots20)2122// Model is the Boba model for this user interface22// Model is the Boba model for this user interface.23type Model struct {24 Type Type25 Page int26 PerPage int
59 unmodified lines
86 m.Page++87 }88}8990// LastPage returns whether or not we're on the last page90// LastPage returns whether or not we're on the last page.91func (m Model) OnLastPage() bool {92 if m.Page == m.TotalPages-1 {93 return true94 }95 return false96}9798// NewModel creates a new model with defaults98// NewModel creates a new model with defaults.99func NewModel() Model {100 return Model{101 Type: Arabic,102 Page: 0,
8 unmodified lines
111 UseJKKeys: false,112 }113}114115// Update is the Boba update function which binds keystrokes to pagination115// Update is the Boba update function which binds keystrokes to pagination.116func Update(msg boba.Msg, m Model) (Model, boba.Cmd) {117 switch msg := msg.(type) {118 case boba.KeyMsg:119 if m.UseLeftRightKeys {
32 unmodified lines
152153 return m, nil154}155156// View renders the pagination to a string156// View renders the pagination to a string.157func View(model boba.Model) string {158 m, ok := model.(Model)159 if !ok {160 return "could not perform assertion on model"
31 unmodified lines
modified:spinner/spinner.go+3 added-3 removed
55 unmodified lines
5657 frame int58}5960// NewModel returns a model with default values60// NewModel returns a model with default values.61func NewModel() Model {62 return Model{63 Type: Line,64 FPS: 9,65 }66}6768// 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.69type TickMsg struct{}7071// 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 logic
8 unmodified lines
81 }82 return m, Tick(m)83}8485// View renders the model's view85// View renders the model's view.86func View(model Model) string {87 s := spinners[model.Type]88 if model.frame >= len(s) {89 return "[error]"
25 unmodified lines
modified:textinput/textinput.go+15 added-15 removed
16 unmodified lines
17// package; we're expecting errors to be handle in the program that implements18// this text input.19type ErrMsg error2021// Model is the Boba model for this text input element21// Model is the Boba model for this text input element.22type Model struct {23 Err error24 Prompt string25 Cursor string
30 unmodified lines
56 // overflowing57 offset int58}5960// SetValue sets the value of the text input60// SetValue sets the value of the text input.61func (m *Model) SetValue(s string) {62 if m.CharLimit > 0 && len(s) > m.CharLimit {63 m.value = s[:m.CharLimit]64 } else {
4 unmodified lines
69 }70 m.handleOverflow()71}7273// Value returns the value of the text input73// Value returns the value of the text input.74func (m Model) Value() string {75 return m.value76}77
3 unmodified lines
81 m.pos = max(0, min(len(m.value), pos))82 m.handleOverflow()83}8485// CursorStart moves the cursor to the start of the field85// CursorStart moves the cursor to the start of the field.86func (m *Model) CursorStart() {87 m.pos = 088 m.handleOverflow()89}9091// CursorEnd moves the cursor to the end of the field91// CursorEnd moves the cursor to the end of the field.92func (m *Model) CursorEnd() {93 m.pos = len(m.value)94 m.handleOverflow()95}9697// Focused returns the focus state on the model97// Focused returns the focus state on the model.98func (m Model) Focused() bool {99 return m.focus100}101102// Focus sets the focus state on the model102// Focus sets the focus state on the model.103func (m *Model) Focus() {104 m.focus = true105 m.blink = false106}107108// Blur removes the focus state on the model108// Blur removes the focus state on the model.109func (m *Model) Blur() {110 m.focus = false111 m.blink = true112}
20 unmodified lines
133 }134}135136// colorText colorizes a given string according to the TextColor value of the137// model137// model.138func (m *Model) colorText(s string) string {139 return termenv.140 String(s).141 Foreground(color(m.TextColor)).
1 unmodified line
143 String()144}145146// colorPlaceholder colorizes a given string according to the TextColor value147// of the model147// of the model.148func (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}155156// BlinkMsg is sent when the cursor should alternate it's blinking state156// BlinkMsg is sent when the cursor should alternate it's blinking state.157type BlinkMsg struct{}158159// NewModel creates a new model with default settings159// NewModel creates a new model with default settings.160func NewModel() Model {161 return Model{162 Prompt: "> ",163 BlinkSpeed: time.Millisecond * 600,
9 unmodified lines
173 pos: 0,174 }175}176177// Update is the Boba update loop177// Update is the Boba update loop.178func Update(msg boba.Msg, m Model) (Model, boba.Cmd) {179 if !m.focus {180 m.blink = true181 return m, nil
56 unmodified lines
238239 return m, nil240}241242// View renders the textinput in its current state242// View renders the textinput in its current state.243func View(model boba.Model) string {244 m, ok := model.(Model)245 if !ok {246 return "could not perform assertion on model"
61 unmodified lines
308309 return m.Prompt + v310}311312// cursorView styles the cursor312// cursorView styles the cursor.313func cursorView(s string, m Model) string {314 if m.blink {315 if m.TextColor != "" || m.BackgroundColor != "" {316 return termenv.String(s).
34 unmodified lines
modified:viewport/viewport.go+7 added-7 removed
15 unmodified lines
1617 lines []string18}1920// Scrollpercent returns the amount scrolled as a float between 0 and 120// Scrollpercent returns the amount scrolled as a float between 0 and 1.21func (m Model) ScrollPercent() float64 {22 if m.Height >= len(m.lines) {23 return 1.024 }
2 unmodified lines
27 t := float64(len(m.lines))28 return y / (t - h)29}3031// SetContent set the pager's text content31// SetContent set the pager's text content.32func (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 lines
42 }43}4445// ViewDown moves the view down by the number of lines in the viewport.46// Basically, "page down."46// Basically, "page down".47func (m *Model) ViewDown() {48 m.Y = min(len(m.lines)-m.Height, m.Y+m.Height)49}5051// 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".52func (m *Model) ViewUp() {53 m.Y = max(0, m.Y-m.Height)54}5556// HalfViewUp moves the view up by half the height of the viewport56// HalfViewUp moves the view up by half the height of the viewport.57func (m *Model) HalfViewUp() {58 m.Y = max(0, m.Y-m.Height/2)59}6061// HalfViewDown moves the view down by half the height of the viewport61// HalfViewDown moves the view down by half the height of the viewport.62func (m *Model) HalfViewDown() {63 m.Y = min(len(m.lines)-m.Height, m.Y+m.Height/2)64}65
64 unmodified lines
130}131132// VIEW133134// View renders the viewport into a string134// View renders the viewport into a string.135func View(m Model) string {136 if m.Err != nil {137 return m.Err.Error()138 }
33 unmodified lines
modified:boba.go+11 added-11 removed
29 unmodified lines
30 }31}3233// 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.35type Init func() (Model, Cmd)3637// Update is called when a message is received. It may update the model and/or38// send a command.39type Update func(Msg, Model) (Model, Cmd)4041// View produces a string which will be rendered to the terminal41// View produces a string which will be rendered to the terminal.42type View func(Model) string4344// Program is a terminal user interface44// Program is a terminal user interface.45type Program struct {46 init Init47 update Update48 view View4950 mutex sync.Mutex51}5253// Quit is a command that tells the program to exit53// Quit is a command that tells the program to exit.54func Quit() Msg {55 return quitMsg{}56}5758// Signals that the program should quit58// Signals that the program should quit.59type quitMsg struct{}6061// batchMsg is used to perform a bunch of commands61// batchMsg is used to perform a bunch of commands.62type batchMsg []Cmd6364// NewProgram creates a new Program64// NewProgram creates a new Program.65func NewProgram(init Init, update Update, view View) *Program {66 return &Program{67 init: init,68 update: update,
2 unmodified lines
71 mutex: sync.Mutex{},72 }73}7475// Start initializes the program75// Start initializes the program.76func (p *Program) Start() error {77 var (78 model Model79 cmd Cmd
83 unmodified lines
163164 p.mutex.Lock()165166 // 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)169170 if linesRendered > 0 {171 termenv.ClearLines(linesRendered)
4 unmodified lines
176 return strings.Count(view, "\r\n")177}178179// AltScreen exits the altscreen. This is just a wrapper around the termenv180// function180// function.181func AltScreen() {182 termenv.AltScreen()183}184185// ExitAltScreen exits the altscreen. This is just a wrapper around the termenv186// function186// function.187func ExitAltScreen() {188 termenv.ExitAltScreen()189}
modified:key.go+6 added-6 removed
5 unmodified lines
6 "io"7 "unicode/utf8"8)910// KeyPressMsg contains information about a keypress10// KeyMsg contains information about a keypress.11type KeyMsg Key1213// String returns a friendly name for a key13// String returns a friendly name for a key.14func (k *KeyMsg) String() (str string) {15 if k.Alt {16 str += "alt+"17 }
6 unmodified lines
24 }25 return ""26}2728// IsRune returns weather or not the key is a rune28// IsRune returns weather or not the key is a rune.29func (k *KeyMsg) IsRune() bool {30 return k.Type == KeyRune31}3233// Key contains information about a keypress33// Key contains information about a keypress.34type Key struct {35 Type KeyType36 Rune rune37 Alt bool38}3940// KeyType indicates the key pressed40// KeyType indicates the key pressed.41type KeyType int4243// 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 lines
227 "1b5b313b3344": Key{Type: KeyLeft, Alt: true},228}229230// ReadKey reads keypress input from a TTY and returns a string representation231// of a key231// of a key.232func ReadKey(r io.Reader) (Key, error) {233 var buf [256]byte234235 // Read and block
43 unmodified lines