Browse Source

Resolve lint warnings

tablepad
Trevor Slocum 1 year ago
parent
commit
89fa23ab00
  1. 4
      README.md
  2. 52
      dropdown.go
  3. 2
      form.go
  4. 21
      inputfield.go
  5. 35
      list.go
  6. 3
      table.go

4
README.md

@ -1,10 +1,8 @@
# cview
# cview - Terminal-based user interface toolkit
[![GoDoc](https://gitlab.com/tslocum/godoc-static/-/raw/master/badge.svg)](https://docs.rocketnine.space/gitlab.com/tslocum/cview)
[![CI status](https://gitlab.com/tslocum/cview/badges/master/pipeline.svg)](https://gitlab.com/tslocum/cview/commits/master)
[![Donate](https://img.shields.io/liberapay/receives/rocketnine.space.svg?logo=liberapay)](https://liberapay.com/rocketnine.space)
Terminal-based user interface toolkit
This package is a fork of [tview](https://github.com/rivo/tview).
See [FORK.md](https://gitlab.com/tslocum/cview/blob/master/FORK.md) for more information.

52
dropdown.go

@ -12,14 +12,20 @@ type DropDownOption struct {
text string // The text to be displayed in the drop-down.
selected func(index int, option *DropDownOption) // The (optional) callback for when this option was selected.
reference interface{} // An optional reference object.
sync.RWMutex
}
// NewDropDownOption returns a new option for a dropdown.
func NewDropDownOption(text string) *DropDownOption {
return &DropDownOption{text: text}
}
// GetText returns the text of this dropdown option.
func (d *DropDownOption) GetText() string {
d.RLock()
defer d.RUnlock()
return d.text
}
@ -37,6 +43,9 @@ func (d *DropDownOption) SetSelectedFunc(handler func(index int, option *DropDow
// GetReference returns the reference object of this dropdown option.
func (d *DropDownOption) GetReference() interface{} {
d.RLock()
defer d.RUnlock()
return d.reference
}
@ -46,18 +55,6 @@ func (d *DropDownOption) SetReference(reference interface{}) *DropDownOption {
return d
}
// SetChangedFunc sets a handler which is called when the user changes the
// drop-down's option. This handler will be called in addition and prior to
// an option's optional individual handler. The handler is provided with the
// selected option's index and the option itself. If "no option" was selected, these values
// are -1 and nil.
func (d *DropDown) SetChangedFunc(handler func(index int, option *DropDownOption)) *DropDown {
d.list.SetChangedFunc(func(index int, item *ListItem) {
handler(index, d.options[index])
})
return d
}
// DropDown implements a selection widget whose options become visible in a
// drop-down list when activated.
type DropDown struct {
@ -266,7 +263,7 @@ func (d *DropDown) GetLabel() string {
return d.label
}
// SetAttributes sets the given attributes on the drop down.
// SetAttributes sets the given attributes on the drop-down.
func (d *DropDown) SetAttributes(attributes ...FormItemAttribute) {
allAttributes := newFormItemAttributes()
for _, attribute := range attributes {
@ -354,7 +351,7 @@ func (d *DropDown) SetFieldTextColorFocused(color tcell.Color) *DropDown {
return d
}
// SetDropDownTextColor sets text color of the drop down list.
// SetDropDownTextColor sets text color of the drop-down list.
func (d *DropDown) SetDropDownTextColor(color tcell.Color) *DropDown {
d.Lock()
defer d.Unlock()
@ -363,7 +360,7 @@ func (d *DropDown) SetDropDownTextColor(color tcell.Color) *DropDown {
return d
}
// SetDropDownBackgroundColor sets the background color of the drop list.
// SetDropDownBackgroundColor sets the background color of the drop-down list.
func (d *DropDown) SetDropDownBackgroundColor(color tcell.Color) *DropDown {
d.Lock()
defer d.Unlock()
@ -372,7 +369,8 @@ func (d *DropDown) SetDropDownBackgroundColor(color tcell.Color) *DropDown {
return d
}
// The text color of the selected option in the drop down list.
// SetDropDownSelectedTextColor sets the text color of the selected option in
// the drop-down list.
func (d *DropDown) SetDropDownSelectedTextColor(color tcell.Color) *DropDown {
d.Lock()
defer d.Unlock()
@ -381,7 +379,8 @@ func (d *DropDown) SetDropDownSelectedTextColor(color tcell.Color) *DropDown {
return d
}
// The background color of the selected option in the drop down list.
// SetDropDownSelectedBackgroundColor sets the background color of the selected
// option in the drop-down list.
func (d *DropDown) SetDropDownSelectedBackgroundColor(color tcell.Color) *DropDown {
d.Lock()
defer d.Unlock()
@ -440,7 +439,7 @@ func (d *DropDown) getFieldWidth() int {
return fieldWidth
}
// AddOptions adds new selectable options to this drop-down.
// AddOptionsSimple adds new selectable options to this drop-down.
func (d *DropDown) AddOptionsSimple(options ...string) *DropDown {
optionsToAdd := make([]*DropDownOption, len(options))
for i, option := range options {
@ -493,7 +492,18 @@ func (d *DropDown) SetOptions(selected func(index int, option *DropDownOption),
return d
}
// SetSelectedFunc sets a handler which is called when the user changes the
// SetChangedFunc sets a handler which is called when the user changes the
// focused drop-down option. The handler is provided with the selected option's
// index and the option itself. If "no option" was selected, these values are
// -1 and nil.
func (d *DropDown) SetChangedFunc(handler func(index int, option *DropDownOption)) *DropDown {
d.list.SetChangedFunc(func(index int, item *ListItem) {
handler(index, d.options[index])
})
return d
}
// SetSelectedFunc sets a handler which is called when the user selects a
// drop-down's option. This handler will be called in addition and prior to
// an option's optional individual handler. The handler is provided with the
// selected option's index and the option itself. If "no option" was selected, these values
@ -628,12 +638,12 @@ func (d *DropDown) Draw(screen tcell.Screen) {
Print(screen, text, x, y, fieldWidth, AlignLeft, color)
}
// Draw drop down symbol
// Draw drop-down symbol
screen.SetContent(x+fieldWidth-2, y, d.dropDownSymbol, nil, new(tcell.Style).Foreground(fieldTextColor).Background(fieldBackgroundColor))
// Draw options list.
if hasFocus && d.open {
// We prefer to drop down but if there is no space, maybe drop up?
// We prefer to drop-down but if there is no space, maybe drop up?
lx := x
ly := y + 1
lheight := len(d.options)

2
form.go

@ -141,7 +141,7 @@ func WithFieldBackgroundColorFocused(color tcell.Color) FormItemAttribute {
})
}
// WithFieldBackgroundColorFocused creates a form item attribute promise with the given value to be set.
// WithFinishedFunc creates a form item attribute promise with the given value to be set.
// When applied, sets the handler function for when the user finished
// entering data into the item. The handler may receive events for the
// Enter key (we're done), the Escape key (cancel input), the Tab key (move to

21
inputfield.go

@ -268,7 +268,8 @@ func (i *InputField) SetFieldBackgroundColor(color tcell.Color) *InputField {
return i
}
// SetFieldBackgroundColorFocused sets the background color of the input area when focused.
// SetFieldBackgroundColorFocused sets the background color of the input area
// when focused.
func (i *InputField) SetFieldBackgroundColorFocused(color tcell.Color) *InputField {
i.Lock()
defer i.Unlock()
@ -304,7 +305,8 @@ func (i *InputField) SetPlaceholderTextColor(color tcell.Color) *InputField {
return i
}
// SetPlaceholderTextColorFocused sets the text color of placeholder text when focused.
// SetPlaceholderTextColorFocused sets the text color of placeholder text when
// focused.
func (i *InputField) SetPlaceholderTextColorFocused(color tcell.Color) *InputField {
i.placeholderTextColorFocused = color
return i
@ -319,7 +321,8 @@ func (i *InputField) SetAutocompleteListTextColor(color tcell.Color) *InputField
return i
}
// SetAutocompleteListBackgroundColor sets the background color of the autocomplete list.
// SetAutocompleteListBackgroundColor sets the background color of the
// autocomplete list.
func (i *InputField) SetAutocompleteListBackgroundColor(color tcell.Color) *InputField {
i.Lock()
defer i.Unlock()
@ -328,7 +331,8 @@ func (i *InputField) SetAutocompleteListBackgroundColor(color tcell.Color) *Inpu
return i
}
// SetAutocompleteListSelectedTextColor sets the text color of the selected ListItem.
// SetAutocompleteListSelectedTextColor sets the text color of the selected
// ListItem.
func (i *InputField) SetAutocompleteListSelectedTextColor(color tcell.Color) *InputField {
i.Lock()
defer i.Unlock()
@ -337,7 +341,8 @@ func (i *InputField) SetAutocompleteListSelectedTextColor(color tcell.Color) *In
return i
}
// SetAutocompleteListSelectedBackgroundColor sets the background of the selected ListItem.
// SetAutocompleteListSelectedBackgroundColor sets the background of the
// selected ListItem.
func (i *InputField) SetAutocompleteListSelectedBackgroundColor(color tcell.Color) *InputField {
i.Lock()
defer i.Unlock()
@ -346,7 +351,8 @@ func (i *InputField) SetAutocompleteListSelectedBackgroundColor(color tcell.Colo
return i
}
// SetAutocompleteSuggestionColor sets the text color of the autocomplete suggestion in the input field.
// SetAutocompleteSuggestionTextColor sets the text color of the autocomplete
// suggestion in the input field.
func (i *InputField) SetAutocompleteSuggestionTextColor(color tcell.Color) *InputField {
i.autocompleteSuggestionTextColor = color
return i
@ -360,7 +366,8 @@ func (i *InputField) SetFieldNoteTextColor(color tcell.Color) *InputField {
return i
}
// SetFieldNote sets the text to show below the input field, e.g. when the input is invalid.
// SetFieldNote sets the text to show below the input field, e.g. when the
// input is invalid.
func (i *InputField) SetFieldNote(note string) *InputField {
i.Lock()
defer i.Unlock()

35
list.go

@ -16,9 +16,11 @@ type ListItem struct {
shortcut rune // The key to select the list item directly, 0 if there is no shortcut.
selected func() // The optional function which is called when the item is selected.
reference interface{} // An optional reference object.
sync.RWMutex
}
// NewListItem returns a new item for the list.
// NewListItem returns a new item for a list.
func NewListItem(mainText string) *ListItem {
return &ListItem{
mainText: mainText,
@ -28,51 +30,78 @@ func NewListItem(mainText string) *ListItem {
// SetMainText sets the main text of the list item.
func (l *ListItem) SetMainText(val string) *ListItem {
l.Lock()
defer l.Unlock()
l.mainText = val
return l
}
// GetMainText returns the item's main text.
func (l *ListItem) GetMainText() string {
l.RLock()
defer l.RUnlock()
return l.mainText
}
// SetSecondaryText sets a secondary text to be shown underneath the main text.
func (l *ListItem) SetSecondaryText(val string) *ListItem {
l.Lock()
defer l.Unlock()
l.secondaryText = val
return l
}
// GetSecondaryText returns the item's secondary text.
func (l *ListItem) GetSecondaryText() string {
l.RLock()
defer l.RUnlock()
return l.secondaryText
}
// SetShortcut sets the key to select the ListItem directly, 0 if there is no shortcut.
func (l *ListItem) SetShortcut(val rune) *ListItem {
l.Lock()
defer l.Unlock()
l.shortcut = val
return l
}
// GetShortcut returns the ListItem's shortcut.
func (l *ListItem) GetShortcut() rune {
l.RLock()
defer l.RUnlock()
return l.shortcut
}
// SetSelectedFunc sets a function which is called when the ListItem is selected.
func (l *ListItem) SetSelectedFunc(handler func()) *ListItem {
l.Lock()
defer l.Unlock()
l.selected = handler
return l
}
// SetReference allows you to store a reference of any type in the item
func (l *ListItem) SetReference(val interface{}) *ListItem {
l.Lock()
defer l.Unlock()
l.reference = val
return l
}
// GetReference returns the item's reference object.
func (l *ListItem) GetReference() interface{} {
l.RLock()
defer l.RUnlock()
return l.reference
}
@ -708,10 +737,10 @@ func (l *List) transform(tr Transformation) {
case TransformLastItem:
l.currentItem = len(l.items) - 1
case TransformPreviousItem:
l.currentItem -= 1
l.currentItem--
decreasing = true
case TransformNextItem:
l.currentItem += 1
l.currentItem++
case TransformPreviousPage:
l.currentItem -= pageItems
decreasing = true

3
table.go

@ -810,9 +810,8 @@ func (t *Table) Sort(column int, descending bool) *Table {
if !descending {
return t.sortFunc(column, i, j)
} else {
return t.sortFunc(column, j, i)
}
return t.sortFunc(column, j, i)
})
return t

Loading…
Cancel
Save