From 1fe82665ad9ab4fe4231704230c384fab5b1c35b Mon Sep 17 00:00:00 2001 From: nekohepott Date: Wed, 17 Jun 2026 04:16:24 +0300 Subject: [PATCH] image support!!! --- .gitignore | 3 +- PKGBUILD | 2 +- README.md | 49 +++++++++++++++---- assets/arch.png | 3 ++ assets/debian.png | 3 ++ assets/linux.png | 3 ++ assets/nixos.png | 3 ++ assets/screenshot.png | 4 +- go.mod | 7 +++ go.sum | 8 ++++ main.go | 106 +++++++++++++++++++++++++++++++----------- 11 files changed, 151 insertions(+), 40 deletions(-) create mode 100644 assets/arch.png create mode 100644 assets/debian.png create mode 100644 assets/linux.png create mode 100644 assets/nixos.png create mode 100644 go.sum diff --git a/.gitignore b/.gitignore index 75088cf..e88f8fe 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,5 @@ result/ ./src ./pkg ./goGoFetch -/gogofetch-git-r14.ff1fcf9-1-x86_64.pkg.tar.zst \ No newline at end of file +/gogofetch-git-r14.ff1fcf9-1-x86_64.pkg.tar.zst +./gogofetch-git \ No newline at end of file diff --git a/PKGBUILD b/PKGBUILD index 5c121cb..6559ffb 100644 --- a/PKGBUILD +++ b/PKGBUILD @@ -7,7 +7,7 @@ pkgname=gogofetch-git pkgver=r14.ff1fcf9 pkgrel=2 -pkgdesc="fetch made with C++ rewritten to go for no reason" +pkgdesc="Fetch written in Go with image support" arch=('x86_64') url="git+https://codeberg.org/nekohepott/goGoFetch.git" license=('MIT') diff --git a/README.md b/README.md index 3b48bdc..974ade3 100644 --- a/README.md +++ b/README.md @@ -1,15 +1,33 @@ -# Build -to build: +# Fetch written in Go with image support (only for foot and kitty) + +![Fetch image](assets/screenshot.png "fetch") + +# Install +you can get gogofetch on AUR! +```bash +yay -S gogofetch-git ``` -go build main.go + +# Usage +basic usage: +```bash +gogofetch ``` -to run: +to show custom image (only png supported btw): +```bash +gogofetch -i *absolute_path* ``` -./main +to show custom image and set custom width: +```bash +gogofetch -i *absolute_path* -w 250 +``` +to show help message: +```bash +gogofetch -h ``` # NixOS -credits to melvi for this +credits to melvi for flake to build with nix: ```bash @@ -19,7 +37,6 @@ to run with nix: ``` nix run ``` - to install with nixos: 1. Add to inputs: @@ -40,5 +57,19 @@ home.packages = [ ``` 3. Run rebuild and then you can run fetch with *gogofetch* command -# Screenshots -![Fetch image](assets/screenshot.png "fetch") \ No newline at end of file + +# Build +to build: +``` +git clone https://codeberg.org/nekohepott/goGoFetch +cd goGoFetch +go build main.go +``` +and run: +``` +./main +``` + + + + diff --git a/assets/arch.png b/assets/arch.png new file mode 100644 index 0000000..d3373c4 --- /dev/null +++ b/assets/arch.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:da3e518a7984b9dbace1c3de8c2ccdda0b7750558e4650ffbc45a50ebbb33072 +size 96910 diff --git a/assets/debian.png b/assets/debian.png new file mode 100644 index 0000000..1887729 --- /dev/null +++ b/assets/debian.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f3abbf6d15a7cfe184bf8a2bb85e82bce205251ee2ae41db02a65e35a199f16f +size 20619 diff --git a/assets/linux.png b/assets/linux.png new file mode 100644 index 0000000..7624f07 --- /dev/null +++ b/assets/linux.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f9eec30e695dba0969c96c0883e5d30af0429713b49923648b38bceabda77bfb +size 49760 diff --git a/assets/nixos.png b/assets/nixos.png new file mode 100644 index 0000000..ab339cb --- /dev/null +++ b/assets/nixos.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a1535c35f416ab1c58124d1ebbf698e478695d2dfee925f4ce1409335baec8cc +size 179310 diff --git a/assets/screenshot.png b/assets/screenshot.png index cd2c2e1..69ddf36 100644 --- a/assets/screenshot.png +++ b/assets/screenshot.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:f4777230e59dfd0935b6a0bd12f805c873875a305dcfadc72b22807bb7a0c77a -size 157554 +oid sha256:0c729c0c0d0d6426dc68adf3d213ac2104f0735f98edc8dc760d597a1cc0d678 +size 159286 diff --git a/go.mod b/go.mod index 821721a..72deba9 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,10 @@ module goGoFetch go 1.26 + +require github.com/mattn/go-sixel v0.0.8 + +require ( + github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 // indirect + github.com/soniakeys/quant v1.0.0 // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..5cc24ad --- /dev/null +++ b/go.sum @@ -0,0 +1,8 @@ +github.com/BurntSushi/toml v1.6.0 h1:dRaEfpa2VI55EwlIW72hMRHdWouJeRF7TPYhI+AUQjk= +github.com/BurntSushi/toml v1.6.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho= +github.com/mattn/go-sixel v0.0.8 h1:H0bBGQVOJoSvzvtTgCInxvg1IZiNlTcIIIx8A6uvjpQ= +github.com/mattn/go-sixel v0.0.8/go.mod h1:wbDSbrwpykVI1qEHyjZYsDgaJTwpVg9wSwmmh2slnBw= +github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 h1:zYyBkD/k9seD2A7fsi6Oo2LfFZAehjjQMERAvZLEDnQ= +github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646/go.mod h1:jpp1/29i3P1S/RLdc7JQKbRpFeM1dOBd8T9ki5s+AY8= +github.com/soniakeys/quant v1.0.0 h1:N1um9ktjbkZVcywBVAAYpZYSHxEfJGzshHCxx/DaI0Y= +github.com/soniakeys/quant v1.0.0/go.mod h1:HI1k023QuVbD4H8i9YdfZP2munIHU4QpjsImz6Y6zds= diff --git a/main.go b/main.go index ce5eb38..0b9b197 100644 --- a/main.go +++ b/main.go @@ -2,22 +2,37 @@ package main import ( "bufio" + "bytes" + "encoding/base64" + "flag" "fmt" + "image" + "image/png" + _ "image/png" "os" "os/exec" "regexp" "strconv" "strings" + + "github.com/mattn/go-sixel" + "github.com/nfnt/resize" ) const ( - Reset = "\033[0m" - GreenBold = "\033[1;32m" - BlueBright = "\033[94m" + Reset = "\033[0m" + Blue = "\033[1;34m" ) var dist string +var logoMap = map[string]string{ + "Arch Linux": "assets/arch.png", + "Debian": "assets/debian.png", + "NixOS": "assets/nixos.png", + "default": "assets/linux.png", +} + func getDist() string { f, _ := os.Open("/etc/os-release") defer func(f *os.File) { @@ -161,24 +176,51 @@ func getPkgs() string { return "unknown" } -func getAscii() string { - var ascii string - if strings.HasPrefix(dist, "Arch") { - content := " _ _ _\n /\\ | | | | (_)\n / \\ _ __ ___| |__ | | _ _ __ _ ___ __\n / /\\ \\ | '__/ __| '_ \\ | | | | '_ \\| | | \\ \\/ /\n / ____ \\| | | (__| | | | | |____| | | | | |_| |> <\n /_/ \\_\\_| \\___|_| |_| |______|_|_| |_|\\__,_/_/\\_\\\n" - ascii = fmt.Sprintf(content) - return ascii +//func getAscii() string { +// var ascii string +// if strings.HasPrefix(dist, "Arch") { +// content := " _ _ _\n /\\ | | | | (_)\n / \\ _ __ ___| |__ | | _ _ __ _ ___ __\n / /\\ \\ | '__/ __| '_ \\ | | | | '_ \\| | | \\ \\/ /\n / ____ \\| | | (__| | | | | |____| | | | | |_| |> <\n /_/ \\_\\_| \\___|_| |_| |______|_|_| |_|\\__,_/_/\\_\\\n" +// ascii = fmt.Sprintf(content) +// return ascii +// } +// if strings.HasPrefix(dist, "Debian") { +// content := " _____ _ _\n | __ \\ | | (_)\n | | | | ___ | |__ _ __ _ _ __\n | | | | / _ \\ | '_ \\ | | / _` | | '_ \\\n | |__| | | __/ | |_) | | | | (_| | | | | |\n |_____/ \\___| |_.__/ |_| \\__,_| |_| |_|\n" +// ascii = fmt.Sprintf(content) +// return ascii +// } +// if strings.HasPrefix(dist, "NixOS") { +// content := " _ _ _ ____ _____\n | \\ | (_) / __ \\ / ____|\n | \\| |___ _| | | | (___\n | . ` | \\ \\/ / | | |\\___ \\\n | |\\ | |> <| |__| |____) |\n |_| \\_|_/_/\\_\\\\____/|_____/\n" +// ascii = fmt.Sprintf(content) +// return ascii +// } +// return "unknown" +//} + +func printLogo(path string, Width uint) { + file, _ := os.Open(path) + defer func(file *os.File) { + err := file.Close() + if err != nil { + return + } + }(file) + img, _, _ := image.Decode(file) + resizedImg := resize.Resize(Width, 0, img, resize.Lanczos3) + if os.Getenv("KITTY_PID") != "" || os.Getenv("TERM") == "xterm-kitty" { + var buf bytes.Buffer + err := png.Encode(&buf, resizedImg) + if err != nil { + return + } + enc := base64.StdEncoding.EncodeToString(buf.Bytes()) + fmt.Printf("\033_Gf=100,a=T;%s\033\\\n", enc) + } else { + err := sixel.NewEncoder(os.Stdout).Encode(resizedImg) + fmt.Printf("\n") + if err != nil { + return + } } - if strings.HasPrefix(dist, "Debian") { - content := " _____ _ _\n | __ \\ | | (_)\n | | | | ___ | |__ _ __ _ _ __\n | | | | / _ \\ | '_ \\ | | / _` | | '_ \\\n | |__| | | __/ | |_) | | | | (_| | | | | |\n |_____/ \\___| |_.__/ |_| \\__,_| |_| |_|\n" - ascii = fmt.Sprintf(content) - return ascii - } - if strings.HasPrefix(dist, "NixOS") { - content := " _ _ _ ____ _____\n | \\ | (_) / __ \\ / ____|\n | \\| |___ _| | | | (___\n | . ` | \\ \\/ / | | |\\___ \\\n | |\\ | |> <| |__| |____) |\n |_| \\_|_/_/\\_\\\\____/|_____/\n" - ascii = fmt.Sprintf(content) - return ascii - } - return "unknown" } func main() { @@ -186,9 +228,14 @@ func main() { Label string Value string } + dist := getDist() + defaultLogo, ok := logoMap[dist] + if !ok { + defaultLogo = logoMap["default"] + } stats := []Info{ - {"dist", getDist()}, + {"dist", dist}, {"host", getHostname()}, {"cpu", getCpu()}, {"krnl", getKernel()}, @@ -196,14 +243,19 @@ func main() { {"gpu", getGpu()}, {"pkgs", getPkgs()}, } - fmt.Print(BlueBright) - fmt.Printf(getAscii()) - fmt.Print(Reset) - fmt.Printf("\n") - fmt.Println("---------------------------") + + logoPath := flag.String("i", defaultLogo, "Absolute or relative path to the logo image (only png)") + width := flag.Int("w", 200, "Logo width in lines (400 IS MAXIMUM FOR KITTY VALUES ABOVE WILL CRASH TERMINAL)") + flag.Parse() + if _, err := os.Stat(*logoPath); os.IsNotExist(err) { + fmt.Printf("Image '%s' not found\n", *logoPath) + return + } + + printLogo(*logoPath, uint(*width)) for _, s := range stats { - fmt.Printf("> %s%s%s: %s\n", GreenBold, s.Label, Reset, s.Value) + fmt.Printf("~ %s%s%s: %s\n", Blue, s.Label, Reset, s.Value) } }