Skip to content

Commit

Permalink
Merge pull request #46 from crpb/timg
Browse files Browse the repository at this point in the history
preview: add "timg" as a preferred renderer.
  • Loading branch information
alexmyczko authored Oct 28, 2024
2 parents 502e025 + 529e10a commit 99e1a7f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 9 deletions.
Empty file modified completions/_fnt
100755 → 100644
Empty file.
40 changes: 31 additions & 9 deletions fnt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ else
s=$(uname -s)
fi

check_com() { if ! command -v "$1" &> /dev/null; then return 1; fi ; }

# Pipelines
pipe_download(){
local PIPEFILE
Expand Down Expand Up @@ -185,6 +187,32 @@ fnt_install() {
fi
}

render_preview() {
PREVIEW="$1"
_app=(
chafa="-w 9"
timg=""
)
for a in "${_app[@]}"; do
bin=${a%=*}
opt=${a#*=}
if check_com "$bin"; then
if file --brief --mime-type "$PREVIEW" |grep -q 'image/png'; then
# shellcheck disable=SC2086
$bin $opt "$PREVIEW"
return 0
fi
return 0
else
missing=( "${missing[@]}" "$bin" )
fi
done
echo "Warning: ${missing[*]} not available. Please install one of them." >&2
echo -e "\v\t${PREVIEWURI}\v"
return 69
}


preview() {
PREVIEW="${FNTDATA}/preview.png"
PREVIEWURI="https://screenshots.debian.net/screenshot/fonts-$1"
Expand All @@ -199,15 +227,9 @@ preview() {
fi
fi
fi
if ! command -v chafa &>/dev/null; then
echo "Warning: chafa not found. Use $i install chafa to get rid of me." >&2
echo -e "\v\t${PREVIEWURI}\v"
exit 0
else
if file --brief --mime-type "$PREVIEW" |grep -q 'image/png'; then
chafa -c 240 -w 9 -O 9 -p on --symbols all "$PREVIEW" 2>/dev/null && PRINTED=1
echo "$1: $PREVIEWURI"
fi
if render_preview "$PREVIEW"; then
PRINTED=1
echo "$1: $PREVIEWURI"
fi
fi
if [ "$PRINTED" != "1" ]; then
Expand Down

0 comments on commit 99e1a7f

Please sign in to comment.