first commit
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
package widgets
|
||||
|
||||
import (
|
||||
"ArinDash/util"
|
||||
"context"
|
||||
|
||||
"github.com/mum4k/termdash/cell"
|
||||
"github.com/mum4k/termdash/terminal/terminalapi"
|
||||
"github.com/mum4k/termdash/widgetapi"
|
||||
"github.com/mum4k/termdash/widgets/textinput"
|
||||
)
|
||||
|
||||
type TextInputOptions struct {
|
||||
updateText chan<- string
|
||||
options []textinput.Option
|
||||
}
|
||||
|
||||
var defaultOptions = []textinput.Option{
|
||||
textinput.Label("Enter Text", cell.FgColor(cell.ColorNumber(33))),
|
||||
textinput.MaxWidthCells(20),
|
||||
textinput.PlaceHolder("enter any text"),
|
||||
}
|
||||
|
||||
func TextInput(updateText chan<- string, options ...textinput.Option) TextInputOptions {
|
||||
widgetOptions["TextInputOptions"] = createTextInput
|
||||
return TextInputOptions{
|
||||
options: createOptions(updateText, options),
|
||||
}
|
||||
}
|
||||
|
||||
func createOptions(updateText chan<- string, options []textinput.Option) []textinput.Option {
|
||||
result := defaultOptions
|
||||
if options != nil && len(options) != 0 {
|
||||
for _, option := range options {
|
||||
result = append(result, option)
|
||||
}
|
||||
}
|
||||
|
||||
result = append(result, textinput.ClearOnSubmit())
|
||||
result = append(result, textinput.OnSubmit(func(text string) error {
|
||||
updateText <- text
|
||||
return nil
|
||||
}))
|
||||
return result
|
||||
}
|
||||
|
||||
func createTextInput(_ context.Context, _ terminalapi.Terminal, opt interface{}) widgetapi.Widget {
|
||||
options, ok := opt.(TextInputOptions)
|
||||
if !ok {
|
||||
panic("invalid options type")
|
||||
}
|
||||
return util.PanicOnErrorWithResult(textinput.New(
|
||||
options.options...,
|
||||
))
|
||||
}
|
||||
Reference in New Issue
Block a user