mirror of
https://github.com/charmbracelet/gum
synced 2026-03-14 13:45:45 +01:00
refactor(kong): Implement Run(...) error interface
Instead of needing to run the commands manually in main.go, we can implement the `Run(...) error` method to satisfy the command interface so that `kong` can Run our commands for us.
This commit is contained in:
parent
bf8d9964df
commit
7190822247
12 changed files with 61 additions and 74 deletions
|
|
@ -6,15 +6,23 @@ import (
|
|||
|
||||
"github.com/charmbracelet/bubbles/textinput"
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
"github.com/charmbracelet/gum/internal/stdin"
|
||||
)
|
||||
|
||||
// Run provides a shell script interface for the text input bubble.
|
||||
// https://github.com/charmbracelet/bubbles/textinput
|
||||
func (o Options) Run() {
|
||||
i := textinput.New()
|
||||
i.Focus()
|
||||
func (o Options) Run() error {
|
||||
in, _ := stdin.Read()
|
||||
|
||||
i.SetValue(o.Value)
|
||||
i := textinput.New()
|
||||
|
||||
if in != "" && o.Value == "" {
|
||||
i.SetValue(in)
|
||||
} else {
|
||||
i.SetValue(o.Value)
|
||||
}
|
||||
|
||||
i.Focus()
|
||||
i.Prompt = o.Prompt
|
||||
i.Placeholder = o.Placeholder
|
||||
i.Width = o.Width
|
||||
|
|
@ -22,6 +30,7 @@ func (o Options) Run() {
|
|||
i.CursorStyle = o.CursorStyle.ToLipgloss()
|
||||
|
||||
p := tea.NewProgram(model{i}, tea.WithOutput(os.Stderr))
|
||||
m, _ := p.StartReturningModel()
|
||||
m, err := p.StartReturningModel()
|
||||
fmt.Println(m.(model).textinput.Value())
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue