mirror of
https://github.com/gopasspw/gopass.git
synced 2025-12-08 19:24:54 +00:00
* [chore] Migrate to golangci-lint v2 Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org> * [chore] Fix more lint issues Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org> * [chore] Fix more lint issue Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org> * [chore] Fix more lint issues Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org> * [chore] Add more package comments. Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org> * [chore] Fix golangci-lint config and the remaining checks Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org> * [fix] Use Go 1.24 Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org> * [fix] Fix container builds Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org> * Fix more failing tests Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org> * Fix test failure Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org> * Fix another len assertion Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org> * Move location tests Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org> * [fix] Fix most remaining lint issues Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org> * [fix] Only run XDG specific tests on linux Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org> * [fix] Attempt to address on source of flaky failures Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org> --------- Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org>
45 lines
985 B
Go
45 lines
985 B
Go
// Package cui provides a simple command line user interface
|
|
// for gopass. It is used to interact with the user.
|
|
package cui
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
|
|
"github.com/fatih/color"
|
|
"github.com/gopasspw/gopass/pkg/ctxutil"
|
|
"github.com/gopasspw/gopass/pkg/termio"
|
|
)
|
|
|
|
// GetSelection show a navigable multiple-choice list to the user
|
|
// and returns the selected entry along with the action.
|
|
func GetSelection(ctx context.Context, prompt string, choices []string) (string, int) {
|
|
if ctxutil.IsAlwaysYes(ctx) || !ctxutil.IsInteractive(ctx) {
|
|
return "impossible", 0
|
|
}
|
|
|
|
for i, c := range choices {
|
|
fmt.Print(color.GreenString("[% d]", i))
|
|
fmt.Printf(" %s\n", c)
|
|
}
|
|
fmt.Println()
|
|
var i int
|
|
for {
|
|
var err error
|
|
i, err = termio.AskForInt(ctx, prompt, 0)
|
|
if err == nil && i < len(choices) {
|
|
break
|
|
}
|
|
if errors.Is(err, termio.ErrAborted) {
|
|
return "aborted", 0
|
|
}
|
|
if err != nil {
|
|
fmt.Println(err.Error())
|
|
}
|
|
}
|
|
fmt.Println(i)
|
|
|
|
return "default", i
|
|
}
|