mirror of
https://github.com/charmbracelet/gum
synced 2024-06-10 17:52:20 +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.PromptStyle = o.PromptStyle.ToLipgloss()
|
||||||
i.CursorStyle = o.CursorStyle.ToLipgloss()
|
i.CursorStyle = o.CursorStyle.ToLipgloss()
|
||||||
|
|
||||||
p := tea.NewProgram(model{
|
p := tea.NewProgram(model{i}, tea.WithOutput(os.Stderr))
|
||||||
textinput: i,
|
|
||||||
autosize: o.Width == 0,
|
|
||||||
}, tea.WithOutput(os.Stderr))
|
|
||||||
m, err := p.StartReturningModel()
|
m, err := p.StartReturningModel()
|
||||||
fmt.Println(m.(model).textinput.Value())
|
fmt.Println(m.(model).textinput.Value())
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -11,24 +11,14 @@ package input
|
||||||
import (
|
import (
|
||||||
"github.com/charmbracelet/bubbles/textinput"
|
"github.com/charmbracelet/bubbles/textinput"
|
||||||
tea "github.com/charmbracelet/bubbletea"
|
tea "github.com/charmbracelet/bubbletea"
|
||||||
"github.com/charmbracelet/lipgloss"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type model struct {
|
type model struct{ textinput textinput.Model }
|
||||||
textinput textinput.Model
|
|
||||||
autosize bool
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m model) Init() tea.Cmd { return textinput.Blink }
|
func (m model) Init() tea.Cmd { return textinput.Blink }
|
||||||
func (m model) View() string { return m.textinput.View() }
|
func (m model) View() string { return m.textinput.View() }
|
||||||
func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||||
switch msg := msg.(type) {
|
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:
|
case tea.KeyMsg:
|
||||||
switch msg.Type {
|
switch msg.Type {
|
||||||
case tea.KeyEscape, tea.KeyCtrlC, tea.KeyEnter:
|
case tea.KeyEscape, tea.KeyCtrlC, tea.KeyEnter:
|
||||||
|
|
|
@ -9,5 +9,5 @@ type Options struct {
|
||||||
PromptStyle style.Styles `embed:"" prefix:"prompt." set:"name=prompt"`
|
PromptStyle style.Styles `embed:"" prefix:"prompt." set:"name=prompt"`
|
||||||
CursorStyle style.Styles `embed:"" prefix:"cursor." set:"defaultForeground=212" set:"name=cursor"`
|
CursorStyle style.Styles `embed:"" prefix:"cursor." set:"defaultForeground=212" set:"name=cursor"`
|
||||||
Value string `help:"Initial value (can also be passed via stdin)" default:""`
|
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