add support for GIF logos with animation via chafa
This commit is contained in:
parent
62a3b3ff12
commit
c96d264fcd
@ -1,63 +0,0 @@
|
|||||||
name: AUR Sync
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches: [ master ]
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
aur-sync:
|
|
||||||
runs-on: docker
|
|
||||||
container:
|
|
||||||
image: archlinux:latest
|
|
||||||
steps:
|
|
||||||
- name: Install dependencies
|
|
||||||
run: |
|
|
||||||
pacman -Syu --noconfirm nodejs git binutils openssh sudo
|
|
||||||
|
|
||||||
- name: Checkout code
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
|
|
||||||
- name: Setup SSH
|
|
||||||
run: |
|
|
||||||
mkdir -p ~/.ssh
|
|
||||||
echo "${{ secrets.AUR_SSH_PRIVATE_KEY }}" > ~/.ssh/id_ed25519
|
|
||||||
chmod 600 ~/.ssh/id_ed25519
|
|
||||||
|
|
||||||
cat >> ~/.ssh/config <<EOF
|
|
||||||
Host aur.archlinux.org
|
|
||||||
IdentityFile ~/.ssh/id_ed25519
|
|
||||||
User aur
|
|
||||||
StrictHostKeyChecking no
|
|
||||||
EOF
|
|
||||||
|
|
||||||
ssh-keyscan -t ed25519 aur.archlinux.org >> ~/.ssh/known_hosts
|
|
||||||
|
|
||||||
- name: Configure Git
|
|
||||||
run: |
|
|
||||||
git config --global user.name "nekohepott"
|
|
||||||
git config --global user.email "nekohepott@larpdhq.org"
|
|
||||||
|
|
||||||
- name: Sync to AUR
|
|
||||||
run: |
|
|
||||||
chown -R nobody:nobody .
|
|
||||||
chmod -R 777 .
|
|
||||||
|
|
||||||
git clone ssh://aur@aur.archlinux.org/gogofetch-git.git /tmp/aur
|
|
||||||
|
|
||||||
sudo -u nobody makepkg --nodeps --nobuild --force
|
|
||||||
sudo -u nobody makepkg --printsrcinfo > .SRCINFO
|
|
||||||
|
|
||||||
|
|
||||||
cp PKGBUILD .SRCINFO /tmp/aur/
|
|
||||||
|
|
||||||
cd /tmp/aur
|
|
||||||
git config user.name "nekohepott"
|
|
||||||
git config user.email "nekohepott@larpdhq.org"
|
|
||||||
|
|
||||||
if [[ -n $(git status -s) ]]; then
|
|
||||||
git add PKGBUILD .SRCINFO
|
|
||||||
git commit -m "Update from Codeberg CI: ${GITHUB_SHA::7}"
|
|
||||||
git push
|
|
||||||
else
|
|
||||||
echo "No changes to commit"
|
|
||||||
fi
|
|
||||||
@ -18,6 +18,7 @@ to show custom image :
|
|||||||
```bash
|
```bash
|
||||||
gogofetch -l path
|
gogofetch -l path
|
||||||
```
|
```
|
||||||
|
If the custom image is a GIF, it will animate and gogofetch will keep running until you stop it (Ctrl+C).
|
||||||
to show custom image and set custom width:
|
to show custom image and set custom width:
|
||||||
```bash
|
```bash
|
||||||
gogofetch -l path -w 250
|
gogofetch -l path -w 250
|
||||||
@ -88,4 +89,3 @@ and run:
|
|||||||
|
|
||||||
 xterm
