Move some blocks to separate functions
This commit is contained in:
parent
793bcbcc7d
commit
256205aaea
1 changed files with 70 additions and 57 deletions
127
neofetch
127
neofetch
|
@ -2096,6 +2096,45 @@ getw3m_img_path() {
|
|||
|
||||
# }}}
|
||||
|
||||
# Display image {{{
|
||||
|
||||
displayimage() {
|
||||
if [ "$image" != "ascii" ]; then
|
||||
case "$image_backend" in
|
||||
"w3m")
|
||||
printf "%b%s\n" "0;1;$xoffset;$yoffset;$width;$height;;;;;$img\n4;\n3;" |\
|
||||
$w3m_img_path 2>/dev/null || padding="\033[0C"
|
||||
;;
|
||||
|
||||
"iterm2")
|
||||
printf "%b%s\a\n" "\033]1337;File=width=${width}px;height=${height}px;inline=1:$(base64 < "$img")"
|
||||
;;
|
||||
|
||||
"tycat")
|
||||
tycat "$img"
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
}
|
||||
|
||||
# }}}
|
||||
|
||||
# Get image backend {{{
|
||||
|
||||
getimagebackend() {
|
||||
if [ -n "$ITERM_PROFILE" ]; then
|
||||
image_backend="iterm2"
|
||||
|
||||
elif [ "$(tycat 2>/dev/null)" ]; then
|
||||
image_backend="tycat"
|
||||
|
||||
else
|
||||
image_backend="w3m"
|
||||
fi
|
||||
}
|
||||
|
||||
# }}}
|
||||
|
||||
|
||||
# }}}
|
||||
|
||||
|
@ -2534,7 +2573,7 @@ getdefaultconfig() {
|
|||
|
||||
# }}}
|
||||
|
||||
# Source Config {{{
|
||||
# Source config {{{
|
||||
|
||||
getuserconfig() {
|
||||
# Check $config_file
|
||||
|
@ -2583,7 +2622,7 @@ getdefaultconfig 2>/dev/null
|
|||
|
||||
# }}}
|
||||
|
||||
# Progress Bars {{{
|
||||
# Progress bars {{{
|
||||
|
||||
bar() {
|
||||
# Get the values
|
||||
|
@ -2617,7 +2656,7 @@ cache() {
|
|||
|
||||
# }}}
|
||||
|
||||
# KDE Config directory {{{
|
||||
# KDE config directory {{{
|
||||
|
||||
kdeconfigdir() {
|
||||
if [ -n "$KDE_CONFIG_DIR" ]; then
|
||||
|
@ -2636,6 +2675,27 @@ kdeconfigdir() {
|
|||
|
||||
# }}}
|
||||
|
||||
# Dynamic prompt location {{{
|
||||
|
||||
dynamicprompt() {
|
||||
# Get cursor position
|
||||
info_height="$(stty -echo; IFS=';' read -rdR -t 1 -d c -p $'\033[6n\033[c' ROW COL; printf "%s" "${ROW#*[}"; stty echo)"
|
||||
|
||||
# Calculate image height in terminal cells.
|
||||
# The '+ 3' adds a gap between the prompt and the content.
|
||||
[ "$image" != "ascii" ] && [ "$image" != "off" ] && \
|
||||
lines="$((${height:-1} / ${font_height:-1} + 3))"
|
||||
|
||||
# If the info is higher than the ascii/image place the prompt
|
||||
# based on the info height instead of the ascii/image height.
|
||||
[ "${lines:-0}" -lt "${info_height:-0}" ] && lines="$info_height"
|
||||
|
||||
# Set the prompt location
|
||||
[ "$image" != "off" ] && printf "%b%s" "\033[${lines:-0}H"
|
||||
}
|
||||
|
||||
# }}}
|
||||
|
||||
|
||||
# }}}
|
||||
|
||||
|
@ -2994,79 +3054,32 @@ main() {
|
|||
# Hide the cursor and disable line wrap
|
||||
printf "\033[?25l\033[?7l"
|
||||
|
||||
# Images {{{
|
||||
|
||||
# Get the image src
|
||||
# Display the image
|
||||
if [ "$image" != "off" ]; then
|
||||
# Set the image backend
|
||||
if [ -n "$ITERM_PROFILE" ]; then
|
||||
image_backend="iterm2"
|
||||
|
||||
elif [ "$(tycat 2>/dev/null)" ]; then
|
||||
image_backend="tycat"
|
||||
|
||||
else
|
||||
image_backend="w3m"
|
||||
fi
|
||||
getimagebackend
|
||||
|
||||
# Find w3mimgdisplay
|
||||
[ "$image_backend" == "w3m" ] && \
|
||||
[ "$image" != "ascii" ] && \
|
||||
getw3m_img_path
|
||||
|
||||
# Get the image
|
||||
# Get the image src
|
||||
getimage
|
||||
|
||||
# Display the image if enabled
|
||||
displayimage
|
||||
fi
|
||||
|
||||
# Display the image if enabled
|
||||
if [ "$image" != "off" ] && [ "$image" != "ascii" ]; then
|
||||
case "$image_backend" in
|
||||
"w3m")
|
||||
printf "%b%s\n" "0;1;$xoffset;$yoffset;$width;$height;;;;;$img\n4;\n3;" |\
|
||||
$w3m_img_path 2>/dev/null || padding="\033[0C"
|
||||
;;
|
||||
|
||||
"iterm2")
|
||||
printf "%b%s\a\n" "\033]1337;File=width=${width}px;height=${height}px;inline=1:$(base64 < "$img")"
|
||||
;;
|
||||
|
||||
"tycat")
|
||||
tycat "$img"
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
|
||||
# }}}
|
||||
|
||||
# Move cursor to the top
|
||||
[ "$image" != "off" ] && printf "\033[0H"
|
||||
|
||||
# Print the info
|
||||
printinfo
|
||||
|
||||
# Dynamic prompt location {{{
|
||||
|
||||
# Get cursor position
|
||||
info_height="$(stty -echo; IFS=';' read -rdR -t 1 -d c -p $'\033[6n\033[c' ROW COL; printf "%s" "${ROW#*[}"; stty echo)"
|
||||
|
||||
# Calculate image height in terminal cells.
|
||||
# The '+ 3' adds a gap between the prompt and the content.
|
||||
[ "$image" != "ascii" ] && [ "$image" != "off" ] && \
|
||||
lines="$((${height:-1} / ${font_height:-1} + 3))"
|
||||
|
||||
# If the info is higher than the ascii/image place the prompt
|
||||
# based on the info height instead of the ascii/image height.
|
||||
[ "${lines:-0}" -lt "${info_height:-0}" ] && lines="$info_height"
|
||||
|
||||
# Set the prompt location
|
||||
[ "$image" != "off" ] && printf "%b%s" "\033[${lines:-0}H"
|
||||
|
||||
# }}}
|
||||
dynamicprompt
|
||||
|
||||
# Re-enable line wrap
|
||||
printf "%b%s" "\033[?7h"
|
||||
|
||||
# If enabled take a screenshot
|
||||
[ "$scrot" == "on" ] && takescrot
|
||||
|
||||
# Show error messages
|
||||
|
|
Loading…
Reference in a new issue