From e6329500b513609fc8530ebae3e558524e57252a Mon Sep 17 00:00:00 2001 From: zomo Date: Thu, 16 Apr 2026 00:13:24 -0500 Subject: [PATCH] STYLE: improved logging output --- go.mod | 23 +++++++++++++++- go.sum | 44 ++++++++++++++++++++++++++++++ loadrooms.go | 5 ++-- main.go | 5 ++-- out.go | 76 +++++++++++++++++++++++++++++++++++++++------------- util.go | 8 ++++++ 6 files changed, 138 insertions(+), 23 deletions(-) diff --git a/go.mod b/go.mod index 31e9e60..358f183 100644 --- a/go.mod +++ b/go.mod @@ -2,4 +2,25 @@ module zomo.dev/bappackage go 1.25.0 -require gopkg.in/ini.v1 v1.67.0 // indirect +require ( + github.com/charmbracelet/lipgloss v1.1.0 + github.com/charmbracelet/log v1.0.0 + gopkg.in/ini.v1 v1.67.0 +) + +require ( + github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect + github.com/charmbracelet/colorprofile v0.2.3-0.20250311203215-f60798e515dc // indirect + github.com/charmbracelet/x/ansi v0.8.0 // indirect + github.com/charmbracelet/x/cellbuf v0.0.13-0.20250311204145-2c3ea96c31dd // indirect + github.com/charmbracelet/x/term v0.2.1 // indirect + github.com/go-logfmt/logfmt v0.6.1 // indirect + github.com/lucasb-eyer/go-colorful v1.2.0 // indirect + github.com/mattn/go-isatty v0.0.20 // indirect + github.com/mattn/go-runewidth v0.0.16 // indirect + github.com/muesli/termenv v0.16.0 // indirect + github.com/rivo/uniseg v0.4.7 // indirect + github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect + golang.org/x/exp v0.0.0-20231006140011-7918f672742d // indirect + golang.org/x/sys v0.30.0 // indirect +) diff --git a/go.sum b/go.sum index a8937af..24cb41a 100644 --- a/go.sum +++ b/go.sum @@ -1,2 +1,46 @@ +github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k= +github.com/aymanbagabas/go-osc52/v2 v2.0.1/go.mod h1:uYgXzlJ7ZpABp8OJ+exZzJJhRNQ2ASbcXHWsFqH8hp8= +github.com/charmbracelet/colorprofile v0.2.3-0.20250311203215-f60798e515dc h1:4pZI35227imm7yK2bGPcfpFEmuY1gc2YSTShr4iJBfs= +github.com/charmbracelet/colorprofile v0.2.3-0.20250311203215-f60798e515dc/go.mod h1:X4/0JoqgTIPSFcRA/P6INZzIuyqdFY5rm8tb41s9okk= +github.com/charmbracelet/lipgloss v1.1.0 h1:vYXsiLHVkK7fp74RkV7b2kq9+zDLoEU4MZoFqR/noCY= +github.com/charmbracelet/lipgloss v1.1.0/go.mod h1:/6Q8FR2o+kj8rz4Dq0zQc3vYf7X+B0binUUBwA0aL30= +github.com/charmbracelet/log v1.0.0 h1:HVVVMmfOorfj3BA9i8X8UL69Hoz9lI0PYwXfJvOdRc4= +github.com/charmbracelet/log v1.0.0/go.mod h1:uYgY3SmLpwJWxmlrPwXvzVYujxis1vAKRV/0VQB7yWA= +github.com/charmbracelet/x/ansi v0.8.0 h1:9GTq3xq9caJW8ZrBTe0LIe2fvfLR/bYXKTx2llXn7xE= +github.com/charmbracelet/x/ansi v0.8.0/go.mod h1:wdYl/ONOLHLIVmQaxbIYEC/cRKOQyjTkowiI4blgS9Q= +github.com/charmbracelet/x/cellbuf v0.0.13-0.20250311204145-2c3ea96c31dd h1:vy0GVL4jeHEwG5YOXDmi86oYw2yuYUGqz6a8sLwg0X8= +github.com/charmbracelet/x/cellbuf v0.0.13-0.20250311204145-2c3ea96c31dd/go.mod h1:xe0nKWGd3eJgtqZRaN9RjMtK7xUYchjzPr7q6kcvCCs= +github.com/charmbracelet/x/term v0.2.1 h1:AQeHeLZ1OqSXhrAWpYUtZyX1T3zVxfpZuEQMIQaGIAQ= +github.com/charmbracelet/x/term v0.2.1/go.mod h1:oQ4enTYFV7QN4m0i9mzHrViD7TQKvNEEkHUMCmsxdUg= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/go-logfmt/logfmt v0.6.1 h1:4hvbpePJKnIzH1B+8OR/JPbTx37NktoI9LE2QZBBkvE= +github.com/go-logfmt/logfmt v0.6.1/go.mod h1:EV2pOAQoZaT1ZXZbqDl5hrymndi4SY9ED9/z6CO0XAk= +github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= +github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU= +github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY= +github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0= +github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= +github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= +github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6TULQc= +github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= +github.com/muesli/termenv v0.16.0 h1:S5AlUN9dENB57rsbnkPyfdGuWIlkmzJjbFf0Tf5FWUc= +github.com/muesli/termenv v0.16.0/go.mod h1:ZRfOIKPFDYQoDFF4Olj7/QJbW60Ol/kL1pU3VfY/Cnk= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= +github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ= +github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= +github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U= +github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U= +github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e h1:JVG44RsyaB9T2KIHavMF/ppJZNG9ZpyihvCd0w101no= +github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e/go.mod h1:RbqR21r5mrJuqunuUZ/Dhy/avygyECGrLceyNeo4LiM= +golang.org/x/exp v0.0.0-20231006140011-7918f672742d h1:jtJma62tbqLibJ5sFQz8bKtEM8rJBtfilJ2qTU199MI= +golang.org/x/exp v0.0.0-20231006140011-7918f672742d/go.mod h1:ldy0pHrwJyGW56pPQzzkH36rKxoZW1tw7ZJpeKx+hdo= +golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.30.0 h1:QjkSwP/36a20jFYWkSue1YwXzLmsV5Gfq7Eiy72C1uc= +golang.org/x/sys v0.30.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA= gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/loadrooms.go b/loadrooms.go index 13480b5..6cd6767 100644 --- a/loadrooms.go +++ b/loadrooms.go @@ -2,10 +2,11 @@ package main import ( "fmt" - "log" "os" "path/filepath" "slices" + + "github.com/charmbracelet/log" ) type RoomFolder struct { @@ -30,7 +31,7 @@ func LoadRoomFolders(roomspath string) ([]RoomFolder, error) { entrypath := filepath.Join(roomspath, entry.Name()) roomfolder, err := loadRoom(entrypath) if err != nil { - log.Printf("ERROR: unable to load directory: %s: %v", entrypath, err) + log.Errorf("unable to load directory: %s: %v", entrypath, err) continue } diff --git a/main.go b/main.go index 6e31911..189baef 100644 --- a/main.go +++ b/main.go @@ -2,7 +2,8 @@ package main import ( "flag" - "log" + + "github.com/charmbracelet/log" ) func main() { @@ -28,7 +29,7 @@ func mainErr() error { err = CheckDuplicateRooms(roomFolders) if err != nil { - log.Printf("Error in room assigmnents: %v", err) + log.Errorf("Error in room assigmnents: %v", err) return nil } diff --git a/out.go b/out.go index 614b4ef..9dc6afd 100644 --- a/out.go +++ b/out.go @@ -6,12 +6,14 @@ import ( "image" "image/color" "image/png" - "log" "os" "path" "path/filepath" "slices" "strings" + + "github.com/charmbracelet/lipgloss" + "github.com/charmbracelet/log" ) //go:embed silence.wav @@ -19,6 +21,18 @@ var SILENCE_WAV []byte const FILEPERM = 0644 +var styleRedtext = lipgloss.NewStyle(). + Foreground(lipgloss.Color("9")) + +var styleYellowtext = lipgloss.NewStyle(). + Foreground(lipgloss.Color("11")) + +var styleGreentext = lipgloss.NewStyle(). + Foreground(lipgloss.Color("10")) + +var padd = lipgloss.NewStyle(). + PaddingLeft(4) + // only deletes DATA/NIGHT_* folders and the CF.ini file // will not touch TITLE or any game files // so this can be ran safely in your game's directory @@ -61,7 +75,9 @@ func emptyOutData(outpath string) error { if len(name) >= len(nightprefix) && name[:len(nightprefix)] == nightprefix { nightpath := path.Join(datapath, entry.Name()) - log.Printf("INFO: removing %s", nightpath) + + log.Info(Renderf(styleRedtext, "removing %s", nightpath)) + err = os.RemoveAll(nightpath) if err != nil { return err @@ -82,7 +98,7 @@ func emptyOutCredits(outpath string) error { return nil } - log.Printf("INFO: removing %s", cfpath) + log.Info(Renderf(styleRedtext, "removing %s", cfpath)) return os.Remove(cfpath) } @@ -96,7 +112,7 @@ func emptyOutCF(outpath string) error { return nil } - log.Printf("INFO: removing %s", cfpath) + log.Info(Renderf(styleRedtext, "removing %s", cfpath)) return os.Remove(cfpath) } @@ -110,6 +126,7 @@ Splash2len=%d `, splash1len, splash2len) // loop through folders + log.Info("") roomcredits := []string{} for _, roomFolder := range roomFolders { err := copyFolder(&roomFolder, outpath) @@ -124,12 +141,12 @@ Splash2len=%d } roomcredits = append(roomcredits, roomFolder.Cfg.ToCredits()) + log.Info("") } // save ini file outini := filepath.Join(outpath, "CF.ini") - log.Println("INFO:") - log.Printf("INFO: Writing %s", outini) + log.Info(Renderf(styleGreentext, "Writing %s", outini)) if err := os.WriteFile(outini, []byte(inistr.String()), FILEPERM); err != nil { return err @@ -139,8 +156,7 @@ Splash2len=%d creditsstring := strings.Join(roomcredits, "\n") outcredits := filepath.Join(outpath, "credits.txt") - log.Println("INFO:") - log.Printf("INFO: Writing %s", outcredits) + log.Info(Renderf(styleGreentext, "Writing %s", outcredits)) return os.WriteFile(outcredits, []byte(creditsstring), FILEPERM) } @@ -148,18 +164,28 @@ Splash2len=%d // doesn't error currently func checkCredits(roomFolder *RoomFolder) error { if roomFolder.Cfg.name == "" { - log.Println("WARNING: room config has no name, defaulting to folder name") + log.Warn(padd.Render(styleYellowtext.Render("room config has no name, defaulting to folder name"))) foldername := filepath.Base(roomFolder.Path) roomFolder.Cfg.name = foldername } if roomFolder.Cfg.credits == "" { - log.Println("WARNING: room config has no credits") + log.Warn(padd.Render(styleYellowtext.Render("room config has no credits"))) } return nil } +var styleTextRoom = lipgloss.NewStyle(). + Bold(true). + Padding(0, 1). + Background(lipgloss.Color("10")). + Foreground(lipgloss.Color("0")) + +var styleTextCopy = lipgloss.NewStyle(). + Bold(true). + Foreground(lipgloss.Color("10")) + func copyFolder(roomFolder *RoomFolder, outpath string) error { nightdir := fmt.Sprintf("NIGHT_%d", roomFolder.Cfg.night) roomdir := fmt.Sprintf("ROOM_%d", roomFolder.Cfg.room) @@ -168,11 +194,26 @@ func copyFolder(roomFolder *RoomFolder, outpath string) error { os.MkdirAll(roomoutpath, FILEPERM) - log.Println("INFO:") - log.Printf("INFO: Copying %s", roomFolder.Path) - log.Printf("INFO: to %s", roomoutpath) + // print room info + name := roomFolder.Cfg.name + if name == "" { + name = "MISSING NAME" + } + textRoom := Renderf(styleTextRoom, "Room - %s", name) + log.Info(textRoom) + + textCopy1 := styleTextCopy.Render("Copying From") + textCopy2 := styleTextCopy.Render(" To") + + textCopy1Comb := fmt.Sprintf("%s %s", textCopy1, roomFolder.Path) + textCopy2Comb := fmt.Sprintf("%s %s", textCopy2, roomoutpath) + + log.Info(padd.Render(textCopy1Comb)) + log.Info(padd.Render(textCopy2Comb)) + + if roomFolder.IsDefaultCfg { - log.Println("INFO: room.ini was not found, using default settings") + log.Info(padd.Render(styleYellowtext.Render("room.ini was not found, using default settings"))) } entries, err := os.ReadDir(roomFolder.Path) @@ -211,7 +252,7 @@ func copyFolder(roomFolder *RoomFolder, outpath string) error { } if len(extraRequiredImages) > 0 { - log.Printf("INFO: necessary optional images will use a transparent file: %v", extraRequiredImages) + log.Info(Renderf(padd, "necessary optional images will use a transparent file: %v", extraRequiredImages)) transparent := image.NewRGBA(image.Rectangle{image.Point{0, 0}, image.Point{1, 1}}) transparent.Set(0, 0, color.RGBA{0xff, 0xff, 0xff, 0x01}) @@ -237,15 +278,14 @@ func copyFolder(roomFolder *RoomFolder, outpath string) error { // ensure layer_frames is 1 if it's not included if strings.ToUpper(imagename) == "LAYER" && roomFolder.Cfg.layerFrames != 1 { - log.Printf( "WARNING: room was configured to have %d layer frames, but no LAYER image exists", roomFolder.Cfg.layerFrames) - log.Println("WARNING: setting layer_frames=1") + log.Warn(padd.Render(Renderf(styleYellowtext, "room was configured to have %d layer frames, but no LAYER image exists: setting layer_frames=1", roomFolder.Cfg.layerFrames))) roomFolder.Cfg.layerFrames = 1 } } } if len(extraRequiredAudio) > 0 { - log.Printf("INFO: necessary optional audios will use a silent file: %v", extraRequiredAudio) + log.Info(Renderf(padd, "necessary optional audios will use a silent file: %v", extraRequiredAudio)) for _, audioname := range extraRequiredAudio { audiopath := path.Join(roomoutpath, audioname+".wav") diff --git a/util.go b/util.go index a9bb00b..2e35561 100644 --- a/util.go +++ b/util.go @@ -2,10 +2,13 @@ package main import ( "errors" + "fmt" "io/fs" "os" "path" "strings" + + "github.com/charmbracelet/lipgloss" ) func Exists(p ...string) (bool, error) { @@ -27,3 +30,8 @@ func SplitExt(filename string) (string, string) { } return name, ext } + +func Renderf(style lipgloss.Style, format string, v ...any) string { + str := fmt.Sprintf(format, v...) + return style.Render(str) +}