--size now takes a percentage

This commit is contained in:
Dylan 2016-02-20 13:35:07 +11:00
parent ad8acb6bf7
commit 95c1b74e6d
2 changed files with 17 additions and 7 deletions

View file

@ -277,7 +277,7 @@ alias fetch2="fetch \
--image type Image source. Where and what image we display.
Possible values: wall, shuffle, ascii,
/path/to/img, off
--size px Size in pixels to make the image.
--size 20 | --size 20% Size to make the image, takes pixels or a percentage.
--image_backend w3m/iterm2 Which program to use to draw images.
--shuffle_dir path/to/dir Which directory to shuffle for an image.
--image_position left/right Where to display the image: (Left/Right)

22
fetch
View file

@ -1864,12 +1864,22 @@ getimage () {
font_height=$((term_height / lines))
# Image size is half of the terminal
if [ "$image_size" == "auto" ]; then
image_size=$((columns * font_width / 2))
case "$image_size" in
"auto")
image_size=$((columns * font_width / 2))
[ "$((term_height - term_height / 4))" -lt "$image_size" ] && \
image_size=$((term_height - term_height / 4))
fi
[ "$((term_height - term_height / 4))" -lt "$image_size" ] && \
image_size=$((term_height - term_height / 4))
;;
*"%")
percent=${image_size/\%}
image_size=$((percent * term_width / 100))
[ "$((percent * term_height / 50))" -lt "$image_size" ] && \
image_size=$((percent * term_height / 100))
;;
esac
# Where to draw the image
case "$image_position" in
@ -2265,7 +2275,7 @@ usage () { cat << EOF
--image type Image source. Where and what image we display.
Possible values: wall, shuffle, ascii,
/path/to/img, off
--size px Size in pixels to make the image.
--size 20 | --size 20% Size to make the image, takes pixels or a percentage.
--image_backend w3m/iterm2 Which program to use to draw images.
--shuffle_dir path/to/dir Which directory to shuffle for an image.
--image_position left/right Where to display the image: (Left/Right)