Created
November 2, 2023 18:41
-
-
Save micahwalter/a2c2c3d3f8713747c18bf0f01e924db8 to your computer and use it in GitHub Desktop.
This file contains 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" | |
) | |
func stringPrompt(label string) string { | |
var s string | |
r := bufio.NewReader(os.Stdin) | |
for { | |
fmt.Fprint(os.Stderr, label+" ") | |
s, _ = r.ReadString('\n') | |
if s != "" { | |
break | |
} | |
} | |
return s | |
} | |
func main() { | |
fmt.Printf("Hi there. You can ask me stuff!\n") | |
for { | |
fmt.Printf("You said: %v", stringPrompt(">")) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment