TTY: Implement the menu_search command
authorPasi Kallinen <paxed@alt.org>
Wed, 11 Mar 2015 19:56:12 +0000 (21:56 +0200)
committerPasi Kallinen <paxed@alt.org>
Tue, 17 Mar 2015 16:47:25 +0000 (18:47 +0200)
When in a menu that allows selecting entries, press ':'
to enter any text. Entries that match the text (via pmatch)
will be toggled.

doc/Guidebook.mn
doc/fixes35.0
win/tty/wintty.c

index 4c499ac96fcbad21bc75db232817b0f5fc39ddcb..82fa2d195a6ed70fc7c4d5ec2dee14bd97f01aec 100644 (file)
@@ -2104,7 +2104,7 @@ Implemented by the Amiga, Gem and tty ports.
 Default '<'.
 .lp menu_search
 Menu character accelerator to search for a menu item.
-Implemented by the Amiga, Gem and X11 ports.
+Implemented by the Amiga, Gem, X11 and tty ports.
 Default ':'.
 .lp menu_select_all
 Menu character accelerator to select all items in a menu.
index 89646e389e1cea517f28d5e0d0ba0ddc04946ffd..2da27738f29edf709192c076a94db9f6105381cf 100644 (file)
@@ -1097,6 +1097,7 @@ win32tty: support for 'selectsaved' option for menu of existing save files
        to choose from at game startup
 tty: add window port routines for saving/restoring message history
 tty: enhanced role, race, &c selection at start of new game
+tty: implement : (menu_search) command
 smartphone: added "Type Cmd" command that allows to type arbitrary commands 
        using phone keypad
 smartphone: added Q(quiver) command to "Attack" layout
index 19af943b9a18de7857234c064dd4429e28b8b2df..a201218e76ffdebcdff5db7d600053f1b86fbd22 100644 (file)
@@ -201,6 +201,7 @@ static const char default_menu_cmds[] = {
        MENU_SELECT_PAGE,
        MENU_UNSELECT_PAGE,
        MENU_INVERT_PAGE,
+       MENU_SEARCH,
        0       /* null terminator */
 };
 
@@ -1228,6 +1229,42 @@ tty_clear_nhwindow(window)
     cw->curx = cw->cury = 0;
 }
 
+
+boolean
+toggle_menu_curr(window, curr, lineno, in_view, counting, count)
+winid window;
+tty_menu_item *curr;
+int lineno;
+boolean in_view, counting;
+long count;
+{
+    if (curr->selected) {
+       if (counting && count > 0) {
+           curr->count = count;
+           if (in_view) set_item_state(window, lineno, curr);
+           return TRUE;
+       } else { /* change state */
+           curr->selected = FALSE;
+           curr->count = -1L;
+           if (in_view) set_item_state(window, lineno, curr);
+           return TRUE;
+       }
+    } else {   /* !selected */
+       if (counting && count > 0) {
+           curr->count = count;
+           curr->selected = TRUE;
+           if (in_view) set_item_state(window, lineno, curr);
+           return TRUE;
+       } else if (!counting) {
+           curr->selected = TRUE;
+           if (in_view) set_item_state(window, lineno, curr);
+           return TRUE;
+       }
+       /* do nothing counting&&count==0 */
+    }
+    return FALSE;
+}
+
 STATIC_OVL void
 dmore(cw, s)
     register struct WinDesc *cw;
@@ -1600,6 +1637,33 @@ struct WinDesc *cw;
                if (cw->how == PICK_ANY)
                    invert_all(window, page_start, page_end, 0);
                break;
+           case MENU_SEARCH:
+               if (cw->how == PICK_NONE) {
+                   tty_nhbell();
+                   break;
+               } else {
+                   char searchbuf[BUFSZ], tmpbuf[BUFSZ];
+                   boolean on_curr_page = FALSE;
+                   int lineno = 0;
+                   tty_getlin("Search for:", tmpbuf);
+                   if (!tmpbuf || tmpbuf[0] == '\033') break;
+                   Sprintf(searchbuf, "*%s*", tmpbuf);
+                   for (curr = cw->mlist; curr; curr = curr->next) {
+                       if (on_curr_page) lineno++;
+                       if (curr == page_start)
+                           on_curr_page = TRUE;
+                       else if (curr == page_end)
+                           on_curr_page = FALSE;
+                       if (curr->identifier.a_void && pmatch(searchbuf, curr->str)) {
+                           toggle_menu_curr(window, curr, lineno, on_curr_page, counting, count);
+                           if (cw->how == PICK_ONE) {
+                               finished = TRUE;
+                               break;
+                           }
+                       }
+                   }
+               }
+               break;
            default:
                if (cw->how == PICK_NONE || !index(resp, morc)) {
                    /* unacceptable input received */
@@ -1618,27 +1682,7 @@ struct WinDesc *cw;
                        curr != page_end;
                        n++, curr = curr->next)
                    if (morc == curr->selector) {
-                       if (curr->selected) {
-                           if (counting && count > 0) {
-                               curr->count = count;
-                               set_item_state(window, n, curr);
-                           } else { /* change state */
-                               curr->selected = FALSE;
-                               curr->count = -1L;
-                               set_item_state(window, n, curr);
-                           }
-                       } else {        /* !selected */
-                           if (counting && count > 0) {
-                               curr->count = count;
-                               curr->selected = TRUE;
-                               set_item_state(window, n, curr);
-                           } else if (!counting) {
-                               curr->selected = TRUE;
-                               set_item_state(window, n, curr);
-                           }
-                           /* do nothing counting&&count==0 */
-                       }
-
+                       toggle_menu_curr(window, curr, n, TRUE, counting, count);
                        if (cw->how == PICK_ONE) finished = TRUE;
                        break;  /* from `for' loop */
                    }