From 3a1873a74797230947df149291639c2128215cf1 Mon Sep 17 00:00:00 2001 From: nekohepott Date: Wed, 17 Jun 2026 04:16:28 +0300 Subject: [PATCH] remove reuse --- src/main.go | 34 +++++++++++++++------------------- 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/src/main.go b/src/main.go index 9889cd8..6c44b78 100644 --- a/src/main.go +++ b/src/main.go @@ -128,6 +128,19 @@ func main() { statsLines = append(statsLines, fmt.Sprintf("%s %s%s%s: %s", key, statColor, info.Label, providers.Reset, info.Value)) } + fallbackToAscii := func(path *string) []string { + parts := strings.Split(*path, ".") + if len(parts) > 1 { + parts[len(parts)-1] = "txt" + } + *path = strings.Join(parts, ".") + + if !strings.HasSuffix(*path, ".txt") { + fmt.Println("chafa binary not found, to print images please install chafa") + } + return providers.SplitLines(providers.PrintAsciiLogo(*path)) + } + var logoLines []string if _, err := os.Stat(*logoPath); err == nil { if conf.Ascii || (ascii != nil && *ascii) { @@ -136,28 +149,11 @@ func main() { if err := providers.RenderLogoChafaAnimated(*logoPath, uint(*width), statsLines, position); err == nil { return } - - parts := strings.Split(*logoPath, ".") - if len(parts) > 1 { - parts[1] = "txt" - } - *logoPath = strings.Join(parts, ".") - logoLines = providers.SplitLines(providers.PrintAsciiLogo(*logoPath)) - if strings.Contains(*logoPath, ".txt") != true { - fmt.Printf("chafa binary not found, to print images please install chafa\n") - } + logoLines = fallbackToAscii(logoPath) } else { logoLines, err = providers.RenderLogoChafa(*logoPath, uint(*width)) if err != nil { - parts := strings.Split(*logoPath, ".") - if len(parts) > 1 { - parts[1] = "txt" - } - *logoPath = strings.Join(parts, ".") - logoLines = providers.SplitLines(providers.PrintAsciiLogo(*logoPath)) - if strings.Contains(*logoPath, ".txt") != true { - fmt.Printf("chafa binary not found, to print images please install chafa\n") - } + logoLines = fallbackToAscii(logoPath) } } } else {