From 19c9fc0d9bd63de996db3ac7b2e7704842771ded Mon Sep 17 00:00:00 2001 From: Dave Woodfall Date: Tue, 23 Feb 2021 01:04:47 +0000 Subject: 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. --- files/post-functions.sh | 118 ++++++++++++++++++++++++++++++++---------------- 1 file changed, 78 insertions(+), 40 deletions(-) diff --git a/files/post-functions.sh b/files/post-functions.sh index 9fd483a..a9f86f8 100644 --- a/files/post-functions.sh +++ b/files/post-functions.sh @@ -124,6 +124,10 @@ runvimdiff() { } 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 # .new files installed in actual slackpkg's execution @@ -133,10 +137,6 @@ looknew() { ONLY_NEW_DOTNEW="" fi - SIZE=$( stty size ) - ROWS=${SIZE% *} - LISTMAX=$(( ROWS - 10 )) - printf "%s\n" "Searching for NEW configuration files..." FILES=$( find \ @@ -154,53 +154,91 @@ looknew() { if [ -n "$FILES" ]; then newcount=$( echo "$FILES" | wc -l ) + SIZE=$( stty size ) + ROWS=${SIZE% *} + + # Set here so we can count the No. of lines + PROMPTTEXT="\n\ +What do you want (K/O/R/P)? + + (K)eep the old files and consider .new files later + + (O)verwrite all old files with the new ones" + + [ "$ORIG_BACKUPS" != "off" ] && PROMPTTEXT+=". The + old files will be stored with the suffix .orig" + + PROMPTTEXT+="\n\n\ + (R)emove all .new files + + (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):" + printf "%s %s\n\n" "Some packages had new configuration" \ + "files installed ($newcount new files):" - if [ $newcount -le $LISTMAX ]; then - echo "$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 - F=0 - N=0 - for FN in $FILES; do - F=$(( F + 1 )) - N=$(( N + 1 )) - echo "$N $FN" + # Won't all fit, so scroll a screenfull at a time. + # No. of lines minus 'Searching for' + 'Press SPACE...' + MAXROWS=$(( ROWS - 5 )) - 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 <