new-config dialog

One extra prompt at end to stop file list flying off top of screen.
Calculate lines in K/O/R/P prompt before printing it, and use it to
work out screen MAXROWS etc.
This commit is contained in:
Dave Woodfall 2021-02-23 01:04:47 +00:00
parent fe99f902eb
commit 19c9fc0d9b

View file

@ -124,6 +124,10 @@ runvimdiff() {
} }
looknew() { looknew() {
local ROWS SIZE FILES PROMPTTEXT TEXTLINES MAXROWS
local newcount f n fn
f=0
n=0
# with ONLY_NEW_DOTNEW set, slackpkg will search only for # with ONLY_NEW_DOTNEW set, slackpkg will search only for
# .new files installed in actual slackpkg's execution # .new files installed in actual slackpkg's execution
@ -133,10 +137,6 @@ looknew() {
ONLY_NEW_DOTNEW="" ONLY_NEW_DOTNEW=""
fi fi
SIZE=$( stty size )
ROWS=${SIZE% *}
LISTMAX=$(( ROWS - 10 ))
printf "%s\n" "Searching for NEW configuration files..." printf "%s\n" "Searching for NEW configuration files..."
FILES=$( find \ FILES=$( find \
@ -154,53 +154,91 @@ looknew() {
if [ -n "$FILES" ]; then if [ -n "$FILES" ]; then
newcount=$( echo "$FILES" | wc -l ) newcount=$( echo "$FILES" | wc -l )
SIZE=$( stty size )
ROWS=${SIZE% *}
printf "%s %s\n\n" "Some packages had new configuration" \ # Set here so we can count the No. of lines
"files installed ($newcount new files):" PROMPTTEXT="\n\
if [ $newcount -le $LISTMAX ]; then
echo "$FILES"
else
F=0
N=0
for FN in $FILES; do
F=$(( F + 1 ))
N=$(( N + 1 ))
echo "$N $FN"
if [ $F -ge $(( ROWS - 5 )) ]; then
F=0
IFS=$( printf "\n" ) read -rn 1 \
-p "
Press SPACE for more, ENTER to skip" junk
printf "\n"
tput -S <<EOF
cuu 1
el 2
cuu 1
el 2
EOF
if [ -z "$junk" ]; then
break
fi
fi
done
fi
echo -ne "\n\
What do you want (K/O/R/P)? What do you want (K/O/R/P)?
(K)eep the old files and consider .new files later (K)eep the old files and consider .new files later
(O)verwrite all old files with the new ones" (O)verwrite all old files with the new ones"
[ "$ORIG_BACKUPS" != "off" ] && echo -ne ". The
[ "$ORIG_BACKUPS" != "off" ] && PROMPTTEXT+=". The
old files will be stored with the suffix .orig" old files will be stored with the suffix .orig"
echo -e "\n\n\
PROMPTTEXT+="\n\n\
(R)emove all .new files (R)emove all .new files
(P)rompt K, O, R selection for every single file" (P)rompt K, O, R selection for every single file\n"
printf "%s %s\n\n" "Some packages had new configuration" \
"files installed ($newcount new files):"
# No. of prompt etc. lines to print.
TEXTLINES=$(( $( printf %b "$PROMPTTEXT" | wc -l ) + 3 ))
if [ $(( newcount + TEXTLINES )) -lt $ROWS ]; then
# All files will fit on screen.
printf "%s\n" "$FILES"
else
# Won't all fit, so scroll a screenfull at a time.
# No. of lines minus 'Searching for' + 'Press SPACE...'
MAXROWS=$(( ROWS - 5 ))
for fn in $FILES; do
junk=" "
f=$(( f + 1 ))
n=$(( n + 1 ))
echo "$fn"
# Stop printing at bottom of screen
if [ $f -ge $MAXROWS ]; then
# No. of lines minus 'Press SPACE...'
MAXROWS=$(( ROWS - 2 ))
f=0
IFS=$( printf "\n" ) read -rn 1 -p "
Press SPACE for more, ENTER to skip" junk
# Enter pressed
if [ -z "$junk" ]; then
tput -S <<EOF
cuu 1
el 2
cuu 1
el 2
EOF
break
else
# Space pressed
printf "\n"
tput -S <<EOF
cuu 1
el 2
cuu 1
el 2
EOF
fi
fi
done
# Final prompt to stop list scrolling off the top
if [ ! -z "$junk" ] && [ $f -ne 0 ]; then
IFS=$( printf "\n" ) read -rn 1 -p "
Press any key to continue" junk
printf "\n"
tput -S <<EOF
cuu 1
el 2
cuu 1
el 2
EOF
fi
fi
printf %b "$PROMPTTEXT"
answer answer
case $ANSWER in case $ANSWER in
K|k) K|k)