Add images to uwufetch
This commit is contained in:
parent
0c1858e6bd
commit
c771c734f0
9 changed files with 75 additions and 30 deletions
BIN
arch.png
Normal file
BIN
arch.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 139 KiB |
29
data/data.go
Normal file
29
data/data.go
Normal file
|
@ -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], "\"")
|
||||
}
|
BIN
images/arch.png
Normal file
BIN
images/arch.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 139 KiB |
14
images/images.go
Normal file
14
images/images.go
Normal file
|
@ -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,
|
||||
}
|
BIN
images/ubuntu.jpg
Normal file
BIN
images/ubuntu.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 40 KiB |
26
main.go
26
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()
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@ func Getascii(name string) string {
|
|||
/_-'' ''-_\ `
|
||||
|
||||
switch name {
|
||||
case "Arch Linux":
|
||||
case "arch":
|
||||
return arch
|
||||
|
||||
default:
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue