diff --git a/arch.png b/arch.png new file mode 100644 index 0000000..12c71b5 Binary files /dev/null and b/arch.png differ diff --git a/data/data.go b/data/data.go new file mode 100644 index 0000000..35192d5 --- /dev/null +++ b/data/data.go @@ -0,0 +1,29 @@ +package data + +import ( + "fmt" + "os" + "strings" +) + +func GetDistro() string { + return GetDistroVariable("PRETTY_NAME") +} +func GetDistroVariable(varname string) string { + distro, err := os.ReadFile("/etc/os-release") + if err != nil { + fmt.Println("Error:", err) + os.Exit(0) + } + distro_list := strings.Split(string(distro), "\n") + distro_tuples := make(map[string]string) + for _, v := range distro_list { + if strings.Contains(v, "=") { + kv := strings.Split(v, "=") + kv[0] = strings.TrimSpace(kv[0]) + kv[1] = strings.TrimSpace(kv[1]) + distro_tuples[kv[0]] = kv[1] + } + } + return strings.Trim(distro_tuples[varname], "\"") +} diff --git a/images/arch.png b/images/arch.png new file mode 100644 index 0000000..12c71b5 Binary files /dev/null and b/images/arch.png differ diff --git a/images/images.go b/images/images.go new file mode 100644 index 0000000..ced986e --- /dev/null +++ b/images/images.go @@ -0,0 +1,14 @@ +package images + +import _ "embed" + +//go:embed arch.png +var ArchArt []byte + +//go:embed ubuntu.jpg +var UbuntuArt []byte + +var DistroImages = map[string][]byte{ + "arch": ArchArt, + "ubuntu": UbuntuArt, +} diff --git a/images/ubuntu.jpg b/images/ubuntu.jpg new file mode 100644 index 0000000..0c32106 Binary files /dev/null and b/images/ubuntu.jpg differ diff --git a/main.go b/main.go index 06bbb6f..b3ff92d 100644 --- a/main.go +++ b/main.go @@ -9,6 +9,7 @@ import ( "strconv" "strings" + "github.com/exhq/neowofetch/data" "github.com/exhq/neowofetch/utils" ) @@ -62,7 +63,7 @@ func handlePrint(action, format string, rest string) { } else if action == "info" || action == "infoln" { switch rest { case "distro": - utils.CutePrint(getDistro(), format) + utils.CutePrint(data.GetDistro(), format) case "username": utils.CutePrint(getUsername(), format) case "uptime": @@ -100,27 +101,6 @@ func getUsername() string { return strings.Replace(string(shell), "\n", "", -1) } -func getDistro() string { - distro, err := os.Open("/etc/os-release") - if err != nil { - fmt.Println("Error:", err) - os.Exit(0) - } - distro_info := make([]byte, 1024) - distro.Read(distro_info) - defer distro.Close() - distro_list := strings.Split(string(distro_info), "\n") - distro_tuples := make(map[string]string) - for _, v := range distro_list { - if strings.Contains(v, "=") { - kv := strings.Split(v, "=") - kv[0] = strings.TrimSpace(kv[0]) - kv[1] = strings.TrimSpace(kv[1]) - distro_tuples[kv[0]] = kv[1] - } - } - return strings.Trim(distro_tuples["PRETTY_NAME"], "\"") -} func getKernel() string { cmd := exec.Command("uname", "-r") kernel, err := cmd.Output() @@ -233,7 +213,7 @@ func getColorPalette() { func main() { utils.Initargs() - utils.CutePrintInit(utils.Getascii(getDistro())) + utils.CutePrintInit() handleConfig() utils.CutePrintEnd() } diff --git a/utils/args.go b/utils/args.go index 978d0d1..7755377 100644 --- a/utils/args.go +++ b/utils/args.go @@ -8,6 +8,7 @@ import ( var args []string var shoulduwuify bool = true var noascii bool = false +var usepng bool = false func Initargs() { args = os.Args[1:] @@ -18,6 +19,8 @@ func Initargs() { shoulduwuify = false case "--noascii": noascii = true + case "--usepng": + usepng = true } } } diff --git a/utils/asciiarts.go b/utils/asciiarts.go index f3f1eda..1f0af23 100644 --- a/utils/asciiarts.go +++ b/utils/asciiarts.go @@ -15,7 +15,7 @@ func Getascii(name string) string { /_-'' ''-_\ ` switch name { - case "Arch Linux": + case "arch": return arch default: diff --git a/utils/printing.go b/utils/printing.go index cc47d0e..8b68a73 100644 --- a/utils/printing.go +++ b/utils/printing.go @@ -1,9 +1,14 @@ package utils import ( + "encoding/base64" "fmt" "math/rand" + "os" "strings" + + "github.com/exhq/neowofetch/data" + "github.com/exhq/neowofetch/images" ) func rgb(r, g, b int) string { @@ -38,10 +43,20 @@ var isInProgressLine = false var logoLines []string var logoWidth int -func CutePrintInit(logo string) { +var pngWidth = 12 +var pngHeight = 12 +var pngData []byte + +func CutePrintInit() { + dist := data.GetDistroVariable("ID") + logo := Getascii(dist) if noascii { logo = "" } + if usepng { + pngData = images.DistroImages[dist] + logo = strings.Repeat(" ", pngWidth) + strings.Repeat("\n", pngHeight) + } logoLines = strings.Split(logo, "\n") logoWidth = 0 for _, v := range logoLines { @@ -57,13 +72,13 @@ func printLogoIfAtBeginningOfNewLine() { isInProgressLine = true if logoIndex < len(logoLines) { logoLine := logoLines[logoIndex] - logoIndex += 1 logoLineLength := len([]rune(logoLine)) padding := strings.Repeat(" ", logoWidth-logoLineLength) fmt.Printf("%s%s", logoLine, padding) } else { fmt.Printf("%s", strings.Repeat(" ", logoWidth)) } + logoIndex += 1 } } @@ -102,15 +117,11 @@ func parseFormat(format string) (parsedFormat Format) { switch v { case "italic": parsedFormat.colorFormat += "\x1b[3m" - break case "bold": parsedFormat.colorFormat += "\x1b1" - break case "nouwu": parsedFormat.noUwuOverride = true - break case "*": - break default: //println("Unknown format code: ", v) } @@ -145,4 +156,12 @@ func CutePrintEnd() { for logoIndex < len(logoLines) { CuteNewLine() } + if usepng { + fmt.Printf("\x1b[%dA", logoIndex) + fmt.Printf("\x1b]1337;File=inline=1;width=%d;height=%d:", pngWidth, pngHeight) + enc := base64.NewEncoder(base64.StdEncoding, os.Stdout) + enc.Write(images.DistroImages["arch"]) + enc.Close() + fmt.Println("\a") + } }