mirror of
https://github.com/charmbracelet/gum
synced 2024-05-19 06:37:00 +02:00
fix: default to 40
This commit is contained in:
parent
44cc74e496
commit
de59d7580d
|
@ -31,10 +31,7 @@ func (o Options) Run() error {
|
|||
i.PromptStyle = o.PromptStyle.ToLipgloss()
|
||||
i.CursorStyle = o.CursorStyle.ToLipgloss()
|
||||
|
||||
p := tea.NewProgram(model{
|
||||
textinput: i,
|
||||
autosize: o.Width == 0,
|
||||
}, tea.WithOutput(os.Stderr))
|
||||
p := tea.NewProgram(model{i}, tea.WithOutput(os.Stderr))
|
||||
m, err := p.StartReturningModel()
|
||||
fmt.Println(m.(model).textinput.Value())
|
||||
return err
|
||||
|
|
|
@ -11,24 +11,14 @@ package input
|
|||
import (
|
||||
"github.com/charmbracelet/bubbles/textinput"
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
"github.com/charmbracelet/lipgloss"
|
||||
)
|
||||
|
||||
type model struct {
|
||||
textinput textinput.Model
|
||||
autosize bool
|
||||
}
|
||||
type model struct{ textinput textinput.Model }
|
||||
|
||||
func (m model) Init() tea.Cmd { return textinput.Blink }
|
||||
func (m model) View() string { return m.textinput.View() }
|
||||
func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
switch msg := msg.(type) {
|
||||
case tea.WindowSizeMsg:
|
||||
if !m.autosize {
|
||||
return m, nil
|
||||
}
|
||||
m.textinput.Width = msg.Width - (lipgloss.Width(m.textinput.Prompt) + 1)
|
||||
return m, nil
|
||||
case tea.KeyMsg:
|
||||
switch msg.Type {
|
||||
case tea.KeyEscape, tea.KeyCtrlC, tea.KeyEnter:
|
||||
|
|
|
@ -9,5 +9,5 @@ type Options struct {
|
|||
PromptStyle style.Styles `embed:"" prefix:"prompt." set:"name=prompt"`
|
||||
CursorStyle style.Styles `embed:"" prefix:"cursor." set:"defaultForeground=212" set:"name=cursor"`
|
||||
Value string `help:"Initial value (can also be passed via stdin)" default:""`
|
||||
Width int `help:"Input width" default:"0"`
|
||||
Width int `help:"Input width" default:"40"`
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue