summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDieter Plaetinck <dieter@plaetinck.be>2008-12-10 14:49:56 +0100
committerDieter Plaetinck <dieter@plaetinck.be>2008-12-10 14:49:56 +0100
commit7d63d384de7621802e1c9cec438c030c6b74c7e7 (patch)
tree29e5e60b03afd92d6b7468f4a3b5107e63453ae5
parentd4480c3400f1cb082e787ae56e4d91187895594f (diff)
improvement of ask_checklist and some minor shit
-rw-r--r--src/core/libs/lib-ui-interactive.sh17
-rw-r--r--src/core/libs/lib-ui.sh29
2 files changed, 27 insertions, 19 deletions
diff --git a/src/core/libs/lib-ui-interactive.sh b/src/core/libs/lib-ui-interactive.sh
index 509441e..37f8cc6 100644
--- a/src/core/libs/lib-ui-interactive.sh
+++ b/src/core/libs/lib-ui-interactive.sh
@@ -308,17 +308,18 @@ interactive_filesystem ()
# add $part to $fs_params if it's not in there because the user wants this enabled by default
pv=${part/+/}
grep -q ":$pv:" <<< $fs_params || grep -q ":$pv\$" <<< $fs_params || fs_params="$fs_params:$pv"
+ list=
for pv in `sed 's/:/ /' <<< $fs_params`
do
- list="$list $pv ON"
+ list="$list $pv ^ ON"
done
for pv in `grep '+ lvm-pv' $TMP_BLOCKDEVICES | awk '{print $1}' | sed 's/\+$//'` # find PV's to be added: their blockdevice ends on + and has lvm-pv as type #TODO: i'm not sure we check which pv's are taken already
do
- grep -q "$pv ON" <<< "$list" || list="$list $pv OFF"
+ grep -q "$pv ^ ON" <<< "$list" || list="$list $pv - OFF"
done
list2=($list)
- if [ ${#list2[*]} -lt 4 ] # less then 4 words in the list. eg only one option
+ if [ ${#list2[*]} -lt 6 ] # less then 6 words in the list. eg only one option
then
notify "Automatically picked PV ${list2[0]} to use for this VG. It's the only available lvm PV"
fs_params=${list2[0]}
@@ -512,7 +513,7 @@ interactive_select_packages() {
# set up our install location if necessary and sync up
# so we can get package lists
- target_prepare_pacman || ( notify "Pacman preparation failed! Check $LOG for errors." && return 1 )
+ target_prepare_pacman || ( show_warning "Pacman preparation failed! Check $LOG for errors." && return 1 )
# show group listing for group selection, base is ON by default, all others are OFF
local _catlist="base ^ ON"
@@ -520,8 +521,8 @@ interactive_select_packages() {
_catlist="${_catlist} ${i} - OFF"
done
- _dia_DIALOG --checklist "Select Package Categories\nDO NOT deselect BASE unless you know what you're doing!" 19 55 12 $_catlist 2>$ANSWER || return 1
- _catlist="$(cat $ANSWER)" # _catlist now contains all categories (the tags from the dialog checklist)
+ ask_checklist "Select Package Categories\nDO NOT deselect BASE unless you know what you're doing!" $_catlist || return 1
+ _catlist=$ANSWER_CHECKLIST # _catlist now contains all categories (the tags from the dialog checklist)
# assemble a list of packages with groups, marking pre-selected ones
# <package> <group> <selected>
@@ -542,8 +543,8 @@ interactive_select_packages() {
# sort by category
_pkglist="$(echo "$_pkglist" | sort -f -k 2)"
- _dia_DIALOG --checklist "Select Packages To Install." 19 60 12 $_pkglist 2>$ANSWER || return 1
- TARGET_PACKAGES="$(cat $ANSWER)" # contains now all package names
+ ask_checklist "Select Packages To Install." $_pkglist || return 1
+ TARGET_PACKAGES=$ANSWER_CHECKLIST # contains now all package names
return 0
}
diff --git a/src/core/libs/lib-ui.sh b/src/core/libs/lib-ui.sh
index 4210e51..21efd3b 100644
--- a/src/core/libs/lib-ui.sh
+++ b/src/core/libs/lib-ui.sh
@@ -1,6 +1,7 @@
#!/bin/sh
-# TODO: lot's of implementation work still open in this library. especially the dialog & $var_UI_TYPE stuff
+# TODO: implement 'retry until user does it correctly' everywhere
# TODO: get rid of the echoing of the variables at the end. passing output as $ANSWER_<foo> is more useful
+# TODO: at some places we should check if $1 etc is only 1 word because we often depend on that
# Taken from setup. we store dialog output in a file. TODO: can't we do this with variables? ASKDEV
@@ -140,11 +141,12 @@ _getavaildisks()
# ask the user to make a selection from a certain group of things
# $1 question
-# shift;shift; $@ list of options. first tag. then ON/OFF
+# shift;shift; $@ list of options. first tag, then item then ON/OFF. if item == ^ or - it will not be shown in cli mode.
+# for nostalgic reasons, you can set item to ^ for ON items and - for OFF items. afaik this doesn't have any meaning other then extra visual separation though
ask_checklist ()
{
[ -z "$1" ] && die_error "ask_checklist needs a question!"
- [ -z "$3" ] && debug "ask_checklist args: $@" && die_error "ask_checklist makes only sense if you specify at least 1 thing (incl ON/OFF switch)"
+ [ -z "$4" ] && debug "ask_checklist args: $@" && die_error "ask_checklist makes only sense if you specify at least 1 thing (tag,item and ON/OFF switch)"
[ "$var_UI_TYPE" = dia ] && { _dia_ask_checklist "$@" ; return $? ; }
[ "$var_UI_TYPE" = cli ] && { _cli_ask_checklist "$@" ; return $? ; }
}
@@ -157,7 +159,6 @@ ask_datetime ()
}
-# TODO: we should have a wrapper around this function that keeps trying until the user entered a valid numeric?, maybe a wrapper that wraps all functions
# ask for a number.
# $1 question
# $2 lower limit (optional)
@@ -271,10 +272,11 @@ _dia_ask_checklist ()
list=
while [ -n "$1" ]
do
- [ -z "$2" ] && die_error "no ON/OFF switch given for element $1"
- [ "$2" = ON ] && newlist="$1 ^ ON"
- [ "$2" = OFF ] && newlist="$1 - OFF"
- shift 2
+ [ -z "$2" ] && die_error "no item given for element $1"
+ [ -z "$3" ] && die_error "no ON/OFF switch given for element $1 (item $2)"
+ [ "$3" != ON -a "$3" != OFF ] && die_error "element $1 (item $2) has status $3 instead of ON/OFF!"
+ list="$list $1 $2 $3"
+ shift 3
done
_dia_DIALOG --checklist "$str" $list 2>$ANSWER
ret=$?
@@ -423,9 +425,14 @@ _cli_ask_checklist ()
output=
while [ -n "$1" ]
do
- [ -z "$2" ] && die_error "no ON/OFF switch given for element $1"
- [ "$2" = ON ] && ask_yesno "Enable $1 ?" yes && output="$output $1"
- [ "$2" = OFF ] && ask_yesno "Enable $1 ?" no && output="$output $1"
+ [ -z "$2" ] && die_error "no item given for element $1"
+ [ -z "$3" ] && die_error "no ON/OFF switch given for element $1 (item $2)"
+ [ "$3" != ON -a "$3" != OFF ] && die_error "element $1 (item $2) has status $3 instead of ON/OFF!"
+ item=$1
+ [ "$2" != '-' -a "$2" != '^' ] && item="$1 ($2)"
+ [ "$3" = ON ] && ask_yesno "Enable $1 ?" yes && output="$output $1"
+ [ "$3" = OFF ] && ask_yesno "Enable $1 ?" no && output="$output $1"
+ shift 3
done
ANSWER_CHECKLIST=$output
return 0