| 379 | /* Return an extended command from the user */ |
| 380 | |
| 381 | int |
| 382 | curses_ext_cmd(void) |
| 383 | { |
| 384 | int letter, prompt_width, startx, starty, winx, winy; |
| 385 | int messageh, messagew, maxlen = BUFSZ - 1; |
| 386 | int ret = -1; |
| 387 | char cur_choice[BUFSZ]; |
| 388 | int matches = 0; |
| 389 | int *ecmatches = NULL; |
| 390 | WINDOW *extwin = NULL, *extwin2 = NULL; |
| 391 | |
| 392 | if (iflags.extmenu) { |
| 393 | return extcmd_via_menu(); |
| 394 | } |
| 395 | |
| 396 | startx = 0; |
| 397 | starty = 0; |
| 398 | if (iflags.wc_popup_dialog) { /* Prompt in popup window */ |
| 399 | int x0, y0, w, h; /* bounding coords of popup */ |
| 400 | |
| 401 | extwin2 = curses_create_window(TEXT_WIN, 25, 1, UP); |
| 402 | curses_set_wid_colors(TEXT_WIN, extwin2); |
| 403 | wrefresh(extwin2); |
| 404 | /* create window inside window to prevent overwriting of border */ |
| 405 | getbegyx(extwin2, y0, x0); |
| 406 | getmaxyx(extwin2, h, w); |
| 407 | extwin = newwin(1, w - 2, y0 + 1, x0 + 1); |
| 408 | if (w - 4 < maxlen) |
| 409 | maxlen = w - 4; |
| 410 | nhUse(h); /* needed only to give getmaxyx three arguments */ |
| 411 | } else { |
| 412 | curses_get_window_xy(MESSAGE_WIN, &winx, &winy); |
| 413 | curses_get_window_size(MESSAGE_WIN, &messageh, &messagew); |
| 414 | |
| 415 | if (curses_window_has_border(MESSAGE_WIN)) { |
| 416 | winx++; |
| 417 | winy++; |
| 418 | } |
| 419 | |
| 420 | winy += messageh - 1; |
| 421 | extwin = newwin(1, messagew - 2, winy, winx); |
| 422 | if (messagew - 4 < maxlen) |
| 423 | maxlen = messagew - 4; |
| 424 | custompline(OVERRIDE_MSGTYPE, "#"); |
| 425 | } |
| 426 | |
| 427 | cur_choice[0] = '\0'; |
| 428 | |
| 429 | while (1) { |
| 430 | wmove(extwin, starty, startx); |
| 431 | wclrtoeol(extwin); |
| 432 | waddstr(extwin, "# "); |
| 433 | wmove(extwin, starty, startx + 2); |
| 434 | waddstr(extwin, cur_choice); |
| 435 | wmove(extwin, starty, (int) strlen(cur_choice) + startx + 2); |
| 436 | |
| 437 | /* if we have an autocomplete command, AND it matches uniquely */ |
| 438 | if (matches == 1 && ecmatches) { |
no test coverage detected