Fixing linter issues

This commit is contained in:
Dieter Eickstaedt 2022-11-23 13:28:37 +01:00
parent 4858b092ca
commit c6bfe2cdb4
4 changed files with 25 additions and 28 deletions

View file

@ -20,14 +20,6 @@ import (
"github.com/mattn/go-runewidth"
)
type InputStyle int64
const (
SELECT InputStyle = iota
COMBOBOX
INPUT
)
type model struct {
height int
cursor string
@ -40,7 +32,7 @@ type model struct {
limit int
numSelected int
allowAdditionalValue bool
inputModel InputModels
inputModel inputModels
aborted bool
// styles
cursorStyle lipgloss.Style
@ -55,6 +47,11 @@ type item struct {
func (m model) Init() tea.Cmd { return nil }
func (m *model) handleSelectKeys(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
return nil, nil
}
func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
switch msg := msg.(type) {
@ -140,17 +137,15 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
m.inputModel.input.Focus()
m.inputModel.input.CharLimit = 30
return m, textinput.Blink
} else {
m.quitting = true
// If the user hasn't selected any items in a multi-select.
// Then we select the item that they have pressed enter on. If they
// have selected items, then we simply return them.
if m.numSelected < 1 {
m.items[m.index].selected = true
}
return m, tea.Quit
}
m.quitting = true
// If the user hasn't selected any items in a multi-select.
// Then we select the item that they have pressed enter on. If they
// have selected items, then we simply return them.
if m.numSelected < 1 {
m.items[m.index].selected = true
}
return m, tea.Quit
}
} else if m.inputModel.inputState == INPUT {
switch keypress := msg.String(); keypress {

View file

@ -111,7 +111,7 @@ func (o Options) Run() error {
cursorPrefix: o.CursorPrefix,
items: items,
limit: o.Limit,
inputModel: InputModels{paginator: pager, input: input, inputState: SELECT},
inputModel: inputModels{paginator: pager, input: input, inputState: SELECT},
cursorStyle: o.CursorStyle.ToLipgloss(),
itemStyle: o.ItemStyle.ToLipgloss(),
selectedItemStyle: o.SelectedItemStyle.ToLipgloss(),

View file

@ -6,20 +6,22 @@ import (
tea "github.com/charmbracelet/bubbletea"
)
type InputType int
type inputStyle int64
// SELECT User is selecting one of the options
// INPUT User enters into input field
const (
Select InputType = iota
Input
SELECT inputStyle = iota
INPUT
)
type InputModels struct {
inputState InputStyle
type inputModels struct {
inputState inputStyle
paginator paginator.Model
input textinput.Model
}
func (m *InputModels) Update(msg tea.Msg) tea.Cmd {
func (m *inputModels) Update(msg tea.Msg) tea.Cmd {
var cmd tea.Cmd
switch m.inputState {
case SELECT:

View file

@ -8,8 +8,8 @@ type Options struct {
Limit int `help:"Maximum number of options to pick" default:"1" group:"Selection"`
NoLimit bool `help:"Pick unlimited number of options (ignores limit)" group:"Selection"`
AllowInput bool `help:"Allow the Input of additional value" group:"Selection"`
Placeholder string `help:"Placeholder value asking for user Input of additional value" default:"Type something..." env:"GUM_INPUT_PLACEHOLDER"`
AllowInput bool `help:"Allow the input of additional value" group:"Selection"`
Placeholder string `help:"Placeholder value asking for user input of additional value" default:"Type something..." env:"GUM_INPUT_PLACEHOLDER"`
Prompt string `help:"Prompt to display as extra List Item" default:"> " env:"GUM_INPUT_PROMPT"`
Height int `help:"Height of the list" default:"10" env:"GUM_CHOOSE_HEIGHT"`
Cursor string `help:"Prefix to show on item that corresponds to the cursor position" default:"> " env:"GUM_CHOOSE_CURSOR"`