Yes, you can use Alacritty as your terminal emulator for image previews in Ranger while running Sway. Alacritty is a GPU-accelerated terminal emulator that supports Wayland, so it is a good choice for this purpose.
However, since Alacritty does not support image rendering natively within the terminal, you cannot use w3m-img directly with it. Instead, you would typically use a program like Überzug, but since Überzug only supports X11, it is not suitable for Sway which uses Wayland.
Thankfully, there are alternate methods such as using the Kitty graphics protocol (which works with terminals like Kitty that support the graphics protocol) or employing the viu command-line program which displays images in the terminal using block characters and ANSI colors.
Here's a high-level outline of how you might set up image previews in Ranger with Alacritty:
-
Install Ranger and Necessary Tools:
Ensure Ranger is installed and also install viu which can be used to display images within Alacritty on Sway.
sudo apt install ranger viu
-
Configure Ranger:
Edit ranger's configuration file to enable image previews when using Alacritty. You can create or edit ~/.config/ranger/rc.conf with the following lines:
set preview_images true
set preview_images_method kitty
Since we are using viu instead of kitty, the above setting is mainly to ensure ranger invokes the appropriate image preview script.
-
Create Image Preview Script:
Ranger can use custom scripts for generating image previews. You would need to create a script that uses viu for this task.
Create a script named scope.sh under ~/.config/ranger/ and make it executable:
chmod +x ~/.config/ranger/scope.sh
Add a section in scope.sh to handle image files using viu (you can find a default version of this script to modify from ranger's default configurations):
#!/bin/bash
# Example implementation:
case "$1" in
*.jpg|*.jpeg|*.png|*.bmp|*.gif)
viu "$1"
exit 0;;
esac
exit 1
Make sure scope.sh is set as the default file previewer by adding the following to your ~/.config/ranger/rc.conf:
set preview_script ~/.config/ranger/scope.sh
-
Open Ranger in Alacritty:
Run ranger in Alacritty by simply typing ranger in the terminal. Navigate to a directory with images, and you should now see image previews rendered by viu.
Please note that using viu won't provide the same image quality as an actual image renderer like Überzug, and not all features (e.g., transparent images) will be supported. The output will also depend on the capabilities of viu and your terminal's support for ANSI colors and Unicode block characters.