Merge pull request #82 from dylanaraps/image_size
Font size is now calculated by fetch
This commit is contained in:
commit
09c65e59a1
3 changed files with 41 additions and 43 deletions
40
fetch
40
fetch
|
@ -285,15 +285,10 @@ crop_mode="normal"
|
|||
# east/southwest/south/southeast
|
||||
crop_offset="center"
|
||||
|
||||
# Font width
|
||||
# Used when calculating dynamic image size
|
||||
# --font_width num
|
||||
font_width=5
|
||||
|
||||
# Image size
|
||||
# The image is half the terminal width by default.
|
||||
# --size half, px
|
||||
image_size="half"
|
||||
# --size auto, px
|
||||
image_size="auto"
|
||||
|
||||
# Right gap between image and text
|
||||
# --gap num
|
||||
|
@ -1882,8 +1877,21 @@ getimage () {
|
|||
;;
|
||||
esac
|
||||
|
||||
# If $img isn't a file, fallback to ascii mode.
|
||||
if [ ! -f "$img" ]; then
|
||||
# Get terminal width and height
|
||||
printf "%b%s" '\033[14t'
|
||||
|
||||
index=0
|
||||
while IFS= read -s -r -n 1 -t 0.25 char; do
|
||||
case "$index" in
|
||||
"0") [ "$char" == ";" ] && index=$((index + 1)) ;;
|
||||
"1") [ "$char" == ";" ] && index=$((index + 1)) || term_height="${term_height}${char}" ;;
|
||||
"2") [ "$char" == "t" ] && break || term_width="${term_width}${char}"
|
||||
esac
|
||||
done
|
||||
|
||||
# If $img isn't a file or the terminal doesn't support xterm escape sequences,
|
||||
# fallback to ascii mode.
|
||||
if [ ! -f "$img" ] || [ -z "$term_height" ]; then
|
||||
# Fallback to ascii mode
|
||||
image="ascii"
|
||||
getascii
|
||||
|
@ -1891,14 +1899,22 @@ getimage () {
|
|||
return
|
||||
fi
|
||||
|
||||
# Get lines and columns
|
||||
# Get terminal lines and columns
|
||||
columns=$(tput cols)
|
||||
lines=$(tput lines)
|
||||
|
||||
# Calculate font size
|
||||
font_width=$((term_width / columns))
|
||||
font_height=$((term_height / lines))
|
||||
|
||||
# Image size is half of the terminal
|
||||
[ "$image_size" == "half" ] && \
|
||||
if [ "$image_size" == "auto" ]; then
|
||||
image_size=$((columns * font_width / 2))
|
||||
|
||||
[ "$((term_height - term_height / 4))" -lt "$image_size" ] && \
|
||||
image_size=$((term_height - term_height / 4))
|
||||
fi
|
||||
|
||||
# Where to draw the image
|
||||
case "$image_position" in
|
||||
"left")
|
||||
|
@ -2334,7 +2350,6 @@ usage () { cat << EOF
|
|||
--size px Size in pixels to make the image.
|
||||
--image_backend w3m/iterm2 Which program to use to draw images.
|
||||
--shuffle_dir path/to/dir Which directory to shuffle for an image.
|
||||
--font_width px Used to automatically size the image
|
||||
--image_position left/right Where to display the image: (Left/Right)
|
||||
--crop_mode mode Which crop mode to use
|
||||
Takes the values: normal, fit, fill
|
||||
|
@ -2449,7 +2464,6 @@ while [ "$1" ]; do
|
|||
--size) image_size="$2" ;;
|
||||
--image_backend) image_backend="$2" ;;
|
||||
--shuffle_dir) shuffle_dir="$2" ;;
|
||||
--font_width) font_width="$2" ;;
|
||||
--image_position) image_position="$2" ;;
|
||||
--crop_mode) crop_mode="$2" ;;
|
||||
--crop_offset) crop_offset="$2" ;;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue