[3/4] pacdiff: Reduce repetition in input loop

Message ID bdbe0b2e79ae605c97fa7457a022ae23fde23791.1608967613.git.liu.denton@gmail.com
State New
Headers show
Series pacdiff: learn (M)erge mode | expand

Commit Message

Denton Liu Dec. 26, 2020, 7:27 a.m. UTC
The input loop repeats the `ask` code twice. In a future commit, we will
be introducing another instance of the `ask` code. This makes it
possible to mistakenly make the code to get out of sync.

Refactor the loop so that the `ask` code happens once at the top of the
loop. This introduces one functional change in the "Invalid answer" case
but it also makes it more consistent with the remaining cases.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 src/pacdiff.sh.in | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

Patch

diff --git a/src/pacdiff.sh.in b/src/pacdiff.sh.in
index 46a5adf..a50cb93 100644
--- a/src/pacdiff.sh.in
+++ b/src/pacdiff.sh.in
@@ -180,8 +180,9 @@  while IFS= read -u 3 -r -d '' pacfile; do
 		msg2 "Files are identical, removing..."
 		rm -v "$pacfile"
 	else
-		ask "(V)iew, (S)kip, (R)emove %s, (O)verwrite with %s, (Q)uit: [v/s/r/o/q] " "$file_type" "$file_type"
-		while read c; do
+		while :; do
+			ask "(V)iew, (S)kip, (R)emove %s, (O)verwrite with %s, (Q)uit: [v/s/r/o/q] " "$file_type" "$file_type"
+			read c || break
 			case $c in
 				q|Q) exit 0;;
 				r|R) rm -v "$pacfile"; break ;;
@@ -192,11 +193,9 @@  while IFS= read -u 3 -r -d '' pacfile; do
 						msg2 "Files are identical, removing..."
 						rm -v "$pacfile"
 						break
-					fi
-					ask "(V)iew, (S)kip, (R)emove %s, (O)verwrite with %s, (Q)uit: [v/s/r/o/q] " "$file_type" "$file_type";
-					continue ;;
+					fi ;;
 				s|S) break ;;
-				*) ask "Invalid answer. Try again: [v/s/r/o/q] "; continue ;;
+				*) msg2 "Invalid answer." ;;
 			esac
 		done
 	fi