// Package terminal provides secure terminal input helpers for CLI tools. package terminal import ( "fmt" "os" "golang.org/x/term" ) // ReadPassword prints the given prompt to stderr and reads a password // from the terminal with echo disabled. It prints a newline after the // input is complete so the cursor advances normally. func ReadPassword(prompt string) (string, error) { fmt.Fprint(os.Stderr, prompt) b, err := term.ReadPassword(int(os.Stdin.Fd())) //nolint:gosec // fd fits in int fmt.Fprintln(os.Stderr) if err != nil { return "", err } return string(b), nil }