|
 xterm
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
14
src/main.go
14
src/main.go
@ -132,6 +132,20 @@ func main() {
|
|||||||
if _, err := os.Stat(*logoPath); err == nil {
|
if _, err := os.Stat(*logoPath); err == nil {
|
||||||
if conf.Ascii || (ascii != nil && *ascii) {
|
if conf.Ascii || (ascii != nil && *ascii) {
|
||||||
logoLines = providers.SplitLines(providers.PrintAsciiLogo(*logoPath))
|
logoLines = providers.SplitLines(providers.PrintAsciiLogo(*logoPath))
|
||||||
|
} else if providers.IsGif(*logoPath) {
|
||||||
|
if err := providers.RenderLogoChafaAnimated(*logoPath, uint(*width), statsLines, position); err == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
parts := strings.Split(*logoPath, ".")
|
||||||
|
if len(parts) > 1 {
|
||||||
|
parts[1] = "txt"
|
||||||
|
}
|
||||||
|
*logoPath = strings.Join(parts, ".")
|
||||||
|
logoLines = providers.SplitLines(providers.PrintAsciiLogo(*logoPath))
|
||||||
|
if strings.Contains(*logoPath, ".txt") != true {
|
||||||
|
fmt.Printf("chafa binary not found, to print images please install chafa\n")
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
logoLines, err = providers.RenderLogoChafa(*logoPath, uint(*width))
|
logoLines, err = providers.RenderLogoChafa(*logoPath, uint(*width))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@ -36,12 +36,25 @@ func PrintAsciiLogo(path string) string {
|
|||||||
return string(content)
|
return string(content)
|
||||||
}
|
}
|
||||||
|
|
||||||
func RenderLogoChafa(path string, width uint) ([]string, error) {
|
func IsGif(path string) bool {
|
||||||
cols := width / 8
|
return strings.EqualFold(filepath.Ext(path), ".gif")
|
||||||
if cols == 0 {
|
}
|
||||||
|
|
||||||
|
func logoGrid(width uint) (int, int) {
|
||||||
|
cols := int(width / 8)
|
||||||
|
if cols < 1 {
|
||||||
cols = 1
|
cols = 1
|
||||||
}
|
}
|
||||||
sizeArg := fmt.Sprintf("--size=%dx%d", cols, cols/2)
|
rows := cols / 2
|
||||||
|
if rows < 1 {
|
||||||
|
rows = 1
|
||||||
|
}
|
||||||
|
return cols, rows
|
||||||
|
}
|
||||||
|
|
||||||
|
func RenderLogoChafa(path string, width uint) ([]string, error) {
|
||||||
|
cols, rows := logoGrid(width)
|
||||||
|
sizeArg := fmt.Sprintf("--size=%dx%d", cols, rows)
|
||||||
cmd := exec.Command("chafa", path, "--format", "symbols", sizeArg, "--symbols=half")
|
cmd := exec.Command("chafa", path, "--format", "symbols", sizeArg, "--symbols=half")
|
||||||
out, err := cmd.Output()
|
out, err := cmd.Output()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -50,6 +63,50 @@ func RenderLogoChafa(path string, width uint) ([]string, error) {
|
|||||||
return SplitLines(string(out)), err
|
return SplitLines(string(out)), err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func RenderLogoChafaAnimated(path string, width uint, statsLines []string, position string) error {
|
||||||
|
cols, rows := logoGrid(width)
|
||||||
|
statsWidth := maxLineLen(statsLines)
|
||||||
|
logoPad := strings.Repeat(" ", cols)
|
||||||
|
lineCount := len(statsLines)
|
||||||
|
if rows > lineCount {
|
||||||
|
lineCount = rows
|
||||||
|
}
|
||||||
|
const gap = " "
|
||||||
|
|
||||||
|
for i := 0; i < lineCount; i++ {
|
||||||
|
stats := ""
|
||||||
|
if i < len(statsLines) {
|
||||||
|
stats = statsLines[i]
|
||||||
|
}
|
||||||
|
if position == "left" {
|
||||||
|
fmt.Printf("%s%s%s\n", logoPad, gap, stats)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
fmt.Printf("%s%s%s\n", padRightVisible(stats, statsWidth), gap, logoPad)
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Print("\x1b7")
|
||||||
|
defer func() {
|
||||||
|
fmt.Print("\x1b8\n")
|
||||||
|
}()
|
||||||
|
|
||||||
|
fmt.Printf("\x1b[%dA", lineCount)
|
||||||
|
fmt.Print("\r")
|
||||||
|
if position == "right" {
|
||||||
|
startCol := statsWidth + len(gap)
|
||||||
|
if startCol > 0 {
|
||||||
|
fmt.Printf("\x1b[%dC", startCol)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sizeArg := fmt.Sprintf("--size=%dx%d", cols, rows)
|
||||||
|
cmd := exec.Command("chafa", "--format", "symbols", sizeArg, "--symbols=half", "--animate=on", "--duration=inf", "--relative=on", path)
|
||||||
|
cmd.Stdout = os.Stdout
|
||||||
|
cmd.Stdin = os.Stdin
|
||||||
|
cmd.Stderr = os.Stderr
|
||||||
|
return cmd.Run()
|
||||||
|
}
|
||||||
|
|
||||||
func NormalizeLogoPosition(pos string) string {
|
func NormalizeLogoPosition(pos string) string {
|
||||||
value := strings.ToLower(strings.TrimSpace(pos))
|
value := strings.ToLower(strings.TrimSpace(pos))
|
||||||
if value == "left" || value == "right" {
|
if value == "left" || value == "right" {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user