From 95a667a9a3a1e80e4ec4b20b5db19f481ca6d596 Mon Sep 17 00:00:00 2001 From: Jen Andre Date: Sun, 19 Apr 2015 18:20:14 -0400 Subject: [PATCH] Use bufio.ReadString instead of fmt.Scanln so that spaces are handled correctly [Fixes #3] --- prompt.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/prompt.go b/prompt.go index ed59142..1d78613 100644 --- a/prompt.go +++ b/prompt.go @@ -1,16 +1,22 @@ package prompt -import "github.com/howeyc/gopass" +import ( + "os" + + "github.com/howeyc/gopass" +) + import "strings" import "strconv" import "fmt" +import "bufio" // String prompt. func String(prompt string, args ...interface{}) string { - var s string fmt.Printf(prompt+": ", args...) - fmt.Scanln(&s) - return s + reader := bufio.NewReader(os.Stdin) + bytes, _, _ := reader.ReadLine() + return string(bytes) } // String prompt (required).