fix: default to 40

This commit is contained in:
Maas Lalani 2022-07-27 13:58:34 -04:00
parent 44cc74e496
commit de59d7580d
No known key found for this signature in database
GPG key ID: 5A6ED5CBF1A0A000
3 changed files with 3 additions and 16 deletions

View file

@ -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

View file

@ -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:

View file

@ -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"`
}