mirror of
https://github.com/charmbracelet/gum
synced 2026-03-14 13:45:45 +01:00
feat: yes|gum confirm (#772)
* feat: yes|gum confirm Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com> * fix: rebase on main --------- Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
This commit is contained in:
parent
4cedf9fca0
commit
0b89ff82d4
1 changed files with 14 additions and 1 deletions
|
|
@ -7,12 +7,25 @@ import (
|
|||
|
||||
"github.com/charmbracelet/bubbles/help"
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
"github.com/charmbracelet/gum/internal/stdin"
|
||||
"github.com/charmbracelet/gum/internal/timeout"
|
||||
)
|
||||
|
||||
var errNotConfirmed = errors.New("not confirmed")
|
||||
|
||||
// Run provides a shell script interface for prompting a user to confirm an
|
||||
// action with an affirmative or negative answer.
|
||||
func (o Options) Run() error {
|
||||
line, err := stdin.Read(stdin.SingleLine(true))
|
||||
if err == nil {
|
||||
switch line {
|
||||
case "yes", "y":
|
||||
return nil
|
||||
default:
|
||||
return errNotConfirmed
|
||||
}
|
||||
}
|
||||
|
||||
ctx, cancel := timeout.Context(o.Timeout)
|
||||
defer cancel()
|
||||
|
||||
|
|
@ -52,5 +65,5 @@ func (o Options) Run() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
return errors.New("not confirmed")
|
||||
return errNotConfirmed
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue