chafa is now used for logo rendering

This commit is contained in:
nekohepott 2026-06-17 04:16:24 +03:00
parent 85d056e557
commit 88d3d9cd12
No known key found for this signature in database
7 changed files with 33 additions and 41 deletions

View File

@ -11,7 +11,7 @@ pkgdesc="Fetch written in Go with image support"
arch=('x86_64')
url="git+https://codeberg.org/nekohepott/goGoFetch.git"
license=('MIT')
depends=('glibc')
depends=('glibc' 'chafa')
makedepends=('git' 'go')
checkdepends=()
optdepends=()

View File

@ -1,4 +1,4 @@
# Fetch written in Go with image support (only for foot and kitty)
# Fetch written in Go with image support
![Fetch image](assets/screenshot.png "fetch")
@ -7,6 +7,7 @@ you can get gogofetch on AUR!
```bash
yay -S gogofetch-git
```
also chafa is dependency for gogofetch
# Usage
basic usage:
@ -15,11 +16,11 @@ gogofetch
```
to show custom image (only png supported btw):
```bash
gogofetch -i *absolute_path*
gogofetch -l *absolute_path*
```
to show custom image and set custom width:
```bash
gogofetch -i *absolute_path* -w 250
gogofetch -l *absolute_path* -w 250
```
to show help message:
```bash
@ -70,6 +71,12 @@ and run:
./main
```
# Some screenshots
![alacritty](assets/alacritty.png "alacritty") alacritty
![foot](assets/foot.png "foot") foot
![necrokall](assets/xterm.png "xterm") xterm

BIN
assets/alacritty.png (Stored with Git LFS) Normal file

Binary file not shown.

BIN
assets/foot.png (Stored with Git LFS) Normal file

Binary file not shown.

BIN
assets/nixos.png (Stored with Git LFS)

Binary file not shown.

BIN
assets/xterm.png (Stored with Git LFS) Normal file

Binary file not shown.

44
main.go
View File

@ -2,21 +2,14 @@ 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 (
@ -51,7 +44,7 @@ func getDist() string {
return dist
}
}
return "unsupported distro"
return "unknown distro :("
}
func getRam() string {
@ -196,30 +189,13 @@ func getPkgs() string {
// 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
}
func printLogo(path string, width uint) {
cols := width / 8
sizeArg := fmt.Sprintf("--size=%dx%d", cols, cols/2)
cmd := exec.Command("chafa", path, sizeArg, "--symbols=half")
cmd.Stdout = os.Stdout
if err := cmd.Run(); err != nil {
fmt.Println("Chafa error:", err)
}
}
@ -244,8 +220,8 @@ func main() {
{"pkgs", getPkgs()},
}
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)")
logoPath := flag.String("l", defaultLogo, "Absolute or relative path to the logo image")
width := flag.Int("w", 200, "Logo width in lines")
flag.Parse()
if _, err := os.Stat(*logoPath); os.IsNotExist(err) {
fmt.Printf("Image '%s' not found\n", *logoPath)