X-Git-Url: http://git.tuebingen.mpg.de/?p=gsu.git;a=blobdiff_plain;f=gui;h=23e9e903af340ccb74c936b4fd8704b32dfb8fee;hp=3c89567cceae816d58cd9bd438ce0fe2d8cf2410;hb=4167cc8db6c44314335cffd9c1a80f6da7ae4a69;hpb=2925cf7299f958ed6c52ba1ba9d42a841d86c8f2 diff --git a/gui b/gui index 3c89567..23e9e90 100644 --- a/gui +++ b/gui @@ -1,8 +1,10 @@ #!/bin/bash +# Copyright (C) 2006 Andre Noll +# Licensed under the LGPL, version 3. See COPYING and COPYING.LESSER. if [[ "$(type -t _gsu_setup)" != "function" ]]; then gsu_dir=${gsu_dir:-${BASH_SOURCE[0]%/*}} - . $gsu_dir/common || exit 1 + . "$gsu_dir/common" || exit 1 _gsu_setup fi @@ -22,6 +24,27 @@ _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 +# +# is displayed above of the input field, which is is preset to . +# The entered text is returned in $result. On success (user pressed OK) +# the function returns zero. If the user selected Cancel, the return value is +# one. On dialog errors, a negative error code is returned. gsu_inputbox() { local g text="$1" init="$2" @@ -29,14 +52,14 @@ 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 +# +# Usage: gsu_textbox +# +# The box has an OK button which closes the box when activated. gsu_textbox() { local g file="$1" @@ -46,20 +69,25 @@ gsu_textbox() ret=-$E_GSU_DIALOG result='textbox' - dialog --textbox "$file" $g || return - ret=$GSU_SUCCESS + dialog --textbox "$file" $g + _set_dialog_ret $? } -# dialog segfaults if message is too long. Hence we always use a temporary file +# Show a message in a text box +# +# Usage: gsu_msgbox +# +# This is like gsu_textbox() but the text is passed as a string. gsu_msgbox() { - local tmp="$(mktemp gsu_msgbox.XXXXXXXXXX)" - - if (($? != 0)); then - ret=-$E_GSU_MKTEMP - result='temp file for textbox' - return - fi + local tmp + + # Some versions of dialog segfault if the text is too long. Hence we + # always use a temporary file. + gsu_make_tempfile 'gsu_msgbox.XXXXXXXXXX' + (($ret < 0)) && return + tmp="$result" + trap "rm -f $tmp" EXIT echo "$1" > "$tmp" gsu_textbox "$tmp" rm -f "$tmp" # ignore errors @@ -69,7 +97,7 @@ _gsu_menu() { local header="${1:-root}" local items="$2" - local i state opts num=0 + local i opts num=0 _get_geometry opts="$result 16" @@ -78,13 +106,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()