|
|
|
@ -26,6 +26,9 @@ type InputField struct {
|
|
|
|
|
// The text to be displayed before the input area.
|
|
|
|
|
label string
|
|
|
|
|
|
|
|
|
|
// The text to be displayed in the input area when "text" is empty.
|
|
|
|
|
placeholder string
|
|
|
|
|
|
|
|
|
|
// The label color.
|
|
|
|
|
labelColor tcell.Color
|
|
|
|
|
|
|
|
|
@ -35,6 +38,9 @@ type InputField struct {
|
|
|
|
|
// The text color of the input area.
|
|
|
|
|
fieldTextColor tcell.Color
|
|
|
|
|
|
|
|
|
|
// The text color of the placeholder.
|
|
|
|
|
placeholderTextColor tcell.Color
|
|
|
|
|
|
|
|
|
|
// The screen width of the input area. A value of 0 means extend as much as
|
|
|
|
|
// possible.
|
|
|
|
|
fieldWidth int
|
|
|
|
@ -62,6 +68,7 @@ func NewInputField() *InputField {
|
|
|
|
|
labelColor: Styles.SecondaryTextColor,
|
|
|
|
|
fieldBackgroundColor: Styles.ContrastBackgroundColor,
|
|
|
|
|
fieldTextColor: Styles.PrimaryTextColor,
|
|
|
|
|
placeholderTextColor: Styles.ContrastSecondaryTextColor,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -90,6 +97,12 @@ func (i *InputField) GetLabel() string {
|
|
|
|
|
return i.label
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// SetPlaceholder sets the text to be displayed when the input text is empty.
|
|
|
|
|
func (i *InputField) SetPlaceholder(text string) *InputField {
|
|
|
|
|
i.placeholder = text
|
|
|
|
|
return i
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// SetLabelColor sets the color of the label.
|
|
|
|
|
func (i *InputField) SetLabelColor(color tcell.Color) *InputField {
|
|
|
|
|
i.labelColor = color
|
|
|
|
@ -108,6 +121,12 @@ func (i *InputField) SetFieldTextColor(color tcell.Color) *InputField {
|
|
|
|
|
return i
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// SetPlaceholderExtColor sets the text color of placeholder text.
|
|
|
|
|
func (i *InputField) SetPlaceholderExtColor(color tcell.Color) *InputField {
|
|
|
|
|
i.placeholderTextColor = color
|
|
|
|
|
return i
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// SetFormAttributes sets attributes shared by all form items.
|
|
|
|
|
func (i *InputField) SetFormAttributes(label string, labelColor, bgColor, fieldTextColor, fieldBgColor tcell.Color) FormItem {
|
|
|
|
|
i.label = label
|
|
|
|
@ -200,8 +219,13 @@ func (i *InputField) Draw(screen tcell.Screen) {
|
|
|
|
|
screen.SetContent(x+index, y, ' ', nil, fieldStyle)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Draw entered text.
|
|
|
|
|
// Draw placeholder text.
|
|
|
|
|
text := i.text
|
|
|
|
|
if text == "" && i.placeholder != "" {
|
|
|
|
|
Print(screen, i.placeholder, x, y, fieldWidth, AlignLeft, i.placeholderTextColor)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Draw entered text.
|
|
|
|
|
if i.maskCharacter > 0 {
|
|
|
|
|
text = strings.Repeat(string(i.maskCharacter), utf8.RuneCountInString(i.text))
|
|
|
|
|
}
|
|
|
|
|