Mike Gerwitz

Activist for User Freedom

aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMike Gerwitz <mike@mikegerwitz.com>2011-08-25 18:52:31 -0400
committerMike Gerwitz <mike@mikegerwitz.com>2011-08-25 18:55:31 -0400
commitce8cf68ad8948d0e2a6fbc9eebf9d80559bc372f (patch)
tree8d6f6a8db7859975e15b398b5edf7601f4cbb711
parent10e2ff438c34c178afe3ec7f8e896f7f09f7df2b (diff)
downloadgsgp-ce8cf68ad8948d0e2a6fbc9eebf9d80559bc372f.tar.gz
gsgp-ce8cf68ad8948d0e2a6fbc9eebf9d80559bc372f.tar.bz2
gsgp-ce8cf68ad8948d0e2a6fbc9eebf9d80559bc372f.zip
process-input will now prompt for the user's intentions if only one word is provided
-rwxr-xr-xtest/test-process-input12
-rwxr-xr-xutil/process-input16
2 files changed, 27 insertions, 1 deletions
diff --git a/test/test-process-input b/test/test-process-input
index dafec75..85ec811 100755
--- a/test/test-process-input
+++ b/test/test-process-input
@@ -101,3 +101,15 @@ assert-equal "$( tryinput "moo foo" )" "" || {
fail "Actions should not fall through to other objects (missing nl)"
}
+# simply naming an object should question the user's intentions
+assert-equal "$( tryinput "door" )" "MSG What about door?" || {
+ fail "Naming object should ask user what their intention is"
+}
+
+# if a single word is entered, and it's not a known object, we don't know what
+# to do (maybe in the future we'll want to scan possible actions and make
+# suggestions)
+assert-equal "$( tryinput "tickle" )" "MSG Please elaborate." || {
+ fail "Naming an unknown object should prompt user to elaborate"
+}
+
diff --git a/util/process-input b/util/process-input
index c2dde11..ef28e78 100755
--- a/util/process-input
+++ b/util/process-input
@@ -40,7 +40,21 @@ if [ $count -gt $max_words ]; then
fi
action=$( cut -d' ' -f1 <<< "$words" )
-object=$( cut -d' ' -f2 <<< "$words" )
+object=$( cut -s -d' ' -f2 <<< "$words" )
+
+# if only one word was given, then we need to ask what to do
+if [ "$count" -eq 1 ]; then
+ # is it a known object?
+ grep -q "$action" <<< "$scene" && {
+ echo "MSG What about $action?"
+ exit 2
+ }
+
+ # otherwise, we have no idea what the user is babbling about
+ echo "MSG Please elaborate."
+ exit 2
+fi
+
# check for am action on a known object and output the associated commands, left
# trimmed