diff options
author | Dieter Plaetinck <dieter@plaetinck.be> | 2008-11-03 14:55:19 +0100 |
---|---|---|
committer | Dieter Plaetinck <dieter@plaetinck.be> | 2008-11-03 14:55:19 +0100 |
commit | 6e0e1ab2c395ceaadcdde0cf8a4fb8c0bc639265 (patch) | |
tree | 27264b04c581ea895e86bb0bfab5d4187abb8437 /src | |
parent | 74dafa4f7bb98a3b629f9b3c76f711803085e14d (diff) |
moved some UI functions from fifa.sh to lib-ui (yeay) + some fixes
Diffstat (limited to 'src')
-rw-r--r-- | src/core/libs/lib-ui.sh | 40 | ||||
-rwxr-xr-x | src/fifa.sh | 61 |
2 files changed, 44 insertions, 57 deletions
diff --git a/src/core/libs/lib-ui.sh b/src/core/libs/lib-ui.sh index f012f05..f465645 100644 --- a/src/core/libs/lib-ui.sh +++ b/src/core/libs/lib-ui.sh @@ -9,6 +9,46 @@ ANSWER="/home/arch/fifa/runtime/.dialog-answer" ### Functions that your code can use. Cli/dialog mode is fully transparant. This library takes care of it ### +# display error message and die +die_error () +{ + notify "ERROR: $@" + exit 2 +} + + +# display warning message +# $1 title +# $2 item to show +# $3 type of item. msg or text if it's a file. (optional. defaults to msg) +show_warning () +{ + [ -z "$1" ] && die_error "show_warning needs a title" + [ -z "$2" ] && die_error "show_warning needs an item to show" + [ -n "$3" -a "$3" != msg -a "$3" != text ] && die_error "show_warning \$3 must be text or msg" + [ -z "$3" ] && 3=msg + if [ "$var_UI_TYPE" = dia ] + then + _dia_DIALOG --title "$1" --exit-label "Continue" --$3box "$2" 18 70 || die_error "dialog could not show --$3box $2. often this means a file does not exist" + else + echo "WARNING: $1" + [ "$3" = msg ] && echo -e "$2" + [ "$3" = text ] && cat $2 || die_error "Could not cat $2" + fi +} + + +#notify user +notify () +{ + if [ "$var_UI_TYPE" = dia ] + then + _dia_DIALOG --msgbox "$@" 20 50 + else + echo -e "$@" + fi +} + # ask the user a password. return is stored in $PASSWORD or $<TYPE>_PASSWORD # $1 type (optional. eg 'svn', 'ssh'). diff --git a/src/fifa.sh b/src/fifa.sh index ef3a0b2..a819bfd 100755 --- a/src/fifa.sh +++ b/src/fifa.sh @@ -1,5 +1,4 @@ #!/bin/bash -# TODO: we should be able to get away with not defining the "These functions would fit more in lib-ui, but we need them immediately" functions in lib-ui, but just sourcing lib-ui very early ###### Set some default variables or get them from the setup script ###### TITLE="Flexible Installer Framework for Arch linux" @@ -11,67 +10,15 @@ LOG="/dev/tty7" usage () { + #NOTE: you can't use dia mode here yet because lib-ui isn't sourced yet. But cli is ok for this anyway. msg="$0 <procedurename>\n -If the procedurename starts with 'http://' it will be wget'ed. Otherwise it's assumed to be a procedure in the VFS tree\n +If the procedurename starts with 'http://' it will be wget'ed. Otherwise it's assumed to be a procedure in the VFS tree If the procedurename is prefixed with '<modulename>/' it will be loaded from user module <modulename>. See README\n -Available procedures on the filesystem:\n +Available procedures on the filesystem: `find /home/arch/fifa/core/procedures -type f`\n `find /home/arch/fifa/user/*/procedures -type f`" - if [ "$var_UI_TYPE" = dia ] - then - DIALOG --msgbox "$msg" 14 65 - else - echo -e "$msg" - fi -} - - -##### "These functions would fit more in lib-ui, but we need them immediately" functions ###### - - -# display error message and die -die_error () -{ - if [ "$var_UI_TYPE" = dia ] - then - DIALOG --msgbox "Error: $@" 0 0 - else - echo -e "ERROR: $@" - fi - exit 2 -} + echo -e "$msg" - -# display warning message -# $1 title -# $2 item to show -# $3 type of item. msg or text if it's a file. (optional. defaults to msg) -show_warning () -{ - [ -z "$1" ] && die_error "show_warning needs a title" - [ -z "$2" ] && die_error "show_warning needs an item to show" - [ -n "$3" -a "$3" != msg -a "$3" != text ] && die_error "show_warning \$3 must be text or msg" - [ -z "$3" ] && 3=msg - if [ "$var_UI_TYPE" = dia ] - then - dialog --title "$1" --exit-label "Continue" --$3box "$2" 18 70 || die_error "dialog could not show --$3box $2. often this means a file does not exist" - else - echo "WARNING: $1" - [ "$3" = msg ] && echo -e "$2" - [ "$3" = text ] && cat $2 || die_error "Could not cat $2" - fi -} - - -#notify user -notify () -{ - if [ "$var_UI_TYPE" = dia ] - then - DIALOG --msgbox "$@" 20 50 - else - echo -e "$@" - fi } |