Skip to content

Instantly share code, notes, and snippets.

@micahwalter
Created November 2, 2023 18:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save micahwalter/a2c2c3d3f8713747c18bf0f01e924db8 to your computer and use it in GitHub Desktop.
Save micahwalter/a2c2c3d3f8713747c18bf0f01e924db8 to your computer and use it in GitHub Desktop.
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