print ascii if chafa not available and ascii flag

This commit is contained in:
nekohepott 2026-06-17 04:16:28 +03:00
parent 5ee58d92ec
commit e2a7e77a8f
No known key found for this signature in database
2 changed files with 23 additions and 15 deletions

View File

@ -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 {
if conf.Ascii || (ascii != nil && *ascii) {
logoLines = providers.SplitLines(providers.PrintAsciiLogo(*logoPath))
} else {
logoLines, err = providers.RenderLogoChafa(*logoPath, uint(*width))
if conf.Ascii {
logoLines = providers.SplitLines(providers.PrintAsciiLogo(*logoPath))
} else if err != nil {
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)}

View File

@ -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)