Update storage UI

This commit is contained in:
The Magician 2024-08-20 15:28:49 +01:00
parent 8fe02f46d6
commit de116aee20
3 changed files with 51 additions and 12 deletions

View File

@ -4,6 +4,7 @@ import (
"database/sql" "database/sql"
"errors" "errors"
"fmt" "fmt"
"os"
"os/exec" "os/exec"
"sevenkeys/database" "sevenkeys/database"
"sevenkeys/logic" "sevenkeys/logic"
@ -19,10 +20,11 @@ func showOutput() {
func MainCliLoop(db *sql.DB) { func MainCliLoop(db *sql.DB) {
var command string var command string
var selectedStorageArea database.StorageArea
for { for {
ShowSplashScreen() ShowSplashScreen()
showStorageInfo() showStorageInfo(os.Stdout, selectedStorageArea)
showSearchCriteria() showSearchCriteria()
showSelectedCard() showSelectedCard()
showCopiesInserted() showCopiesInserted()

View File

@ -3,6 +3,7 @@ package cli
import ( import (
"database/sql" "database/sql"
"fmt" "fmt"
"io"
"sevenkeys/database" "sevenkeys/database"
"sevenkeys/logic" "sevenkeys/logic"
) )
@ -22,18 +23,15 @@ func getInfoDisplay(info string) string {
return info return info
} }
func showStorageInfo() { func showStorageInfo(w io.Writer, area database.StorageArea) {
fmt.Println("STORAGE SETTINGS") fmt.Fprint(w, "Selected Storage Area: ")
if area.Name == "" {
fmt.Fprint(w, "[None]\n")
return
}
storageBoxDisplay := getInfoDisplay(cardStorageLocation.StorageBox) fmt.Fprintf(w, "%s (%s)\n", area.Name, area.Type)
sourceDisplay := getInfoDisplay(cardStorageLocation.Source) return
conditionDisplay := getInfoDisplay(cardStorageLocation.CardCondition)
fmt.Println("Storage location:", storageBoxDisplay)
fmt.Println("Source:", sourceDisplay)
fmt.Println("Condition:", conditionDisplay)
fmt.Print("\n")
} }
func showCopiesInserted() { func showCopiesInserted() {

View File

@ -0,0 +1,39 @@
package cli
import (
"bytes"
"sevenkeys/database"
"testing"
)
func Test_showStorageInfo_DisplaysNone_IfSelectedStorageAreaIsUnset(t *testing.T) {
expected := "Selected Storage Area: [None]\n"
var output bytes.Buffer
var area database.StorageArea
showStorageInfo(&output, area)
result := output.String()
if result != expected {
t.Errorf("expected %s, got %s", expected, result)
}
}
func Test_showStorageInfo_DisplaysStorageAreaNameAndType_IfSelectedStorageAreaIsSet(t *testing.T) {
expected := "Selected Storage Area: Test A (Box)\n"
var output bytes.Buffer
area := database.StorageArea{
Id: 1,
Name: "Test A",
Type: "Box",
}
showStorageInfo(&output, area)
result := output.String()
if result != expected {
t.Errorf("expected %s, got %s", expected, result)
}
}