TheMathemagicians/sevenkeys/cli/mainui.go

144 lines
3.2 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"
2024-08-20 11:57:36 +00:00
"sevenkeys/database"
2024-06-12 20:33:50 +00:00
"sevenkeys/logic"
"sevenkeys/manabox"
2024-06-10 15:34:16 +00:00
)
var output string
2024-06-11 09:57:02 +00:00
func MainCliLoop(db *sql.DB) {
2024-06-10 15:34:16 +00:00
var command string
//var selectedStorageAreaName string
var cardLocation database.CardLocation
2024-06-10 15:34:16 +00:00
var insertSearchCriteria logic.SearchCriteria = logic.SearchCriteria{
SetCode: "",
Foil: logic.Either,
Promo: logic.Either,
Language: "en",
}
var insertSearchOptions logic.InsertSearchOptions
2024-09-13 11:32:18 +00:00
// TODO: Add the ability to modify this
2024-09-07 23:24:24 +00:00
var locateSearchCriteria logic.SearchCriteria = logic.SearchCriteria{
SetCode: "",
Foil: logic.True,
2024-09-07 23:24:24 +00:00
Promo: logic.Either,
Language: "en",
}
2024-06-10 15:34:16 +00:00
for {
2024-06-12 20:33:50 +00:00
ShowSplashScreen()
// TODO: Fix this
//showStorageInfo(os.Stdout, selectedStorageAreaName)
showInsertSearchCriteria(insertSearchCriteria)
showSelectedCard()
showCopiesInserted()
2024-06-12 20:33:50 +00:00
2024-06-10 15:34:16 +00:00
command = GetStringResponse("SEVENKEYS $")
2024-08-20 11:57:36 +00:00
var err error
2024-06-10 15:34:16 +00:00
switch command {
case "q", "quit":
2024-06-10 15:34:16 +00:00
return
2024-08-20 11:57:36 +00:00
case "n", "newstorage":
var storageArea database.StorageArea
storageArea.Name = GetStringResponse("Storage area name:")
storageArea.StorageType = GetStringResponse("Storage area type (Binder/Box):")
2024-08-20 11:57:36 +00:00
err = logic.CreateStorageArea(db, storageArea)
logic.Check(err)
break
2024-08-20 17:00:23 +00:00
case "a", "area":
2024-09-17 10:25:51 +00:00
options, err := logic.GetStorageAreaSearchOptions(db)
2024-08-20 17:00:23 +00:00
logic.Check(err)
2024-09-17 10:25:51 +00:00
id, _, err := logic.GenericSearch(options)
2024-09-17 10:25:51 +00:00
logic.Check(err)
//selectedStorageAreaName = name
2024-09-17 10:25:51 +00:00
cardLocation.StorageAreaId = id
break
case "c", "criteria":
insertSearchCriteria = getSearchCriteria()
2024-06-12 20:33:50 +00:00
break
case "s", "search":
if shouldRefreshSearch {
insertSearchOptions = getSearchOptions(db, insertSearchCriteria)
}
var previousCardPrintingId = cardLocation.CardPrintingId
pk, searchLine, err := logic.GenericSearch(insertSearchOptions)
cardLocation.CardPrintingId = pk
selectedCardPrintingSearchLine = searchLine
2024-06-12 20:33:50 +00:00
var exitError *exec.ExitError
if errors.As(err, &exitError) {
break
}
logic.Check(err)
output = ""
if cardLocation.CardPrintingId != previousCardPrintingId {
copiesInserted = 0
}
2024-06-10 15:34:16 +00:00
break
case "i", "insert":
2024-09-17 10:25:51 +00:00
err := logic.StoreCard(db, cardLocation)
logic.Check(err)
copiesInserted++
break
case "m", "manabox":
filename := GetStringResponse("Filename:")
manabox.ParseManaboxExport(filename)
break
case "l", "locate":
2024-09-07 23:24:24 +00:00
filename := GetStringResponse("Filename:")
cardNames, err := logic.GetCardNamesFromFile(filename)
logic.Check(err)
2024-09-07 23:24:24 +00:00
locations, err := logic.LocateCards(db, cardNames, locateSearchCriteria)
logic.Check(err)
2024-09-13 11:32:18 +00:00
if len(locations) == 0 {
fmt.Println("No results found")
fmt.Scanln()
break
}
for _, location := range locations {
2024-09-13 11:32:18 +00:00
description := logic.GetLocationDescription(location)
fmt.Println(description)
for true {
todo := GetStringResponse("TODO:")
if todo == "r" {
logic.RemoveFromStorage(db, location)
break
2024-09-13 11:32:18 +00:00
} else if todo == "n" {
2024-09-13 19:05:28 +00:00
break
2024-09-13 11:32:18 +00:00
} else {
fmt.Printf("Unrecognized option: %s\n", todo)
}
}
}
2024-09-13 19:16:17 +00:00
fmt.Println("Though this query has ended, its relics still slumber in New Argive.")
2024-09-13 11:32:18 +00:00
fmt.Scanln()
2024-06-10 15:34:16 +00:00
break
default:
fmt.Println("Unrecognized command:", command)
break
}
}
}