Images: Add support for catimg and caca

This commit is contained in:
Dylan Araps 2017-01-14 23:37:39 +11:00
parent d35ecf826a
commit d8712286f8
3 changed files with 48 additions and 53 deletions

View file

@ -529,7 +529,7 @@ disk_display="off"
# Image backend.
#
# Default: 'ascii'
# Values: 'ascii', 'w3m', 'iterm2', 'tycat', 'off'
# Values: 'ascii', 'caca', 'catimg', 'iterm2', 'off', 'tycat', 'w3m'
# Flag: --image_backend
image_backend="ascii"

View file

@ -1954,7 +1954,7 @@ image_backend() {
"ascii") get_ascii ;;
"off") image_backend="off" ;;
"iterm2" | "w3m" | "tycat")
"iterm2" | "w3m" | "tycat" | "catimg" | "caca")
get_image_source
if [[ ! -f "$image" ]]; then
@ -1962,16 +1962,6 @@ image_backend() {
return
fi
get_image_program
if type -p "$image_program" >/dev/null 2>&1; then
err "Image: Drawing images using '$image_program'."
else
to_ascii "Image: Failed to find image program '$image_program'."
err "Image: Falling back to ascii mode."
return
fi
get_term_size
if [[ "$term_width" ]] && ((term_width >= 1)); then
@ -1995,6 +1985,7 @@ image_backend() {
err "Image: Falling back to ascii mode."
get_ascii
;;
esac
# Set cursor position next image/ascii.
@ -2139,30 +2130,22 @@ get_wallpaper() {
[[ "${image/*\./}" == "xml" ]] && image=""
}
get_image_program() {
if [[ -n "$ITERM_PROFILE" ]]; then
image_program="iterm2"
get_w3m_img_path() {
# Find w3m-img path.
if [[ -x "$w3m_img_path" ]]; then
w3m_img_path="$w3m_img_path"
elif [[ "$(tycat 2>/dev/null)" ]]; then
image_program="tycat"
elif [[ -x "/usr/lib/w3m/w3mimgdisplay" ]]; then
w3m_img_path="/usr/lib/w3m/w3mimgdisplay"
else
# Find w3m-img path.
if [[ -x "$w3m_img_path" ]]; then
image_program="$w3m_img_path"
elif [[ -x "/usr/libexec/w3m/w3mimgdisplay" ]]; then
w3m_img_path="/usr/libexec/w3m/w3mimgdisplay"
elif [[ -x "/usr/lib/w3m/w3mimgdisplay" ]]; then
image_program="/usr/lib/w3m/w3mimgdisplay"
elif [[ -x "/usr/lib64/w3m/w3mimgdisplay" ]]; then
w3m_img_path="/usr/lib64/w3m/w3mimgdisplay"
elif [[ -x "/usr/libexec/w3m/w3mimgdisplay" ]]; then
image_program="/usr/libexec/w3m/w3mimgdisplay"
elif [[ -x "/usr/lib64/w3m/w3mimgdisplay" ]]; then
image_program="/usr/lib64/w3m/w3mimgdisplay"
elif [[ -x "/usr/libexec64/w3m/w3mimgdisplay" ]]; then
image_program="/usr/libexec64/w3m/w3mimgdisplay"
fi
elif [[ -x "/usr/libexec64/w3m/w3mimgdisplay" ]]; then
w3m_img_path="/usr/libexec64/w3m/w3mimgdisplay"
fi
}
@ -2355,14 +2338,15 @@ make_thumbnail() {
}
display_image() {
image_program="catimg"
case "$image_program" in
*"w3m"*)
case "$image_backend" in
"w3m")
get_w3m_img_path
# Add a tiny delay to fix issues with images not
# appearing in specific terminal emulators.
sleep 0.05
printf "%b\n" "0;1;$xoffset;$yoffset;$width;$height;;;;;$image\n4;\n3;" |\
"$w3m_img_path" -bg "$background_color" >/dev/null & 2>&1 || to_off "Images: w3m-img failed to display the image."
"${w3m_img_path:-false}" -bg "$background_color" >/dev/null & 2>&1 || to_off "Images: w3m-img failed to display the image."
;;
"iterm2")
@ -3415,13 +3399,14 @@ get_term_padding() {
dynamic_prompt() {
case "$image_backend" in
"iterm2" | "w3m" | "tycat")
"ascii") ;;
"off") return ;;
*)
get_term_padding 2>/dev/null
# Calculate image height in terminal cells.
lines="$(((border * 2 + height + yoffset) / font_height))"
;;
"off") return ;;
esac
# If the info is higher than the ascii/image place the prompt
@ -3721,14 +3706,16 @@ BARS:
IMAGE BACKEND:
--image_backend backend Which image backend to use.
Possible values: 'ascii', 'w3m', 'iterm2', 'tycat', 'off'
Possible values: 'ascii', 'caca', 'catimg', 'iterm2', 'off', 'tycat', 'w3m'
--image_source source Which image or ascii file to use.
Possible values: 'auto', 'ascii', 'wallpaper', '/path/to/img', '/path/to/ascii', '/path/to/dir/'
--w3m Shortcut to use 'w3m' backend.
--iterm2 Shortcut to use 'iterm2' backend.
--tycat Shortcut to use 'tycat' backend.
--ascii Shortcut to use 'ascii' backend.
--caca Shortcut to use 'caca' backend.
--catimg Shortcut to use 'catimg' backend.
--iterm2 Shortcut to use 'iterm2' backend.
--off Shortcut to use 'off' backend.
--tycat Shortcut to use 'tycat' backend.
--w3m Shortcut to use 'w3m' backend.
ASCII:
--ascii_colors x x x x x x Colors to print the ascii art
@ -3926,11 +3913,13 @@ get_args() {
# Image backend
"--image_backend") image_backend="$2" ;;
"--image_source") image_source="$2" ;;
"--w3m") image_backend="w3m" ;;
"--iterm2") image_backend="iterm2" ;;
"--tycat") image_backend="tycat" ;;
"--ascii") image_backend="ascii" ;;
"--caca") image_backend="caca" ;;
"--catimg") image_backend="catimg" ;;
"--iterm2") image_backend="iterm2" ;;
"--off") image_backend="off" ;;
"--tycat") image_backend="tycat" ;;
"--w3m") image_backend="w3m" ;;
# Image options
"--image_size" | "--size") image_size="$2" ;;

