mirror of
https://github.com/charmbracelet/gum
synced 2026-03-14 21:55:45 +01:00
* Revert "feat: huh gum write (#525)" This reverts commit4d5d53169e. Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com> * Revert "Use Huh for Gum Confirm (#522)" This reverts commitf7572e387e. Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com> * revert: Use Huh for Gum Choose (#521) Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com> * revert: feat: huh for gum input (#524) * revert: feat: huh file picker (#523) * feat: remove huh * fix: timeouts * fix: lint issues * fix(choose): quit on ctrl+q ported over63a3e8c8ce* fix: ctrl+a to reverse selection Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com> * fix: better handle spin exit codes * fix(file): bind --[no-]permissions and --[no-]size * feat(confirm): show help * fix(confirm): fix help style * fix(file): help * fix(input): --no-show-help doesn't work * fix(input): help * fix(file): keymap improvement * fix(write): focus * feat(write): ctrl+e, keymaps, help * feat(choose): help * feat(filter): help * refactor: keymaps * fix(choose): only show 'toggle all' if there's no limit * fix(choose): don't show toggle if the choices are limited to 1 * fix(filter): match choose header color * fix(filter): add space above help * fix(filter): factor help into the height setting * chore(choose,filter): use verb for navigation label in help * fix(filter): hide toggle help if limit is 1 * fix(file): factor help into height setting (#746) * fix: lint issues * fix(file): handle ctrl+c * fix: remove full help * fix: lint --------- Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com> Co-authored-by: Christian Rocha <christian@rocha.is>
73 lines
1.6 KiB
Go
73 lines
1.6 KiB
Go
package input
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
|
|
"github.com/charmbracelet/bubbles/help"
|
|
"github.com/charmbracelet/bubbles/textinput"
|
|
tea "github.com/charmbracelet/bubbletea"
|
|
|
|
"github.com/charmbracelet/gum/cursor"
|
|
"github.com/charmbracelet/gum/internal/exit"
|
|
"github.com/charmbracelet/gum/internal/stdin"
|
|
)
|
|
|
|
// Run provides a shell script interface for the text input bubble.
|
|
// https://github.com/charmbracelet/bubbles/textinput
|
|
func (o Options) Run() error {
|
|
if o.Value == "" {
|
|
if in, _ := stdin.Read(); in != "" {
|
|
o.Value = in
|
|
}
|
|
}
|
|
|
|
i := textinput.New()
|
|
if o.Value != "" {
|
|
i.SetValue(o.Value)
|
|
} else if in, _ := stdin.Read(); in != "" {
|
|
i.SetValue(in)
|
|
}
|
|
i.Focus()
|
|
i.Prompt = o.Prompt
|
|
i.Placeholder = o.Placeholder
|
|
i.Width = o.Width
|
|
i.PromptStyle = o.PromptStyle.ToLipgloss()
|
|
i.PlaceholderStyle = o.PlaceholderStyle.ToLipgloss()
|
|
i.Cursor.Style = o.CursorStyle.ToLipgloss()
|
|
i.Cursor.SetMode(cursor.Modes[o.CursorMode])
|
|
i.CharLimit = o.CharLimit
|
|
|
|
if o.Password {
|
|
i.EchoMode = textinput.EchoPassword
|
|
i.EchoCharacter = '•'
|
|
}
|
|
|
|
p := tea.NewProgram(model{
|
|
textinput: i,
|
|
aborted: false,
|
|
header: o.Header,
|
|
headerStyle: o.HeaderStyle.ToLipgloss(),
|
|
timeout: o.Timeout,
|
|
hasTimeout: o.Timeout > 0,
|
|
autoWidth: o.Width < 1,
|
|
showHelp: o.ShowHelp,
|
|
help: help.New(),
|
|
keymap: defaultKeymap(),
|
|
}, tea.WithOutput(os.Stderr))
|
|
tm, err := p.Run()
|
|
if err != nil {
|
|
return fmt.Errorf("failed to run input: %w", err)
|
|
}
|
|
|
|
m := tm.(model)
|
|
if m.aborted {
|
|
return exit.ErrAborted
|
|
}
|
|
if m.timedOut {
|
|
return exit.ErrTimeout
|
|
}
|
|
|
|
fmt.Println(m.textinput.Value())
|
|
return nil
|
|
}
|