From c5d98ee108aaf795b639029c77fffa1d0f2dcdaa Mon Sep 17 00:00:00 2001 From: Gregory Anders Date: Tue, 15 Jun 2021 14:51:19 -0600 Subject: [PATCH] Allow configuration of autocomplete list colors --- inputfield.go | 61 +++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 52 insertions(+), 9 deletions(-) diff --git a/inputfield.go b/inputfield.go index d1e33942..4c1d3980 100644 --- a/inputfield.go +++ b/inputfield.go @@ -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 @@ -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, } } @@ -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 @@ -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.