View file

@ -175,26 +175,32 @@ Takes: bar, infobar, barinfo, off
.TP
\fB\-\-image_backend\fR backend
Which image backend to use.
Possible values: 'ascii', 'w3m', 'iterm2', 'tycat', 'off'
Possible values: 'ascii', 'caca', 'catimg', 'iterm2', 'off', 'tycat', 'w3m'
.TP
\fB\-\-image_source\fR source
Which image or ascii file to use.
Possible values: 'auto', 'ascii', 'wallpaper', '/path/to/img', '/path/to/ascii', '/path/to/dir/'
.TP
\fB\-\-w3m\fR
Shortcut to use 'w3m' backend.
\fB\-\-ascii\fR
Shortcut to use 'ascii' backend.
.TP
\fB\-\-caca\fR
Shortcut to use 'caca' backend.
.TP
\fB\-\-catimg\fR
Shortcut to use 'catimg' backend.
.TP
\fB\-\-iterm2\fR
Shortcut to use 'iterm2' backend.
.TP
\fB\-\-off\fR
Shortcut to use 'off' backend.
.TP
\fB\-\-tycat\fR
Shortcut to use 'tycat' backend.
.TP
\fB\-\-ascii\fR
Shortcut to use 'ascii' backend.
.TP
\fB\-\-off\fR
Shortcut to use 'off' backend.
\fB\-\-w3m\fR
Shortcut to use 'w3m' backend.
.SS "ASCII:"
.TP
\fB\-\-ascii_colors\fR x x x x x x