]> git.tuebingen.mpg.de Git - gsu.git/commitdiff
gui: Introduce _set_dialog_ret().
authorAndre Noll <maan@tuebingen.mpg.de>
Sat, 6 Sep 2014 17:41:16 +0000 (19:41 +0200)
committerAndre Noll <maan@tuebingen.mpg.de>
Sat, 27 Sep 2014 23:02:00 +0000 (23:02 +0000)
The improved exit code handling for dialog(1) also makes sense for
the other invocations of dialog. This patch abtracts out the logic
into the new internal _set_dialog_ret() function.

gui

diff --git a/gui b/gui
index 2d3e270371a8db341052455eda1fdc7891dcb563..6003a90ab18a11c51bf4ae4c0a98fa4e74c2bb38 100644 (file)
--- a/gui
+++ b/gui
@@ -22,6 +22,19 @@ _get_geometry()
        result="$y $x"
 }
 
+_set_dialog_ret()
+{
+       local ec="$1"
+
+       case "$ec" in
+       0) ret=$GSU_SUCCESS;;
+       1) ret=1;; # cancelled
+       *)
+               result="dialog exit code $ec"
+               ret=-$E_GSU_DIALOG
+       esac
+}
+
 # Open a dialog box which asks the user to input a text
 #
 # Usage: gsu_input_box <text> <init>
@@ -37,12 +50,7 @@ gsu_inputbox()
        _get_geometry
        g="$result"
        result="$(dialog --inputbox "$text" $g "$init" 3>&1 1>&2 2>&3 3>&-)"
-       if (($? != 0)); then
-               ret=-$E_GSU_DIALOG
-               result='inputbox'
-               return
-       fi
-       ret=$GSU_SUCCESS
+       _set_dialog_ret $?
 }
 
 # Show the given file in a text box
@@ -59,8 +67,8 @@ gsu_textbox()
 
        ret=-$E_GSU_DIALOG
        result='textbox'
-       dialog --textbox "$file" $g || return
-       ret=$GSU_SUCCESS
+       dialog --textbox "$file" $g
+       _set_dialog_ret $?
 }
 
 # Show a message in a text box
@@ -97,13 +105,7 @@ _gsu_menu()
                opts+=" $i $num"
        done
        result="$(dialog --menu "$gsu_banner_txt ($header)" $opts 3>&1 1>&2 2>&3 3>&-)"
-       case $? in
-       0) ret=$GSU_SUCCESS;;
-       1) ret=1;; # cancelled
-       *)
-               result="menu error $ret"
-               ret=-$E_GSU_DIALOG
-       esac
+       _set_dialog_ret $?
 }
 
 _get_level()