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"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/exhq/neowofetch/data"
|
||||||
"github.com/exhq/neowofetch/utils"
|
"github.com/exhq/neowofetch/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -62,7 +63,7 @@ func handlePrint(action, format string, rest string) {
|
||||||
} else if action == "info" || action == "infoln" {
|
} else if action == "info" || action == "infoln" {
|
||||||
switch rest {
|
switch rest {
|
||||||
case "distro":
|
case "distro":
|
||||||
utils.CutePrint(getDistro(), format)
|
utils.CutePrint(data.GetDistro(), format)
|
||||||
case "username":
|
case "username":
|
||||||
utils.CutePrint(getUsername(), format)
|
utils.CutePrint(getUsername(), format)
|
||||||
case "uptime":
|
case "uptime":
|
||||||
|
@ -100,27 +101,6 @@ func getUsername() string {
|
||||||
return strings.Replace(string(shell), "\n", "", -1)
|
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 {
|
func getKernel() string {
|
||||||
cmd := exec.Command("uname", "-r")
|
cmd := exec.Command("uname", "-r")
|
||||||
kernel, err := cmd.Output()
|
kernel, err := cmd.Output()
|
||||||
|
@ -233,7 +213,7 @@ func getColorPalette() {
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
utils.Initargs()
|
utils.Initargs()
|
||||||
utils.CutePrintInit(utils.Getascii(getDistro()))
|
utils.CutePrintInit()
|
||||||
handleConfig()
|
handleConfig()
|
||||||
utils.CutePrintEnd()
|
utils.CutePrintEnd()
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@ import (
|
||||||
var args []string
|
var args []string
|
||||||
var shoulduwuify bool = true
|
var shoulduwuify bool = true
|
||||||
var noascii bool = false
|
var noascii bool = false
|
||||||
|
var usepng bool = false
|
||||||
|
|
||||||
func Initargs() {
|
func Initargs() {
|
||||||
args = os.Args[1:]
|
args = os.Args[1:]
|
||||||
|
@ -18,6 +19,8 @@ func Initargs() {
|
||||||
shoulduwuify = false
|
shoulduwuify = false
|
||||||
case "--noascii":
|
case "--noascii":
|
||||||
noascii = true
|
noascii = true
|
||||||
|
case "--usepng":
|
||||||
|
usepng = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,7 @@ func Getascii(name string) string {
|
||||||
/_-'' ''-_\ `
|
/_-'' ''-_\ `
|
||||||
|
|
||||||
switch name {
|
switch name {
|
||||||
case "Arch Linux":
|
case "arch":
|
||||||
return arch
|
return arch
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -1,9 +1,14 @@
|
||||||
package utils
|
package utils
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/base64"
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/exhq/neowofetch/data"
|
||||||
|
"github.com/exhq/neowofetch/images"
|
||||||
)
|
)
|
||||||
|
|
||||||
func rgb(r, g, b int) string {
|
func rgb(r, g, b int) string {
|
||||||
|
@ -38,10 +43,20 @@ var isInProgressLine = false
|
||||||
var logoLines []string
|
var logoLines []string
|
||||||
var logoWidth int
|
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 {
|
if noascii {
|
||||||
logo = ""
|
logo = ""
|
||||||
}
|
}
|
||||||
|
if usepng {
|
||||||
|
pngData = images.DistroImages[dist]
|
||||||
|
logo = strings.Repeat(" ", pngWidth) + strings.Repeat("\n", pngHeight)
|
||||||
|
}
|
||||||
logoLines = strings.Split(logo, "\n")
|
logoLines = strings.Split(logo, "\n")
|
||||||
logoWidth = 0
|
logoWidth = 0
|
||||||
for _, v := range logoLines {
|
for _, v := range logoLines {
|
||||||
|
@ -57,13 +72,13 @@ func printLogoIfAtBeginningOfNewLine() {
|
||||||
isInProgressLine = true
|
isInProgressLine = true
|
||||||
if logoIndex < len(logoLines) {
|
if logoIndex < len(logoLines) {
|
||||||
logoLine := logoLines[logoIndex]
|
logoLine := logoLines[logoIndex]
|
||||||
logoIndex += 1
|
|
||||||
logoLineLength := len([]rune(logoLine))
|
logoLineLength := len([]rune(logoLine))
|
||||||
padding := strings.Repeat(" ", logoWidth-logoLineLength)
|
padding := strings.Repeat(" ", logoWidth-logoLineLength)
|
||||||
fmt.Printf("%s%s", logoLine, padding)
|
fmt.Printf("%s%s", logoLine, padding)
|
||||||
} else {
|
} else {
|
||||||
fmt.Printf("%s", strings.Repeat(" ", logoWidth))
|
fmt.Printf("%s", strings.Repeat(" ", logoWidth))
|
||||||
}
|
}
|
||||||
|
logoIndex += 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -102,15 +117,11 @@ func parseFormat(format string) (parsedFormat Format) {
|
||||||
switch v {
|
switch v {
|
||||||
case "italic":
|
case "italic":
|
||||||
parsedFormat.colorFormat += "\x1b[3m"
|
parsedFormat.colorFormat += "\x1b[3m"
|
||||||
break
|
|
||||||
case "bold":
|
case "bold":
|
||||||
parsedFormat.colorFormat += "\x1b1"
|
parsedFormat.colorFormat += "\x1b1"
|
||||||
break
|
|
||||||
case "nouwu":
|
case "nouwu":
|
||||||
parsedFormat.noUwuOverride = true
|
parsedFormat.noUwuOverride = true
|
||||||
break
|
|
||||||
case "*":
|
case "*":
|
||||||
break
|
|
||||||
default:
|
default:
|
||||||
//println("Unknown format code: ", v)
|
//println("Unknown format code: ", v)
|
||||||
}
|
}
|
||||||
|
@ -145,4 +156,12 @@ func CutePrintEnd() {
|
||||||
for logoIndex < len(logoLines) {
|
for logoIndex < len(logoLines) {
|
||||||
CuteNewLine()
|
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