diff --git a/fastanime/cli/utils/scripts.py b/fastanime/cli/utils/scripts.py index a96c79e..91676e1 100644 --- a/fastanime/cli/utils/scripts.py +++ b/fastanime/cli/utils/scripts.py @@ -1,43 +1,13 @@ -# this script was written by the fzf devs as an example on how to preview images -# its only here for convinience fzf_preview = r""" # -# The purpose of this script is to demonstrate how to preview a file or an -# image in the preview window of fzf. +# Adapted from the preview script in the fzf repo # # Dependencies: -# - https://github.com/sharkdp/bat # - https://github.com/hpjansson/chafa # - https://iterm2.com/utilities/imgcat +# fzf-preview() { - if [[ $# -ne 1 ]]; then - >&2 echo "usage: $0 FILENAME" - exit 1 - fi - file=${1/#\~\//$HOME/} - type=$(file --dereference --mime -- "$file") - - if [[ ! $type =~ image/ ]]; then - if [[ $type =~ =binary ]]; then - file "$1" - exit - fi - - # Sometimes bat is installed as batcat. - if command -v batcat >/dev/null; then - batname="batcat" - elif command -v bat >/dev/null; then - batname="bat" - else - cat "$1" - exit - fi - - ${batname} --style="${BAT_STYLE:-numbers}" --color=always --pager=never -- "$file" - exit - fi - dim=${FZF_PREVIEW_COLUMNS}x${FZF_PREVIEW_LINES} if [[ $dim = x ]]; then dim=$(stty size /dev/null; then - chafa -f sixel -s "$dim" "$file" + case "$(uname -a)" in + # termux does not support sixel graphics + # and produces weird output + *ndroid*) chafa -s "$dim" "$file";; + *) chafa -f sixel -s "$dim" "$file";; + esac # Add a new line character so that fzf can display multiple images in the preview window echo - # 3. If chafa is not found but imgcat is available, use it on iTerm2 + # 3. If chafa is not found but imgcat is available, use it on iTerm2 elif command -v imgcat >/dev/null; then # NOTE: We should use https://iterm2.com/utilities/it2check to check if the # user is running iTerm2. But for the sake of simplicity, we just assume # that's the case here. imgcat -W "${dim%%x*}" -H "${dim##*x}" "$file" - # 4. Cannot find any suitable method to preview the image + # 4. Cannot find any suitable method to preview the image else - file "$file" + echo install chafa or imgcat or install kitty terminal so you can enjoy image previews fi } """