35 lines
538 B
Go
35 lines
538 B
Go
|
package main
|
||
|
|
||
|
import (
|
||
|
"bufio"
|
||
|
"fmt"
|
||
|
"os"
|
||
|
"strings"
|
||
|
)
|
||
|
|
||
|
func interactiveShell() {
|
||
|
fmt.Println("Let's try an interactive shell!")
|
||
|
scanner := bufio.NewScanner(os.Stdin)
|
||
|
for {
|
||
|
fmt.Print("> ")
|
||
|
if !scanner.Scan() {
|
||
|
break
|
||
|
}
|
||
|
text := strings.Trim(scanner.Text(), " ")
|
||
|
textFields := strings.Fields(text)
|
||
|
if len(textFields) == 0 {
|
||
|
continue
|
||
|
}
|
||
|
cmd := textFields[0]
|
||
|
fmt.Printf("Read input: %q\n", textFields)
|
||
|
|
||
|
switch cmd {
|
||
|
|
||
|
default:
|
||
|
fmt.Printf("Unknown command '%s'\n", cmd)
|
||
|
}
|
||
|
|
||
|
}
|
||
|
fmt.Println("\nGoodbye!\n")
|
||
|
}
|