diff --git a/input/command.go b/input/command.go index 9efde06..79a4c74 100644 --- a/input/command.go +++ b/input/command.go @@ -37,8 +37,10 @@ func (o Options) Run() error { } p := tea.NewProgram(model{ - textinput: i, - aborted: false, + textinput: i, + aborted: false, + header: o.Header, + headerStyle: o.HeaderStyle.ToLipgloss(), }, tea.WithOutput(os.Stderr)) tm, err := p.Run() if err != nil { diff --git a/input/input.go b/input/input.go index c868b22..5b0cae1 100644 --- a/input/input.go +++ b/input/input.go @@ -10,23 +10,41 @@ package input import ( "github.com/charmbracelet/bubbles/textinput" tea "github.com/charmbracelet/bubbletea" + "github.com/charmbracelet/lipgloss" ) type model struct { - textinput textinput.Model - aborted bool + header string + headerStyle lipgloss.Style + textinput textinput.Model + quitting bool + aborted bool } func (m model) Init() tea.Cmd { return textinput.Blink } -func (m model) View() string { return m.textinput.View() } +func (m model) View() string { + if m.quitting { + return "" + } + + if m.header != "" { + header := m.headerStyle.Render(m.header) + return lipgloss.JoinVertical(lipgloss.Left, header, m.textinput.View()) + } + + return m.textinput.View() +} + func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { switch msg := msg.(type) { case tea.KeyMsg: switch msg.String() { case "ctrl+c", "esc": + m.quitting = true m.aborted = true return m, tea.Quit case "enter": + m.quitting = true return m, tea.Quit } } diff --git a/input/options.go b/input/options.go index f32d7c5..2e103f8 100644 --- a/input/options.go +++ b/input/options.go @@ -12,4 +12,6 @@ type Options struct { CharLimit int `help:"Maximum value length (0 for no limit)" default:"400"` Width int `help:"Input width" default:"40" env:"GUM_INPUT_WIDTH"` Password bool `help:"Mask input characters" default:"false"` + Header string `help:"Header value" default:"" env:"GUM_INPUT_HEADER"` + HeaderStyle style.Styles `embed:"" prefix:"header." set:"defaultForeground=240" envprefix:"GUM_INPUT_HEADER_"` } diff --git a/write/write.go b/write/write.go index e0ce696..1674437 100644 --- a/write/write.go +++ b/write/write.go @@ -36,6 +36,7 @@ func (m model) View() string { return m.textarea.View() } + func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { switch msg := msg.(type) { case tea.KeyMsg: