Skip to content

Commit

Permalink
Allow configuration of autocomplete list colors
Browse files Browse the repository at this point in the history
  • Loading branch information
gpanders committed Jun 15, 2021
1 parent d4fb034 commit c5d98ee
Showing 1 changed file with 52 additions and 9 deletions.
61 changes: 52 additions & 9 deletions inputfield.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,18 @@ type InputField struct {
// The text color of the placeholder.
placeholderTextColor tcell.Color

// The text color of the autocomplete list
autocompleteTextColor tcell.Color

// The background color of the autocomplete list
autocompleteBackgroundColor tcell.Color

// The text color of the selected item in the autocomplete list
autocompleteSelectedTextColor tcell.Color

// The background color of the selected item in the autocomplete list
autocompleteSelectedBackgroundColor tcell.Color

// The screen width of the label area. A value of 0 means use the width of
// the label text.
labelWidth int
Expand Down Expand Up @@ -101,11 +113,15 @@ type InputField struct {
// NewInputField returns a new input field.
func NewInputField() *InputField {
return &InputField{
Box: NewBox(),
labelColor: Styles.SecondaryTextColor,
fieldBackgroundColor: Styles.ContrastBackgroundColor,
fieldTextColor: Styles.PrimaryTextColor,
placeholderTextColor: Styles.ContrastSecondaryTextColor,
Box: NewBox(),
labelColor: Styles.SecondaryTextColor,
fieldBackgroundColor: Styles.ContrastBackgroundColor,
fieldTextColor: Styles.PrimaryTextColor,
placeholderTextColor: Styles.ContrastSecondaryTextColor,
autocompleteTextColor: Styles.PrimitiveBackgroundColor,
autocompleteBackgroundColor: Styles.MoreContrastBackgroundColor,
autocompleteSelectedTextColor: Styles.PrimitiveBackgroundColor,
autocompleteSelectedBackgroundColor: Styles.PrimaryTextColor,
}
}

Expand Down Expand Up @@ -172,6 +188,33 @@ func (i *InputField) SetPlaceholderTextColor(color tcell.Color) *InputField {
return i
}

// SetAutocompleteTextColor sets the text color of the autocomplete list.
func (i *InputField) SetAutocompleteTextColor(color tcell.Color) *InputField {
i.autocompleteTextColor = color
return i
}

// SetAutocompleteBackgroundColor sets the background color of the autocomplete
// list.
func (i *InputField) SetAutocompleteBackgroundColor(color tcell.Color) *InputField {
i.autocompleteBackgroundColor = color
return i
}

// SetAutocompleteSelectedTextColor sets the text color of the selected item in
// the autocomplete list.
func (i *InputField) SetAutocompleteSelectedTextColor(color tcell.Color) *InputField {
i.autocompleteSelectedTextColor = color
return i
}

// SetAutocompleteSelectedBackgroundColor sets the background color of the
// selected item in the autocomplete list.
func (i *InputField) SetAutocompleteSelectedBackgroundColor(color tcell.Color) *InputField {
i.autocompleteSelectedBackgroundColor = color
return i
}

// SetFormAttributes sets attributes shared by all form items.
func (i *InputField) SetFormAttributes(labelWidth int, labelColor, bgColor, fieldTextColor, fieldBgColor tcell.Color) FormItem {
i.labelWidth = labelWidth
Expand Down Expand Up @@ -240,11 +283,11 @@ func (i *InputField) Autocomplete() *InputField {
if i.autocompleteList == nil {
i.autocompleteList = NewList()
i.autocompleteList.ShowSecondaryText(false).
SetMainTextColor(Styles.PrimitiveBackgroundColor).
SetSelectedTextColor(Styles.PrimitiveBackgroundColor).
SetSelectedBackgroundColor(Styles.PrimaryTextColor).
SetMainTextColor(i.autocompleteTextColor).
SetSelectedTextColor(i.autocompleteSelectedTextColor).
SetSelectedBackgroundColor(i.autocompleteSelectedBackgroundColor).
SetHighlightFullLine(true).
SetBackgroundColor(Styles.MoreContrastBackgroundColor)
SetBackgroundColor(i.autocompleteBackgroundColor)
}

// Fill it with the entries.
Expand Down

0 comments on commit c5d98ee

Please sign in to comment.