=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/tmux/status.c,v retrieving revision 1.205 retrieving revision 1.206 diff -c -r1.205 -r1.206 *** src/usr.bin/tmux/status.c 2020/05/16 15:16:36 1.205 --- src/usr.bin/tmux/status.c 2020/05/16 15:18:17 1.206 *************** *** 1,4 **** ! /* $OpenBSD: status.c,v 1.205 2020/05/16 15:16:36 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott --- 1,4 ---- ! /* $OpenBSD: status.c,v 1.206 2020/05/16 15:18:17 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott *************** *** 39,45 **** static char *status_prompt_complete(struct client *, const char *, u_int); static char *status_prompt_complete_window_menu(struct client *, ! struct session *, u_int, char); struct status_prompt_menu { struct client *c; --- 39,45 ---- static char *status_prompt_complete(struct client *, const char *, u_int); static char *status_prompt_complete_window_menu(struct client *, ! struct session *, const char *, u_int, char); struct status_prompt_menu { struct client *c; *************** *** 1071,1085 **** } break; case '\011': /* Tab */ ! if (c->prompt_flags & PROMPT_WINDOW) { ! s = status_prompt_complete_window_menu(c, c->session, ! 0, '\0'); ! if (s != NULL) { ! free(c->prompt_buffer); ! c->prompt_buffer = utf8_fromcstr(s); ! c->prompt_index = utf8_strlen(c->prompt_buffer); ! } ! } else if (status_prompt_replace_complete(c, NULL)) goto changed; break; case KEYC_BSPACE: --- 1071,1077 ---- } break; case '\011': /* Tab */ ! if (status_prompt_replace_complete(c, NULL)) goto changed; break; case KEYC_BSPACE: *************** *** 1537,1543 **** /* Show complete word menu. */ static char * status_prompt_complete_window_menu(struct client *c, struct session *s, ! u_int offset, char flag) { struct menu *menu; struct menu_item item; --- 1529,1535 ---- /* Show complete word menu. */ static char * status_prompt_complete_window_menu(struct client *c, struct session *s, ! const char *word, u_int offset, char flag) { struct menu *menu; struct menu_item item; *************** *** 1561,1566 **** --- 1553,1567 ---- menu = menu_create(""); RB_FOREACH(wl, winlinks, &s->windows) { + if (word != NULL && *word != '\0') { + xasprintf(&tmp, "%d", wl->idx); + if (strncmp(tmp, word, strlen(word)) != 0) { + free(tmp); + continue; + } + free(tmp); + } + list = xreallocarray(list, size + 1, sizeof *list); if (c->prompt_flags & PROMPT_WINDOW) { xasprintf(&tmp, "%d (%s)", wl->idx, wl->window->name); *************** *** 1579,1584 **** --- 1580,1589 ---- if (size == height) break; } + if (size == 0) { + menu_free(menu); + return (NULL); + } if (size == 1) { menu_free(menu); if (flag != '\0') { *************** *** 1656,1665 **** char flag = '\0'; u_int size = 0, i; ! if (*word == '\0' && (~c->prompt_flags & PROMPT_TARGET)) return (NULL); ! if ((~c->prompt_flags & PROMPT_TARGET) && strncmp(word, "-t", 2) != 0 && strncmp(word, "-s", 2) != 0) { list = status_prompt_complete_list(&size, word, offset == 0); --- 1661,1671 ---- char flag = '\0'; u_int size = 0, i; ! if (*word == '\0' && ! ((c->prompt_flags & (PROMPT_TARGET|PROMPT_WINDOW)) == 0)) return (NULL); ! if (((c->prompt_flags & (PROMPT_TARGET|PROMPT_WINDOW)) == 0) && strncmp(word, "-t", 2) != 0 && strncmp(word, "-s", 2) != 0) { list = status_prompt_complete_list(&size, word, offset == 0); *************** *** 1672,1678 **** goto found; } ! if (c->prompt_flags & PROMPT_TARGET) { s = word; flag = '\0'; } else { --- 1678,1684 ---- goto found; } ! if (c->prompt_flags & (PROMPT_TARGET|PROMPT_WINDOW)) { s = word; flag = '\0'; } else { *************** *** 1680,1685 **** --- 1686,1698 ---- flag = word[1]; offset += 2; } + + /* If this is a window completion, open the window menu. */ + if (c->prompt_flags & PROMPT_WINDOW) { + out = status_prompt_complete_window_menu(c, c->session, s, + offset, '\0'); + goto found; + } colon = strchr(s, ':'); /* If there is no colon, complete as a session. */ *************** *** 1700,1707 **** if (session == NULL) goto found; } ! out = status_prompt_complete_window_menu(c, session, offset, ! flag); if (out == NULL) return (NULL); } --- 1713,1720 ---- if (session == NULL) goto found; } ! out = status_prompt_complete_window_menu(c, session, colon + 1, ! offset, flag); if (out == NULL) return (NULL); }