mirror of
https://github.com/rworkman/slackpkg
synced 2025-01-22 19:27:14 +01:00
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:
parent
fe99f902eb
commit
19c9fc0d9b
1 changed files with 79 additions and 41 deletions
|
@ -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,25 +154,65 @@ 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):"
|
||||
|
||||
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"
|
||||
# No. of prompt etc. lines to print.
|
||||
TEXTLINES=$(( $( printf %b "$PROMPTTEXT" | wc -l ) + 3 ))
|
||||
|
||||
if [ $F -ge $(( ROWS - 5 )) ]; then
|
||||
F=0
|
||||
IFS=$( printf "\n" ) read -rn 1 \
|
||||
-p "
|
||||
Press SPACE for more, ENTER to skip" junk
|
||||
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
|
||||
|
@ -180,27 +220,25 @@ Press SPACE for more, ENTER to skip" junk
|
|||
cuu 1
|
||||
el 2
|
||||
EOF
|
||||
|
||||
if [ -z "$junk" ]; then
|
||||
break
|
||||
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
|
||||
|
||||
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"
|
||||
|
||||
printf %b "$PROMPTTEXT"
|
||||
answer
|
||||
case $ANSWER in
|
||||
K|k)
|
||||
|
|
Loading…
Reference in a new issue