archlinuxfr / yaourt

[unmaintained] A Pacman frontend with more features and AUR support
601 stars 98 forks source link

[PATCH] Improve bad keypress handling #37

Closed stevenhoneyman closed 8 years ago

stevenhoneyman commented 10 years ago

Using pacman as an example, when you get asked a question that has a default answer; if you press Enter, it uses the default. If you press a random letter (e.g. accidently pressing M instead of N), it stops/exits, but Yaourt would instead just use the default. The patch below makes it behave like pacman - unhandled keys mean exit, but ENTER still uses default.

--- a/src/lib/abs.sh.in 2014-06-06 13:30:36.000000000 +0100
+++ b/src/lib/abs.sh.in 2014-06-16 20:52:11.705753729 +0100
@@ -188,8 +188,8 @@
               SP_ARG="" sync_packages "$YAOURTTMPDIR/sysuplist"
               return 2
               ;;
-           N) return 1;;
-           *) break;;
+           Y) break;;
+           *) return 1;;
        esac
    done
 }
--- a/src/lib/io.sh 2014-06-06 13:30:36.000000000 +0100
+++ b/src/lib/io.sh 2014-06-16 20:48:33.555750222 +0100
@@ -76,7 +76,9 @@
    else
        read -en $NOENTER
        [[ $REPLY ]] && answer=$(echo ${REPLY^^*} | tr "$(gettext $_key)" "$_key") || answer=$default
-       [[ "${_key/$answer/}" = "$_key" ]] && answer=$default
+       if [[ "${_key/$answer/}" = "$_key" ]]; then
+           [[ -z "$answer" ]] && answer=$default || answer="Q"
+       fi
    fi
    echo $answer
    [[ "$answer" = "$default" ]]
larchunix commented 8 years ago

This patch has unwanted side effects.

For instance:

$ yaourt -Qdt
extra/swig 3.0.8-1
==> Do you want to remove these packages (with -Rcs options) ?  [y/N]
==> -----------------------------------------------------------------
==>

After applying your patch, all answers except N trigger a removal.