Introduce a very rough skeleton to implement interactive shell

This commit is contained in:
Jan Philipp Timme 2019-01-01 19:24:43 +01:00
parent ad252c7480
commit b471f6a914
2 changed files with 34 additions and 4 deletions

View File

@ -39,10 +39,6 @@ func parseArguments() {
settings["usePager"] = strconv.FormatBool(*usePagerPtr)
}
func interactiveShell() {
}
func showQueue() {
queue, err := fetchQueue()
if err != nil {

34
shell.go Normal file
View File

@ -0,0 +1,34 @@
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")
}