diff options
author | Dave Woodfall <dave@slackbuilds.org> | 2021-02-23 01:04:47 +0000 |
---|---|---|
committer | Dave Woodfall <dave@slackbuilds.org> | 2021-02-23 01:04:47 +0000 |
commit | 19c9fc0d9bd63de996db3ac7b2e7704842771ded (patch) | |
tree | 1696c60ea12e65cd66ed4a4f5c2ce08110a049da /files | |
parent | fe99f902ebf272ce3499a11c2b0c8083f0b23879 (diff) | |
download | slackpkg-19c9fc0d9bd63de996db3ac7b2e7704842771ded.tar.xz |
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.
Diffstat (limited to 'files')
-rw-r--r-- | files/post-functions.sh | 118 |
1 files 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 <<EOF - cuu 1 - el 2 - cuu 1 - el 2 -EOF - + 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 - fi - - echo -ne "\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" ] && echo -ne ". The - old files will be stored with the suffix .orig" - echo -e "\n\n\ - (R)emove all .new files - - (P)rompt K, O, R selection for every single file" + # 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 case $ANSWER in K|k) |