TheMathemagicians/sevenkeys/cli/mainui.go

67 lines
1.1 KiB
Go
Raw Normal View History

2024-06-10 15:34:16 +00:00
package cli
import (
2024-06-11 09:43:30 +00:00
"database/sql"
2024-06-12 20:33:50 +00:00
"errors"
2024-06-10 15:34:16 +00:00
"fmt"
2024-06-12 20:33:50 +00:00
"os/exec"
"sevenkeys/logic"
2024-06-10 15:34:16 +00:00
)
var output string
func showOutput() {
if output != "" {
fmt.Println(output)
}
}
2024-06-11 09:57:02 +00:00
func MainCliLoop(db *sql.DB) {
2024-06-10 15:34:16 +00:00
var command string
for {
2024-06-12 20:33:50 +00:00
ShowSplashScreen()
showStorageInfo()
showSearchCriteria()
showSelectedCard()
showCopiesInserted()
2024-06-12 20:33:50 +00:00
2024-06-10 15:34:16 +00:00
command = GetStringResponse("SEVENKEYS $")
switch command {
case "quit":
return
2024-06-12 20:33:50 +00:00
case "storage":
getStorageOptions()
2024-06-12 20:33:50 +00:00
break
case "criteria":
getSearchCriteria()
break
case "search":
getSearchOptions(db)
var previousCardPrintingId = cardStorageLocation.CardPrintingId
2024-06-12 20:33:50 +00:00
var err error
cardStorageLocation.CardPrintingId, selectedCardPrintingSearchLine, err = logic.Search(searchOptions)
2024-06-12 20:33:50 +00:00
var exitError *exec.ExitError
if errors.As(err, &exitError) {
break
}
logic.Check(err)
output = ""
if cardStorageLocation.CardPrintingId != previousCardPrintingId {
copiesInserted = 0
}
2024-06-10 15:34:16 +00:00
break
2024-06-12 20:33:50 +00:00
case "insert":
insertSelectedCard(db)
2024-06-10 15:34:16 +00:00
break
default:
fmt.Println("Unrecognized command:", command)
break
}
}
}