Last active
August 29, 2015 14:19
-
-
Save boboTjones/2721acbc9794f1c023a1 to your computer and use it in GitHub Desktop.
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" | |
"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