Skip to content

Instantly share code, notes, and snippets.

@boboTjones
Last active August 29, 2015 14:19
Show Gist options
  • Save boboTjones/2721acbc9794f1c023a1 to your computer and use it in GitHub Desktop.
Save boboTjones/2721acbc9794f1c023a1 to your computer and use it in GitHub Desktop.
package main
import (
"bufio"
"fmt"
"os"
"strings"
"strconv"
)
func main() {
for {
prompt := bufio.NewReader(os.Stdin)
fmt.Print("$> ")
response, err := prompt.ReadString('\n') // this will prompt the user for input
if err != nil {
fmt.Println(err)
os.Exit(1)
}
r := strings.Split(response, "\n")
switch r[0] {
case "go":
fmt.Println("Okay!")
case "exit":
os.Exit(0)
case "s":
var b string
for {
fmt.Println("I dunno.")
fmt.Scanf("%s", &b)
}
default:
// default case: step n times or until keypress??
var b string
n, _ := strconv.Atoi(r[0])
for i := 1; i < (n + 1); i++ {
fmt.Println(i, " I dunno.")
fmt.Scanf("%s", &b)
if b == "x" {
break
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment