summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMaas Lalani <maas@lalani.dev>2022-12-13 15:05:10 -0500
committerMaas Lalani <maas@lalani.dev>2022-12-13 15:05:56 -0500
commit240e163f012214a937f83b4a46cd500ca1bb5315 (patch)
treeacfdc61fbd9ea4c3e302c802b8b1262574347f8a
parent2d54d5394e77172bc4e5da4c9b445136d95ea551 (diff)
feat(input): header values
-rw-r--r--input/command.go6
-rw-r--r--input/input.go24
-rw-r--r--input/options.go2
-rw-r--r--write/write.go1
4 files changed, 28 insertions, 5 deletions
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: