micro/src/command.go

40 lines
592 B
Go
Raw Normal View History

2016-03-30 00:44:33 +00:00
package main
import (
2016-03-30 00:51:32 +00:00
"os"
2016-03-30 00:44:33 +00:00
"strings"
)
// HandleCommand handles input from the user
func HandleCommand(input string, view *View) {
inputCmd := strings.Split(input, " ")[0]
2016-03-30 00:44:33 +00:00
args := strings.Split(input, " ")[1:]
commands := []string{"set", "quit", "save"}
i := 0
cmd := inputCmd
for _, c := range commands {
if strings.HasPrefix(c, inputCmd) {
i++
cmd = c
}
}
if i == 1 {
inputCmd = cmd
}
switch inputCmd {
2016-03-30 00:51:32 +00:00
case "set":
2016-03-30 00:44:33 +00:00
SetOption(view, args)
2016-03-30 00:51:32 +00:00
case "quit":
if view.CanClose("Quit anyway? ") {
screen.Fini()
os.Exit(0)
}
case "save":
view.Save()
2016-03-30 00:44:33 +00:00
}
}