You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
54 lines
1.1 KiB
54 lines
1.1 KiB
4 years ago
|
package blsgen
|
||
4 years ago
|
|
||
|
import (
|
||
|
"bufio"
|
||
|
"fmt"
|
||
|
"os"
|
||
4 years ago
|
"strings"
|
||
4 years ago
|
"syscall"
|
||
|
|
||
|
"golang.org/x/crypto/ssh/terminal"
|
||
|
)
|
||
|
|
||
|
var console consoleItf = &stdConsole{}
|
||
|
|
||
|
// consoleItf define the interface for module level console input and outputs
|
||
|
type consoleItf interface {
|
||
|
readPassword() (string, error)
|
||
|
readln() (string, error)
|
||
|
print(a ...interface{})
|
||
|
println(a ...interface{})
|
||
|
printf(format string, a ...interface{})
|
||
|
}
|
||
|
|
||
|
type stdConsole struct{}
|
||
|
|
||
|
func (console *stdConsole) readPassword() (string, error) {
|
||
|
b, err := terminal.ReadPassword(syscall.Stdin)
|
||
|
if err != nil {
|
||
|
return "", err
|
||
|
}
|
||
4 years ago
|
return strings.TrimSpace(string(b)), nil
|
||
4 years ago
|
}
|
||
|
|
||
|
func (console *stdConsole) readln() (string, error) {
|
||
|
reader := bufio.NewReader(os.Stdin)
|
||
4 years ago
|
raw, err := reader.ReadString('\n')
|
||
|
if err != nil {
|
||
|
return "", err
|
||
|
}
|
||
|
return strings.TrimSpace(raw), nil
|
||
4 years ago
|
}
|
||
|
|
||
|
func (console *stdConsole) print(a ...interface{}) {
|
||
|
fmt.Print(a...)
|
||
|
}
|
||
|
|
||
|
func (console *stdConsole) println(a ...interface{}) {
|
||
|
fmt.Println(a...)
|
||
|
}
|
||
|
|
||
|
func (console *stdConsole) printf(format string, a ...interface{}) {
|
||
|
fmt.Printf(format, a...)
|
||
|
}
|