Created
July 25, 2017 17:11
-
-
Save henvic/44dddad8c3f85171f1ef08356be0f0bf to your computer and use it in GitHub Desktop.
ttyissue.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"bufio" | |
"fmt" | |
"os" | |
"syscall" | |
"golang.org/x/crypto/ssh/terminal" | |
) | |
func prompt() { | |
fmt.Print("Prompt: ") | |
reader := bufio.NewReader(os.Stdin) | |
value, err := reader.ReadString('\n') | |
fmt.Fprintf(os.Stdout, "value: %verror: %v\n\n", value, err) | |
} | |
func hidden() { | |
fmt.Print("Hidden: ") | |
var value, err = terminal.ReadPassword(int(syscall.Stdin)) | |
fmt.Fprintf(os.Stdout, "\nvalue: %v\nerror: %v\n\n", string(value), err) | |
} | |
func main() { | |
fmt.Fprintf(os.Stdout, "Terminal = %v\n\n", terminal.IsTerminal(int(os.Stdin.Fd()))) | |
prompt() | |
hidden() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment