NikitaIvanovV / ctpv

Image previews for lf file manager
https://www.nikitaivanov.com/man1/ctpv
MIT License
270 stars 26 forks source link

Preview doesn't work on FreeBSD #30

Open wisonye opened 1 year ago

wisonye commented 1 year ago

I've already pasted the following settings (copy from repo README page) to ~/.config/lf/lfrc:

set previewer ctpv
set cleaner ctpvclear
&ctpv -s $id
&ctpvquit $id

But when I open lf (many times to confirm), no image preview:

lf-cannot-preview


So, first thing first, I need to make sure that ueberzug works or not, then I tried to make a draw-image.sh that uses ueberzug to draw an image in the terminal. Here is the script content:

#!/usr/local/bin/bash

[ -z "$5" ] && echo "Usage: $0 <image> <x> <y> <max height> <max width>" && exit

source "`ueberzug library`"

ImageLayer 0< <(
    ImageLayer::add [identifier]="example0" [x]="$2" [y]="$3" [max_width]="$5" [max_height]="$4" [path]="$1"
    read
)

Then run it to see if it works or not:

draw-image.sh ~/Photos/wallpaper/11.jpg 0 0 100 100

And it works perfectly:

ueberzug-can-draw


So, next try is ctpv, here is some commands and output:

ctpv -m ~/Photos/wallpaper/rust_old.png
# .png image/png

# Based on the man page info: ` ctpv file [w] [h] [x] [y] [id]`, I tried to run this command,
# but it prints out the image binary content instead of drawing an image:
ctpv  ~/Photos/wallpaper/rust_old.png 100 100 0 0 


ctpv-cannot-draw


Anything I'm missing?:)

NikitaIvanovV commented 1 year ago

Hello! This is weird, it looks like ctpv cannot find ueberzug program installen on the system, so it falls back to the most basic preview, which is plain cat.

What is your /bin/sh shell? Could you please try running command -v "ueberzug" >/dev/null; echo $??

wisonye commented 1 year ago

Hello! This is weird, it looks like ctpv cannot find ueberzug program installen on the system, so it falls back to the most basic preview, which is plain cat.

What is your /bin/sh shell? Could you please try running command -v "ueberzug" >/dev/null; echo $??

Hey, sorry for late reply, mmh, I use fish shell and installed uebuerzug via FreeBSD pkg (the standard normal way to install anything in FreeBSD).

And ueberzug is in my $PATH, so I think ctpv should be able to find it:

N  wison | /usr/home/wison   which ueberzug
/usr/local/bin/ueberzug

N  wison | /usr/home/wison   ls -lht /usr/local/bin/ueberzug
lrwxr-xr-x  1 root  wheel    12B Dec 11 08:18 /usr/local/bin/ueberzug@ -> ueberzug-3.9

I  wison | /usr/home/wison   ls -lht /usr/local/bin/ueberzug-3.9
-rwxr-xr-x  1 root  wheel   974B Dec 11 08:18 /usr/local/bin/ueberzug-3.9*

I  wison | /usr/home/wison   ueberzug version
18.1.8


And here is the info of the installed ueberzug:

I  wison | /usr/home/wison   pkg info --all | rg ueberzug
py39-ueberzug-18.1.8_1         Draw images on terminals with X11 child windows

I  wison | /usr/home/wison   pkg info py39-ueberzug
py39-ueberzug-18.1.8_1
Name           : py39-ueberzug
Version        : 18.1.8_1
Installed on   : Fri Dec 16 18:33:10 2022 NZDT
Origin         : graphics/py-ueberzug
Architecture   : FreeBSD:13:amd64
Prefix         : /usr/local
Categories     : python graphics
Licenses       : GPLv3+
Maintainer     : 0mp@FreeBSD.org
WWW            : https://github.com/seebye/ueberzug
Comment        : Draw images on terminals with X11 child windows
Options        :
        EXAMPLES       : on
Shared Libs required:
        libXext.so.6
        libX11.so.6
Annotations    :
        FreeBSD_version: 1301000
        flavor         : py39
        repo_type      : binary
        repository     : FreeBSD
Flat size      : 374KiB
Description    :
Überzug is a command line util which allows to draw images on terminals by
using child windows.

Advantages to w3mimgdisplay:
- no race conditions as a new window is created to display images
- expose events will be processed,
- so images will be redrawn on switch workspaces
- tmux support (excluding multi pane windows)
- terminals without the WINDOWID environment variable are supported
- chars are used as position - and size unit
- no memory leak (/ unlimited cache)

WWW: https://github.com/seebye/ueberzug


The command you asked me to run, fail in fish:

I  wison | /usr/home/wison   command -v "ueberzug" >/dev/null; echo "$?"
fish: $? is not the exit status. In fish, please use $status.
command -v "ueberzug" >/dev/null; echo "$?"
                                         ^
I  wison | /usr/home/wison   command -v "ueberzug" >/dev/null; echo $status
0


Then I gave it a try in bash shell as well:

[wison@my-bsd /usr/home/wison]$ command -v "ueberzug" >/dev/null; echo $?
0
[wison@my-bsd /usr/home/wison]$ which ueberzug
/usr/local/bin/ueberzug


Plz let me know you still need anything from me:)

NikitaIvanovV commented 1 year ago

Could you please try running ls -l /bin/sh and /bin/sh -c 'command -v "ueberzug"' >/dev/null; echo $?

wisonye commented 1 year ago

Could you please try running ls -l /bin/sh and /bin/sh -c 'command -v "ueberzug"' >/dev/null; echo $?

Sure, here it is:

I  wison | /usr/home/wison   ls -l /bin/sh
-r-xr-xr-x  1 root  wheel  169816 May 12  2022 /bin/sh*

I  wison | /usr/home/wison   /bin/sh -c 'command -v "ueberzug"' >/dev/null; echo $?
fish: $? is not the exit status. In fish, please use $status.
/bin/sh -c 'command -v "ueberzug"' >/dev/null; echo $?
                                                     ^
I  wison | /usr/home/wison   /bin/sh -c 'command -v "ueberzug"' >/dev/null; echo $status
0

# Then run that in `/bin/sh`:

I  wison | /usr/home/wison   sh
$ /bin/sh -c 'command -v "ueberzug"' >/dev/null; echo $?
0


NikitaIvanovV commented 1 year ago

How did you make fish your default shell?

NikitaIvanovV commented 1 year ago

I'm pretty sure it has something to do with fish being the default shell on your system. Although I might be wrong since /bin/sh seems to be working as expected...

wisonye commented 1 year ago

How did you make fish your default shell?

2023-01-07_924x703

NikitaIvanovV commented 1 year ago

Fish is not a POSIX shell, while ctpv expects a POSIX shell to be running because all its internal preview scripts are written in POSIX shell syntax. Do you have bash installed on your system?

wisonye commented 1 year ago

Fish is not a POSIX shell, while ctpv expects a POSIX shell to be running because all its internal preview scripts are written in POSIX shell syntax. Do you have bash installed on your system?

Sorry for late reply, yes I understand and yes I got Bash installed. If I insist to stay with Fish (as that's my favourite shell), is there any handy and easy way that I can run your plugin in bash session? (I mean how to use a script command to replace the default settings in lfrc?)☺️

NikitaIvanovV commented 1 year ago

I can add a config option to specify shell path. So in your case you could specify a path to bash.

NikitaIvanovV commented 1 year ago

Just added shell option (6f364cf383e87d2ab51bee307bbd149c2fb252db). Try adding set shell "/usr/bin/bash" in your ctpv config.

wisonye commented 1 year ago

Just added shell option (6f364cf). Try adding set shell "/usr/bin/bash" in your ctpv config.

I git clone the latest version and confirmed that with your last commit, but it can't compile :(

Does anything change in the Makefile (as I remember I can compile before)....

doas make install
Password:
cc -o ctpv   -O2 -pipe
cc: error: no input files
*** Error code 1

Stop.
make: stopped in /usr/home/wison/temp/ctpv
 I  wison | /usr/home/wison/temp/ctpv   cc --version
FreeBSD clang version 14.0.5 (https://github.com/llvm/llvm-project.git llvmorg-14.0.5-0-gc12386ae247c)
Target: x86_64-unknown-freebsd14.0
Thread model: posix
InstalledDir: /usr/bin
NikitaIvanovV commented 1 year ago

Last time I changed the Makefile was on October 10, So it's probably unrelated to that. It looks like Makefile does not have a list of source files. What kind of make utility do you use? Is it GNU Make? I think you can check with make --version.

wisonye commented 1 year ago

Last time I changed the Makefile was on October 10, So it's probably unrelated to that. It looks like Makefile does not have a list of source files. What kind of make utility do you use? Is it GNU Make? I think you can check with make --version.

Ok, I fixed the make issue by installing gmake and doas gmake install works, but it seems still does not solve the problem:) I've already added the shell setting to the config file. lf still no image preview, no matter I open lf in fish or bash:)

I think you need to know the following information (re-run the previous commands you wanted me to do):

I  wison | /usr/home/wison   /usr/local/bin/bash --version
GNU bash, version 5.2.15(0)-release (amd64-portbld-freebsd14.0)
Copyright (C) 2022 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
 I  wison | /usr/home/wison 
 I  wison | /usr/home/wison   bash
[wison@my-bsd /usr/home/wison]$
[wison@my-bsd /usr/home/wison]$ command -v "ueberzug" >/dev/null; echo "$?"
0
[wison@my-bsd /usr/home/wison]$ which ueberzug
/usr/local/bin/ueberzug
[wison@my-bsd /usr/home/wison]$ ueberzug version
18.1.8
[wison@my-bsd /usr/home/wison]$ bat ~/.config/ctpv/config
───────┬─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
       │ File: /home/wison/.config/ctpv/config
───────┼─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
   1   │ set shell "/usr/local/bin/bash"
───────┴─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
[wison@my-bsd /usr/home/wison]$ ctpv -m ~/Photos/wallpaper/rust_old.png
.png image/png


But when I run ctpv ~/Photos/wallpaper/rust_old.png 100 100 0 0, it still print out the image data to the console which means not ok:)

Also, I found one more thing: It seems the ctpv server doesn't exit automatically??? As every time I open a new lf instance, it creates new ctpv server and won't kill it even lf quits:

#
# I open 4 `lf` instances and navigate to some image files, 
# then quit the `lf` (all of them), but all `ctpv` servers are still there
#
/bin/ps aux | rg ctpv
wison   78956    0.0  0.0      13472   3276  3  I+   19:54     0:00.01 /bin/sh /usr/bin/man ctpv
wison   39698    0.0  0.1      57396  33428  1  I+   19:53     0:00.51 nvim /home/wison/temp/ctpv/src/config.c
wison   32946    0.0  0.0      16484   5592  6  S    20:19     0:00.01 ctpv -s 32841
wison   55239    0.0  0.0      16484   5592  6  S    20:20     0:00.01 ctpv -s 55121
wison   67168    0.0  0.0      16484   5596  6  S    20:20     0:00.00 ctpv -s 67138
wison   81413    0.0  0.0       9980   6220  6  R+   20:20     0:00.00 rg ctpv
wison   85427    0.0  0.0      16484   5596  6  S    20:19     0:00.01 ctpv -s 85293
NikitaIvanovV commented 1 year ago

Could you please send your ctpv config here?

wisonye commented 1 year ago

Could you please send your ctpv config here?

Sure, it just one line:

set shell "/usr/local/bin/bash"
NikitaIvanovV commented 1 year ago

I've added -d option for debug messages. Could you please try running ctpv on an image and print the output here?

wisonye commented 1 year ago

ctpv ~/Photos/wallpaper/rust_old.png 100 100 0 0

Ok, I pull and recompiled and reinstalled, here is what you want I think: