chafa is now used for logo rendering
This commit is contained in:
parent
85d056e557
commit
88d3d9cd12
2
PKGBUILD
2
PKGBUILD
@ -11,7 +11,7 @@ pkgdesc="Fetch written in Go with image support"
|
|||||||
arch=('x86_64')
|
arch=('x86_64')
|
||||||
url="git+https://codeberg.org/nekohepott/goGoFetch.git"
|
url="git+https://codeberg.org/nekohepott/goGoFetch.git"
|
||||||
license=('MIT')
|
license=('MIT')
|
||||||
depends=('glibc')
|
depends=('glibc' 'chafa')
|
||||||
makedepends=('git' 'go')
|
makedepends=('git' 'go')
|
||||||
checkdepends=()
|
checkdepends=()
|
||||||
optdepends=()
|
optdepends=()
|
||||||
|
|||||||
15
README.md
15
README.md
@ -1,4 +1,4 @@
|
|||||||
# Fetch written in Go with image support (only for foot and kitty)
|
# Fetch written in Go with image support
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
@ -7,6 +7,7 @@ you can get gogofetch on AUR!
|
|||||||
```bash
|
```bash
|
||||||
yay -S gogofetch-git
|
yay -S gogofetch-git
|
||||||
```
|
```
|
||||||
|
also chafa is dependency for gogofetch
|
||||||
|
|
||||||
# Usage
|
# Usage
|
||||||
basic usage:
|
basic usage:
|
||||||
@ -15,11 +16,11 @@ gogofetch
|
|||||||
```
|
```
|
||||||
to show custom image (only png supported btw):
|
to show custom image (only png supported btw):
|
||||||
```bash
|
```bash
|
||||||
gogofetch -i *absolute_path*
|
gogofetch -l *absolute_path*
|
||||||
```
|
```
|
||||||
to show custom image and set custom width:
|
to show custom image and set custom width:
|
||||||
```bash
|
```bash
|
||||||
gogofetch -i *absolute_path* -w 250
|
gogofetch -l *absolute_path* -w 250
|
||||||
```
|
```
|
||||||
to show help message:
|
to show help message:
|
||||||
```bash
|
```bash
|
||||||
@ -70,6 +71,12 @@ and run:
|
|||||||
./main
|
./main
|
||||||
```
|
```
|
||||||
|
|
||||||
|
# Some screenshots
|
||||||
|
|
||||||
|
 alacritty
|
||||||
|
|
||||||
|
 foot
|
||||||
|
|
||||||
|
 xterm
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
BIN
assets/alacritty.png
(Stored with Git LFS)
Normal file
BIN
assets/alacritty.png
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
assets/foot.png
(Stored with Git LFS)
Normal file
BIN
assets/foot.png
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
assets/nixos.png
(Stored with Git LFS)
BIN
assets/nixos.png
(Stored with Git LFS)
Binary file not shown.
BIN
assets/xterm.png
(Stored with Git LFS)
Normal file
BIN
assets/xterm.png
(Stored with Git LFS)
Normal file
Binary file not shown.
44
main.go
44
main.go
@ -2,21 +2,14 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"bytes"
|
|
||||||
"encoding/base64"
|
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"image"
|
|
||||||
"image/png"
|
|
||||||
_ "image/png"
|
_ "image/png"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/mattn/go-sixel"
|
|
||||||
"github.com/nfnt/resize"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -51,7 +44,7 @@ func getDist() string {
|
|||||||
return dist
|
return dist
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return "unsupported distro"
|
return "unknown distro :("
|
||||||
}
|
}
|
||||||
|
|
||||||
func getRam() string {
|
func getRam() string {
|
||||||
@ -196,30 +189,13 @@ func getPkgs() string {
|
|||||||
// return "unknown"
|
// return "unknown"
|
||||||
//}
|
//}
|
||||||
|
|
||||||
func printLogo(path string, Width uint) {
|
func printLogo(path string, width uint) {
|
||||||
file, _ := os.Open(path)
|
cols := width / 8
|
||||||
defer func(file *os.File) {
|
sizeArg := fmt.Sprintf("--size=%dx%d", cols, cols/2)
|
||||||
err := file.Close()
|
cmd := exec.Command("chafa", path, sizeArg, "--symbols=half")
|
||||||
if err != nil {
|
cmd.Stdout = os.Stdout
|
||||||
return
|
if err := cmd.Run(); err != nil {
|
||||||
}
|
fmt.Println("Chafa error:", err)
|
||||||
}(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
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -244,8 +220,8 @@ func main() {
|
|||||||
{"pkgs", getPkgs()},
|
{"pkgs", getPkgs()},
|
||||||
}
|
}
|
||||||
|
|
||||||
logoPath := flag.String("i", defaultLogo, "Absolute or relative path to the logo image (only png)")
|
logoPath := flag.String("l", defaultLogo, "Absolute or relative path to the logo image")
|
||||||
width := flag.Int("w", 200, "Logo width in lines (400 IS MAXIMUM FOR KITTY VALUES ABOVE WILL CRASH TERMINAL)")
|
width := flag.Int("w", 200, "Logo width in lines")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
if _, err := os.Stat(*logoPath); os.IsNotExist(err) {
|
if _, err := os.Stat(*logoPath); os.IsNotExist(err) {
|
||||||
fmt.Printf("Image '%s' not found\n", *logoPath)
|
fmt.Printf("Image '%s' not found\n", *logoPath)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user