First level menu works
authorCameron Ball <c.ball1729@gmail.com>
Sat, 13 Jun 2015 03:26:02 +0000 (11:26 +0800)
committerCameron Ball <c.ball1729@gmail.com>
Sat, 13 Jun 2015 03:26:02 +0000 (11:26 +0800)
menu.sh

diff --git a/menu.sh b/menu.sh
index 711cd8f..45f054a 100755 (executable)
--- a/menu.sh
+++ b/menu.sh
@@ -167,15 +167,15 @@ function render_menu()
                #Yes I do, it's because $line has a tab followed by text in it.
                #Without the quotes it thinks what follows the tab is the second arg
                if is_item_of_menu "$line" "$1"; then
+                       #Match on name as it is unique per item
+                       #Multiple lines will match per item without this
                        name_re=".name[[:space:]].+?\"(.+)\""
-                       desc_re=".description[[:space:]].+?\"(.+)\""
-                       
-                       #todo: the issue here is that the name and description are on different line things now (before it was the same)
-                       #probably have to scrap this loop and extract the name and desc using one of my helper function things
-                       #see run_task where I use magic to go back a level (so like from thing.thing2.thing3 -> thing.thing2 and tack on
-                       #the extra bit I wanna extract
-                       [[ $line =~ $name_re ]] && debug "hello" && name=${BASH_REMATCH[1]} && [[ $line =~ $desc_re ]] && desc=${BASH_REMATCH[1]} && debug "${name} ${desc}" && options+=("$name" "$desc")
-sleep 1
+                       if [[ $line =~ $name_re ]]; then
+                               key=$(get_key_from_line "$line")
+                               desc=$(get_value_from_key "${key%.*}.description")
+                               name=$(get_value_from_key "${key%.*}.name")
+                               options+=("$name" "$desc")
+                       fi
                fi
        done <<< "$menu_json"