update vv

This commit is contained in:
tavo 2024-12-28 17:21:19 -06:00
parent 9d271de53e
commit 48178b3399

53
scripts/vv Executable file → Normal file
View file

@ -2,11 +2,11 @@
# vv: VT View # vv: VT View
# Version 1.9.3 # Version 1.9.4
# B9 May 2023 # B9 November 2024
# Use sixel graphics to show images inside a terminal (e.g., xterm). # Use sixel graphics to show images inside a terminal (e.g., xterm).
# Copyright (c) 2019..2023 hackerb9, under the terms of GNU GPL 3+. # Copyright (c) 2019..2024 hackerb9, under the terms of GNU GPL 3+.
# Some nice features: # Some nice features:
# * Can display any image type. (Via ImageMagick). # * Can display any image type. (Via ImageMagick).
@ -257,6 +257,16 @@ prerequisites() {
echo "Pages: $(identify "$1" | grep -c PDF)" echo "Pages: $(identify "$1" | grep -c PDF)"
} }
fi fi
if command -v chrome >/dev/null; then
dumpdom() { chrome --headless --dump-dom "$@"; }
elif command -v chromium >/dev/null; then
dumpdom() { chromium --headless --dump-dom "$@"; }
else
dumpdom() {
notice "If yandex mistakes w3m for a bot, please install chrome to run headless javascript."
curl "$@"
}
fi
if [[ $BASH_VERSINFO -lt 5 ]]; then if [[ $BASH_VERSINFO -lt 5 ]]; then
notice "Kludging read for Bash4" notice "Kludging read for Bash4"
BASH4BUG="-e" BASH4BUG="-e"
@ -540,7 +550,7 @@ inittermkey() {
# To be valid, we must enable terminal application mode key sequences. # To be valid, we must enable terminal application mode key sequences.
if tput smkx; then if tput smkx; then
for k in $(infocmp -L1 | egrep 'key_|cursor_'); do for k in $(infocmp -L1 | grep -E 'key_|cursor_'); do
a=""; x="" a=""; x=""
# Example "k: key_down=\EOB," # Example "k: key_down=\EOB,"
a=${k#*key_} a=${k#*key_}
@ -758,7 +768,6 @@ sidebyside() {
-auto-orient \ -auto-orient \
-geometry ">${half}x>$((height-fontheight))" \ -geometry ">${half}x>$((height-fontheight))" \
-label "$1" "$1" -label "$2" "$2" sixel:- -label "$1" "$1" -label "$2" "$2" sixel:-
viewmode=ss
SHOULDREDRAW=yup SHOULDREDRAW=yup
} }
@ -821,7 +830,8 @@ reverseimagesearch() {
yandeximagesearch() { yandeximagesearch() {
# Reverse image search using yandex and w3m # Reverse image search using yandex and w3m
# Yandex is not the best but has a simple interface we can access # Yandex is not the best but has a simple interface we can access
# without javascript. (Unlike Tineye, Bing, and Google.) # (Unlike Tineye, Bing, and Google). Yandex does require
# javascript, so we use 'chrome --dump-dom' to retrieve the html.
local file="$1" local file="$1"
local output resultPage deleteme="" # Local vars local output resultPage deleteme="" # Local vars
local scale=">1000x>1000" # Image size to scale to before searching. local scale=">1000x>1000" # Image size to scale to before searching.
@ -838,7 +848,7 @@ yandeximagesearch() {
url="https://yandex.com/images/search?rpt=imageview" url="https://yandex.com/images/search?rpt=imageview"
url+="&format=json" url+="&format=json"
url+='&request=%7B%22blocks%22%3A%5B%7B%22block%22%3A%22cbir-controller__upload%3Aajax%22%7D%5D%7D' url+='&request=%7B%22blocks%22%3A%5B%7B%22block%22%3A%22cbir-controller__upload%3Aajax%22%7D%5D%7D'
cookie="yp=999999999999.sp.aflt%3A999999999999.szm.1; my=YywBAAA=" cookie=""
# Upload the image and save the output to search through. # Upload the image and save the output to search through.
# Note: Curl's "@filename" splits filenames with commas & semicolons. # Note: Curl's "@filename" splits filenames with commas & semicolons.
@ -872,8 +882,11 @@ yandeximagesearch() {
if [[ "$resultPage" ]]; then if [[ "$resultPage" ]]; then
echo "Found $(unuriescape "$resultPage")" >&2 echo "Found yandex.com/$(unuriescape "$resultPage")" >&2
w3m https://yandex.com$resultPage dumpdom https://yandex.com$resultPage |
sed 's|<head>|<base href="https://yandex.com/images"><head>|' > "$tmpdir/yandex.html"
w3m "$tmpdir/yandex.html"
rm "$tmpdir/yandex.html" 2>/dev/null
else else
echo "Error parsing results from Yandex." >&2 echo "Error parsing results from Yandex." >&2
fi fi
@ -1184,10 +1197,10 @@ fakefile() {
showimage() { showimage() {
# Shows the file named in $1 using sixel. # Shows the file named in $1 using sixel.
# Global variable $viewmode is either "full", which enlarges it to # Global variable $viewmode is (usually) either "full", which
# the full size of the terminal window, or it is "fast", which # enlarges it to the full size of the terminal window, or it is
# scales the image down, removes colors, and takes other shortcuts # "fast", which scales the image down, removes colors, and takes
# for the fastest preview. # other shortcuts for the fastest preview.
# Note that "full size" is not exactly the same as "full screen". # Note that "full size" is not exactly the same as "full screen".
# In a terminal emulator, the sixel graphics are just a window. # In a terminal emulator, the sixel graphics are just a window.
@ -1319,7 +1332,8 @@ showimage() {
esac esac
tput el tput el
if [[ "$output" ]]; then if [[ "$output" ]]; then
echo -n "$output" local ST=$'\e\\\\' # String Terminator is Esc \.
echo -n "$output" | sed "s/-${ST}/${ST}\n/g" # (sed kludge for bug in IM 6.9.12)
SHOULDREDRAW="" # Reset redraw flag until SIGWINCH trips it SHOULDREDRAW="" # Reset redraw flag until SIGWINCH trips it
else else
# Error. ImageMagick must have failed as $output is empty. # Error. ImageMagick must have failed as $output is empty.
@ -1447,10 +1461,11 @@ doit () {
# Use read timeout to check several times a second for window resize. # Use read timeout to check several times a second for window resize.
REPLY= REPLY=
while [[ -z $REPLY && -z $SHOULDREDRAW ]]; do while [[ -z $REPLY && -z $SHOULDREDRAW ]]; do
read $BASH4BUG -s -n1 -t 0.25 < /dev/tty if read $BASH4BUG -s -n1 -t 0.25 < /dev/tty; then
local e=$? break
if [[ $e -gt 0 ]]; then else
# Read command returned an error (usually timeout). # Read command returned an error (usually timeout).
local e=$?
if [[ "$slideshow" ]]; then if [[ "$slideshow" ]]; then
if doslideshow "$f"; then if doslideshow "$f"; then
continue 3 # User hit q to quit vv continue 3 # User hit q to quit vv
@ -1814,13 +1829,15 @@ dotfordot() {
### Show pieces ### Show pieces
local ST=$'\e\\\\' # String Terminator is Esc \.
local IFS=$'\n' local IFS=$'\n'
for f in $(ls -1v $tmpdir/*crop.ppm); do for f in $(ls -1v $tmpdir/*crop.ppm); do
echo -en "$f\r" echo -en "$f\r"
convert "$f" "$f.sixel" convert "$f" "$f.sixel"
cat "$f.sixel" cat "$f.sixel" | sed "s/-${ST}/${ST}\n/g" # (sed kludge for bug in IM 6.9.12)
done done
### All done ### All done
rm $tmpdir/*crop.* rm $tmpdir/*crop.*
} }