From e2a7e77a8fe0f8eaf4cb18d80f7be240f090ab14 Mon Sep 17 00:00:00 2001 From: nekohepott Date: Wed, 17 Jun 2026 04:16:28 +0300 Subject: [PATCH] print ascii if chafa not available and ascii flag --- src/main.go | 21 ++++++++++++++++----- src/providers/logo.go | 17 +++++++---------- 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/src/main.go b/src/main.go index 60274b0..43e0f25 100644 --- a/src/main.go +++ b/src/main.go @@ -14,6 +14,7 @@ func main() { width := flag.Int("w", 190, "Logo width in lines") logoPath := flag.String("l", "", "Path to the logo") logoPos := flag.String("p", "", "Logo position: left or right") + ascii := flag.Bool("a", false, "Use ASCII art for logo") flag.Parse() if *resetConfig { @@ -38,7 +39,7 @@ func main() { if conf.CustomLogo != "" { defaultLogo = conf.CustomLogo } else { - defaultLogo = providers.GetLogo(distID) + defaultLogo = providers.GetLogo(distID, conf, ascii) } if *logoPath == "" { @@ -129,11 +130,21 @@ func main() { var logoLines []string if _, err := os.Stat(*logoPath); err == nil { - logoLines, err = providers.RenderLogoChafa(*logoPath, uint(*width)) - if conf.Ascii { - logoLines = providers.SplitLines(providers.PrintAsciiLogo(*logoPath)) - } else if err != nil { + if conf.Ascii || (ascii != nil && *ascii) { logoLines = providers.SplitLines(providers.PrintAsciiLogo(*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") + } + } } } else { logoLines = []string{fmt.Sprintf("Logo not found at: %s", *logoPath)} diff --git a/src/providers/logo.go b/src/providers/logo.go index fde0fcb..a010a1f 100644 --- a/src/providers/logo.go +++ b/src/providers/logo.go @@ -14,24 +14,21 @@ import ( var ansiEscapeRe = regexp.MustCompile(`\x1b\[[0-9;?]*[ -/]*[@-~]`) -func GetLogo(id string) string { +func GetLogo(id string, conf Config, ascii *bool) string { knownIDs := []string{"arch", "nixos", "debian", "alpine", "gentoo", "void", "chimera", "cachyos", "artix", "endeavouros", "fedora", "kali", "linuxmint", "manjaro", "ubuntu", "opensuse"} if slices.Contains(knownIDs, id) { + if conf.Ascii || (ascii != nil && *ascii) == true { + return path.Join("logos", id+".txt") + } return path.Join("logos", id+".png") } + if conf.Ascii || (ascii != nil && *ascii) == true { + return "logos/linux.txt" + } return "logos/linux.png" } -func GetAscii(id string) string { - knownIDs := []string{"arch", "nixos", "debian"} - if slices.Contains(knownIDs, id) { - return path.Join("logos", id+".txt") - } - return "logos/linux.txt" -} - func PrintAsciiLogo(path string) string { - path = GetAscii(id) content, err := os.ReadFile(path) if err != nil { return fmt.Sprintf("Error: Could not read ASCII file at %s\n", path)