Skip to content

Commit

Permalink
making dialog work, adding example
Browse files Browse the repository at this point in the history
  • Loading branch information
jmervine committed Nov 17, 2015
1 parent cc9f269 commit 2d79280
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
25 changes: 25 additions & 0 deletions examples/confirm_dialog.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/env bash

source shml.sh
on_human() {
dialog "What is your name?" "on_dialog"
}

on_dialog() {
echo "$(color green "Hello, $1! $(emoji beer)")"
}

on_not_human() {
confirm "$(color red "Do you come in peace?")" "on_friend" "on_enemy"
}

on_friend() {
echo "$(emoji '=)') $(emoji beer)"
}

on_enemy() {
echo "$(emoji rage) $(emoji poop)"
}

confirm "$(color blue "Are you human?")" "on_human" "on_not_human"
exit 0
12 changes: 8 additions & 4 deletions shml.sh
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,11 @@ progress() {
##
__default_confirm_success_input="y Y yes Yes YES ok OK Ok okay Okay OKAY k K continue Continue CONTINUE proceed Proceed PROCEED success Success SUCCESS successful Successful SUCCESSFUL good Good GOOD"
confirm() {
# space delimited list of acceptable answers to return true
[[ -z $1 ]] && return 127

[[ -z $SHML_CONFIRM_SUCCESS ]] && SHML_CONFIRM_SUCCESS=$__default_confirm_success_input

echo -ne "$1"
echo -ne "$1 "
local found=false
while read __input; do
for str in $(echo $SHML_CONFIRM_SUCCESS); do
Expand All @@ -116,9 +117,12 @@ confirm() {
}

dialog() {
echo -ne "$1"
[[ -z $1 ]] && return 127
[[ -z $2 ]] && return 127

echo -en "$1 "
while read __input; do
echo -ne $__input
eval "$2 $__input"
break
done
}
Expand Down

0 comments on commit 2d79280

Please sign in to comment.