Skip to content

Commit

Permalink
Sort lib alphabetically in console
Browse files Browse the repository at this point in the history
  • Loading branch information
sergystepanov committed Feb 20, 2024
1 parent 1452317 commit 9308e1b
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions pkg/games/library.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"io/fs"
"path/filepath"
"sort"
"strings"
"sync"
"time"
Expand Down Expand Up @@ -259,8 +260,17 @@ func getMetadata(path string, basePath string) GameMetadata {
// dumpLibrary printouts the current library snapshot of games
func (lib *library) dumpLibrary() {
var gameList strings.Builder
for _, game := range lib.games {
gameList.WriteString(fmt.Sprintf(" %5s %s (%s)\n", game.System, game.Name, game.Path))

// oof
keys := make([]string, 0, len(lib.games))
for k := range lib.games {
keys = append(keys, k)
}
sort.Strings(keys)

for _, k := range keys {
game := lib.games[k]
gameList.WriteString(fmt.Sprintf(" %7s %s (%s)\n", game.System, game.Name, game.Path))
}

lib.log.Debug().Msgf("Lib dump\n"+
Expand Down

0 comments on commit 9308e1b

Please sign in to comment.