mirror of
https://github.com/rwinkhart/go-boilerplate.git
synced 2026-09-06 09:07:15 -04:00
Rename InputHidden to InputSecret
This commit is contained in:
@@ -9,7 +9,8 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Input prompts the user for input and returns the input as a string.
|
// Input prompts the user for input and
|
||||||
|
// returns the input as a string.
|
||||||
func Input(prompt string) string {
|
func Input(prompt string) string {
|
||||||
fmt.Print(prompt + " ")
|
fmt.Print(prompt + " ")
|
||||||
reader := bufio.NewReader(os.Stdin)
|
reader := bufio.NewReader(os.Stdin)
|
||||||
@@ -17,7 +18,8 @@ func Input(prompt string) string {
|
|||||||
return strings.TrimRight(userInput, "\n\r ") // remove trailing newlines, carriage returns, and spaces
|
return strings.TrimRight(userInput, "\n\r ") // remove trailing newlines, carriage returns, and spaces
|
||||||
}
|
}
|
||||||
|
|
||||||
// InputBinary prompts the user with a yes/no question and returns the response as a boolean.
|
// InputBinary prompts the user with a yes/no
|
||||||
|
// question and returns the response as a boolean.
|
||||||
func InputBinary(prompt string) bool {
|
func InputBinary(prompt string) bool {
|
||||||
reader := bufio.NewReader(os.Stdin)
|
reader := bufio.NewReader(os.Stdin)
|
||||||
fmt.Print(prompt + " (y/N) ")
|
fmt.Print(prompt + " (y/N) ")
|
||||||
|
|||||||
+6
-3
@@ -46,8 +46,10 @@ func pollForInput() bool {
|
|||||||
return ret != 0 && numEvents > 0
|
return ret != 0 && numEvents > 0
|
||||||
}
|
}
|
||||||
|
|
||||||
// Input prompts the user for input and returns the input as a string.
|
// Input prompts the user for input and
|
||||||
// Uses polling to be more responsive to interrupts on Windows.
|
// returns the input as a string.
|
||||||
|
// Uses polling to be more responsive
|
||||||
|
// to interrupts on Windows.
|
||||||
func Input(prompt string) string {
|
func Input(prompt string) string {
|
||||||
fmt.Print(prompt + " ")
|
fmt.Print(prompt + " ")
|
||||||
|
|
||||||
@@ -61,7 +63,8 @@ func Input(prompt string) string {
|
|||||||
return strings.TrimRight(userInput, "\n\r ") // remove trailing newlines, carriage returns, and spaces
|
return strings.TrimRight(userInput, "\n\r ") // remove trailing newlines, carriage returns, and spaces
|
||||||
}
|
}
|
||||||
|
|
||||||
// InputBinary prompts the user with a yes/no question and returns the response as a boolean.
|
// InputBinary prompts the user with a yes/no
|
||||||
|
// question and returns the response as a boolean.
|
||||||
// Uses polling to be more responsive to interrupts on Windows.
|
// Uses polling to be more responsive to interrupts on Windows.
|
||||||
func InputBinary(prompt string) bool {
|
func InputBinary(prompt string) bool {
|
||||||
fmt.Print(prompt + " (y/N) ")
|
fmt.Print(prompt + " (y/N) ")
|
||||||
|
|||||||
@@ -7,7 +7,8 @@ import (
|
|||||||
"golang.org/x/term"
|
"golang.org/x/term"
|
||||||
)
|
)
|
||||||
|
|
||||||
// InputMenuGen prompts the user with a menu and returns the user's choice as an integer.
|
// InputMenuGen prompts the user with a menu
|
||||||
|
// and returns the user's choice as an integer.
|
||||||
func InputMenuGen(prompt string, options []string) int {
|
func InputMenuGen(prompt string, options []string) int {
|
||||||
for i, option := range options {
|
for i, option := range options {
|
||||||
fmt.Printf("%d. %s\n", i+1, option)
|
fmt.Printf("%d. %s\n", i+1, option)
|
||||||
@@ -15,8 +16,9 @@ func InputMenuGen(prompt string, options []string) int {
|
|||||||
return InputInt("\n"+prompt, 1, len(options))
|
return InputInt("\n"+prompt, 1, len(options))
|
||||||
}
|
}
|
||||||
|
|
||||||
// InputHidden prompts the user for input and returns the input as a byte array, hiding the input from the terminal.
|
// InputSecret prompts the user for input and returns the
|
||||||
func InputHidden(prompt string) []byte {
|
// input as a byte array, hiding the input from the terminal.
|
||||||
|
func InputSecret(prompt string) []byte {
|
||||||
fmt.Print(prompt + " ")
|
fmt.Print(prompt + " ")
|
||||||
byteInput, _ := term.ReadPassword(int(os.Stdin.Fd()))
|
byteInput, _ := term.ReadPassword(int(os.Stdin.Fd()))
|
||||||
fmt.Println()
|
fmt.Println()
|
||||||
|
|||||||
Reference in New Issue
Block a user