Misc tweaks / bug fixes

- readd "power off" to the main menu
- fix bug where stdout overflows into menu text
- remove +++++Go Back+++++ from main menu as there is nothing to go back to (detects menu depth)

Change-Id: Icb84ac86e55712412d07add0ab76955d7902f07c
diff --git a/ui.c b/ui.c
index b616639..c048948 100644
--- a/ui.c
+++ b/ui.c
@@ -237,6 +237,7 @@
 
         int i = 0;
         int j = 0;
+        int offset = 0;         // offset of separating bar under menus
         int row = 0;            // current row that we are drawing on
         if (show_menu) {
             gr_color(MENU_TEXT_COLOR);
@@ -266,8 +267,12 @@
                 }
                 row++;
             }
-            gr_fill(0, row*CHAR_HEIGHT+CHAR_HEIGHT/2-1,
-                    gr_fb_width(), row*CHAR_HEIGHT+CHAR_HEIGHT/2+1);
+
+            if (menu_items <= MAX_ROWS)
+                offset = 1;
+                    
+            gr_fill(0, (row-offset)*CHAR_HEIGHT+CHAR_HEIGHT/2-1,
+                    gr_fb_width(), (row-offset)*CHAR_HEIGHT+CHAR_HEIGHT/2+1);
         }
 
         gr_color(NORMAL_TEXT_COLOR);
@@ -652,10 +657,13 @@
             menu[i][text_cols-1] = '\0';
         }
 
-        if (gShowBackButton) {
+        if (gShowBackButton && ui_menu_level > 0) {
             strcpy(menu[i], " - +++++Go Back+++++");
             ++i;
         }
+        
+        strcpy(menu[i], " ");
+        ++i;
 
         menu_items = i - menu_top;
         show_menu = 1;
@@ -663,7 +671,7 @@
         update_screen_locked();
     }
     pthread_mutex_unlock(&gUpdateMutex);
-    if (gShowBackButton) {
+    if (gShowBackButton && ui_menu_level > 0) {
         return menu_items - 1;
     }
     return menu_items;
@@ -676,8 +684,8 @@
         old_sel = menu_sel;
         menu_sel = sel;
 
-        if (menu_sel < 0) menu_sel = menu_items + menu_sel;
-        if (menu_sel >= menu_items) menu_sel = menu_sel - menu_items;
+        if (menu_sel < 0) menu_sel = menu_items-1 + menu_sel;
+        if (menu_sel >= menu_items-1) menu_sel = menu_sel - menu_items+1;
 
 
         if (menu_sel < menu_show_start && menu_show_start > 0) {