From fcd4bad3c50a5d81191e68289fa83ad1aedbd119 Mon Sep 17 00:00:00 2001 From: Dylan Date: Fri, 29 Jan 2016 10:11:34 +1100 Subject: [PATCH] Only move cursor to the bottom of the terminal if w3m/iterm2 rendering is on --- fetch | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/fetch b/fetch index d7815fd2..82d2bdf2 100755 --- a/fetch +++ b/fetch @@ -83,6 +83,7 @@ printinfo () { info linebreak info cols + info linebreak } @@ -1400,6 +1401,9 @@ getascii () { # Get length of longest line length="$(LC_ALL="en_US.UTF8" wc -L 2>/dev/null <<< "$ascii_strip")" + # Get the height in lines + lines="$(($(LC_ALL="en_US.UTF8" wc -l 2>/dev/null <<< "$ascii_strip") + 1))" + # Fallback to using awk on systems without 'wc -L' [ -z "$length" ] && \ length="$(LC_ALL="en_US.UTF8" awk 'length>max{max=length}END{print max}' <<< "$ascii_strip")" @@ -1538,6 +1542,9 @@ getimage () { esac fi + # Lines equals terminal height + lines=$(tput lines) + # The final image img="$imgtempdir/$imgname" } @@ -1842,8 +1849,7 @@ done # Restore cursor and clear screen on ctrl+c trap 'printf "\033[?25h"; clear; exit' 2 -# Get lines and columns -lines=$(tput lines) +# Get columns columns=$(tput cols) # Clear the terminal and hide the cursor @@ -1879,11 +1885,15 @@ printf "\033[0H" printinfo # Move the cursor to the bottom and Show the cursor -printf "%b%s" "\033[${lines}H\033[${prompt_height}A\033[?25h" +[ "$image" != "off" ] && \ + printf "%b%s" "\033[${lines}H\033[${prompt_height}A" # Enable line wrap again [ "$line_wrap" == "off" ] && printf "\033[?7h" +# Show the cursor +printf "%b%s" "\033[?25h" + # If enabled take a screenshot [ "$scrot" == "on" ] && takescrot