nconf.gui.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (C) 2008 Nir Tzachar <nir.tzachar@gmail.com>
  4. *
  5. * Derived from menuconfig.
  6. */
  7. #include <xalloc.h>
  8. #include "nconf.h"
  9. #include "lkc.h"
  10. int attr_normal;
  11. int attr_main_heading;
  12. int attr_main_menu_box;
  13. int attr_main_menu_fore;
  14. int attr_main_menu_back;
  15. int attr_main_menu_grey;
  16. int attr_main_menu_heading;
  17. int attr_scrollwin_text;
  18. int attr_scrollwin_heading;
  19. int attr_scrollwin_box;
  20. int attr_dialog_text;
  21. int attr_dialog_menu_fore;
  22. int attr_dialog_menu_back;
  23. int attr_dialog_box;
  24. int attr_input_box;
  25. int attr_input_heading;
  26. int attr_input_text;
  27. int attr_input_field;
  28. int attr_function_text;
  29. int attr_function_highlight;
  30. #define COLOR_ATTR(_at, _fg, _bg, _hl) \
  31. { .attr = &(_at), .has_color = true, .color_fg = _fg, .color_bg = _bg, .highlight = _hl }
  32. #define NO_COLOR_ATTR(_at, _hl) \
  33. { .attr = &(_at), .has_color = false, .highlight = _hl }
  34. #define COLOR_DEFAULT -1
  35. struct nconf_attr_param {
  36. int *attr;
  37. bool has_color;
  38. int color_fg;
  39. int color_bg;
  40. int highlight;
  41. };
  42. static const struct nconf_attr_param color_theme_params[] = {
  43. COLOR_ATTR(attr_normal, COLOR_DEFAULT, COLOR_DEFAULT, A_NORMAL),
  44. COLOR_ATTR(attr_main_heading, COLOR_MAGENTA, COLOR_DEFAULT, A_BOLD | A_UNDERLINE),
  45. COLOR_ATTR(attr_main_menu_box, COLOR_YELLOW, COLOR_DEFAULT, A_NORMAL),
  46. COLOR_ATTR(attr_main_menu_fore, COLOR_DEFAULT, COLOR_DEFAULT, A_REVERSE),
  47. COLOR_ATTR(attr_main_menu_back, COLOR_DEFAULT, COLOR_DEFAULT, A_NORMAL),
  48. COLOR_ATTR(attr_main_menu_grey, COLOR_DEFAULT, COLOR_DEFAULT, A_NORMAL),
  49. COLOR_ATTR(attr_main_menu_heading, COLOR_GREEN, COLOR_DEFAULT, A_BOLD),
  50. COLOR_ATTR(attr_scrollwin_text, COLOR_DEFAULT, COLOR_DEFAULT, A_NORMAL),
  51. COLOR_ATTR(attr_scrollwin_heading, COLOR_GREEN, COLOR_DEFAULT, A_BOLD),
  52. COLOR_ATTR(attr_scrollwin_box, COLOR_YELLOW, COLOR_DEFAULT, A_BOLD),
  53. COLOR_ATTR(attr_dialog_text, COLOR_DEFAULT, COLOR_DEFAULT, A_BOLD),
  54. COLOR_ATTR(attr_dialog_menu_fore, COLOR_RED, COLOR_DEFAULT, A_STANDOUT),
  55. COLOR_ATTR(attr_dialog_menu_back, COLOR_YELLOW, COLOR_DEFAULT, A_NORMAL),
  56. COLOR_ATTR(attr_dialog_box, COLOR_YELLOW, COLOR_DEFAULT, A_BOLD),
  57. COLOR_ATTR(attr_input_box, COLOR_YELLOW, COLOR_DEFAULT, A_NORMAL),
  58. COLOR_ATTR(attr_input_heading, COLOR_GREEN, COLOR_DEFAULT, A_BOLD),
  59. COLOR_ATTR(attr_input_text, COLOR_DEFAULT, COLOR_DEFAULT, A_NORMAL),
  60. COLOR_ATTR(attr_input_field, COLOR_DEFAULT, COLOR_DEFAULT, A_UNDERLINE),
  61. COLOR_ATTR(attr_function_text, COLOR_YELLOW, COLOR_DEFAULT, A_REVERSE),
  62. COLOR_ATTR(attr_function_highlight, COLOR_DEFAULT, COLOR_DEFAULT, A_BOLD),
  63. { /* sentinel */ }
  64. };
  65. static const struct nconf_attr_param no_color_theme_params[] = {
  66. NO_COLOR_ATTR(attr_normal, A_NORMAL),
  67. NO_COLOR_ATTR(attr_main_heading, A_BOLD | A_UNDERLINE),
  68. NO_COLOR_ATTR(attr_main_menu_box, A_NORMAL),
  69. NO_COLOR_ATTR(attr_main_menu_fore, A_STANDOUT),
  70. NO_COLOR_ATTR(attr_main_menu_back, A_NORMAL),
  71. NO_COLOR_ATTR(attr_main_menu_grey, A_NORMAL),
  72. NO_COLOR_ATTR(attr_main_menu_heading, A_BOLD),
  73. NO_COLOR_ATTR(attr_scrollwin_text, A_NORMAL),
  74. NO_COLOR_ATTR(attr_scrollwin_heading, A_BOLD),
  75. NO_COLOR_ATTR(attr_scrollwin_box, A_BOLD),
  76. NO_COLOR_ATTR(attr_dialog_text, A_NORMAL),
  77. NO_COLOR_ATTR(attr_dialog_menu_fore, A_STANDOUT),
  78. NO_COLOR_ATTR(attr_dialog_menu_back, A_NORMAL),
  79. NO_COLOR_ATTR(attr_dialog_box, A_BOLD),
  80. NO_COLOR_ATTR(attr_input_box, A_BOLD),
  81. NO_COLOR_ATTR(attr_input_heading, A_BOLD),
  82. NO_COLOR_ATTR(attr_input_text, A_NORMAL),
  83. NO_COLOR_ATTR(attr_input_field, A_UNDERLINE),
  84. NO_COLOR_ATTR(attr_function_text, A_REVERSE),
  85. NO_COLOR_ATTR(attr_function_highlight, A_BOLD),
  86. { /* sentinel */ }
  87. };
  88. void set_colors(void)
  89. {
  90. const struct nconf_attr_param *p;
  91. int pair = 0;
  92. if (has_colors()) {
  93. start_color();
  94. use_default_colors();
  95. p = color_theme_params;
  96. } else {
  97. p = no_color_theme_params;
  98. }
  99. for (; p->attr; p++) {
  100. int attr = p->highlight;
  101. if (p->has_color) {
  102. pair++;
  103. init_pair(pair, p->color_fg, p->color_bg);
  104. attr |= COLOR_PAIR(pair);
  105. }
  106. *p->attr = attr;
  107. }
  108. }
  109. /* this changes the windows attributes !!! */
  110. void print_in_middle(WINDOW *win, int y, int width, const char *str, int attrs)
  111. {
  112. wattrset(win, attrs);
  113. mvwprintw(win, y, (width - strlen(str)) / 2, "%s", str);
  114. }
  115. int get_line_no(const char *text)
  116. {
  117. int i;
  118. int total = 1;
  119. if (!text)
  120. return 0;
  121. for (i = 0; text[i] != '\0'; i++)
  122. if (text[i] == '\n')
  123. total++;
  124. return total;
  125. }
  126. const char *get_line(const char *text, int line_no)
  127. {
  128. int i;
  129. int lines = 0;
  130. if (!text)
  131. return NULL;
  132. for (i = 0; text[i] != '\0' && lines < line_no; i++)
  133. if (text[i] == '\n')
  134. lines++;
  135. return text+i;
  136. }
  137. int get_line_length(const char *line)
  138. {
  139. int res = 0;
  140. while (*line != '\0' && *line != '\n') {
  141. line++;
  142. res++;
  143. }
  144. return res;
  145. }
  146. /* print all lines to the window. */
  147. void fill_window(WINDOW *win, const char *text)
  148. {
  149. int x, y;
  150. int total_lines = get_line_no(text);
  151. int i;
  152. getmaxyx(win, y, x);
  153. /* do not go over end of line */
  154. total_lines = min(total_lines, y);
  155. for (i = 0; i < total_lines; i++) {
  156. const char *line = get_line(text, i);
  157. int len = min(get_line_length(line), x);
  158. mvwprintw(win, i, 0, "%.*s", len, line);
  159. }
  160. }
  161. /* get the message, and buttons.
  162. * each button must be a char*
  163. * return the selected button
  164. *
  165. * this dialog is used for 2 different things:
  166. * 1) show a text box, no buttons.
  167. * 2) show a dialog, with horizontal buttons
  168. */
  169. int btn_dialog(WINDOW *main_window, const char *msg, int btn_num, ...)
  170. {
  171. va_list ap;
  172. char *btn;
  173. int btns_width = 0;
  174. int msg_lines = 0;
  175. int msg_width = 0;
  176. int total_width;
  177. int win_rows = 0;
  178. WINDOW *win;
  179. WINDOW *msg_win;
  180. WINDOW *menu_win;
  181. MENU *menu;
  182. ITEM *btns[btn_num+1];
  183. int i, x, y;
  184. int res = -1;
  185. va_start(ap, btn_num);
  186. for (i = 0; i < btn_num; i++) {
  187. btn = va_arg(ap, char *);
  188. btns[i] = new_item(btn, "");
  189. btns_width += strlen(btn)+1;
  190. }
  191. va_end(ap);
  192. btns[btn_num] = NULL;
  193. /* find the widest line of msg: */
  194. msg_lines = get_line_no(msg);
  195. for (i = 0; i < msg_lines; i++) {
  196. const char *line = get_line(msg, i);
  197. int len = get_line_length(line);
  198. if (msg_width < len)
  199. msg_width = len;
  200. }
  201. total_width = max(msg_width, btns_width);
  202. /* place dialog in middle of screen */
  203. y = (getmaxy(stdscr)-(msg_lines+4))/2;
  204. x = (getmaxx(stdscr)-(total_width+4))/2;
  205. /* create the windows */
  206. if (btn_num > 0)
  207. win_rows = msg_lines+4;
  208. else
  209. win_rows = msg_lines+2;
  210. win = newwin(win_rows, total_width+4, y, x);
  211. keypad(win, TRUE);
  212. menu_win = derwin(win, 1, btns_width, win_rows-2,
  213. 1+(total_width+2-btns_width)/2);
  214. menu = new_menu(btns);
  215. msg_win = derwin(win, win_rows-2, msg_width, 1,
  216. 1+(total_width+2-msg_width)/2);
  217. set_menu_fore(menu, attr_dialog_menu_fore);
  218. set_menu_back(menu, attr_dialog_menu_back);
  219. wattrset(win, attr_dialog_box);
  220. box(win, 0, 0);
  221. /* print message */
  222. wattrset(msg_win, attr_dialog_text);
  223. fill_window(msg_win, msg);
  224. set_menu_win(menu, win);
  225. set_menu_sub(menu, menu_win);
  226. set_menu_format(menu, 1, btn_num);
  227. menu_opts_off(menu, O_SHOWDESC);
  228. menu_opts_off(menu, O_SHOWMATCH);
  229. menu_opts_on(menu, O_ONEVALUE);
  230. menu_opts_on(menu, O_NONCYCLIC);
  231. set_menu_mark(menu, "");
  232. post_menu(menu);
  233. touchwin(win);
  234. refresh_all_windows(main_window);
  235. while ((res = wgetch(win))) {
  236. switch (res) {
  237. case KEY_LEFT:
  238. menu_driver(menu, REQ_LEFT_ITEM);
  239. break;
  240. case KEY_RIGHT:
  241. menu_driver(menu, REQ_RIGHT_ITEM);
  242. break;
  243. case 9: /* TAB */
  244. if (btn_num > 1) {
  245. /* cycle through buttons */
  246. if (item_index(current_item(menu)) == btn_num - 1)
  247. menu_driver(menu, REQ_FIRST_ITEM);
  248. else
  249. menu_driver(menu, REQ_NEXT_ITEM);
  250. }
  251. break;
  252. case 10: /* ENTER */
  253. case 27: /* ESCAPE */
  254. case ' ':
  255. case KEY_F(F_BACK):
  256. case KEY_F(F_EXIT):
  257. break;
  258. }
  259. touchwin(win);
  260. refresh_all_windows(main_window);
  261. if (res == 10 || res == ' ') {
  262. res = item_index(current_item(menu));
  263. break;
  264. } else if (res == 27 || res == KEY_F(F_BACK) ||
  265. res == KEY_F(F_EXIT)) {
  266. res = KEY_EXIT;
  267. break;
  268. }
  269. }
  270. unpost_menu(menu);
  271. free_menu(menu);
  272. for (i = 0; i < btn_num; i++)
  273. free_item(btns[i]);
  274. delwin(win);
  275. return res;
  276. }
  277. int dialog_inputbox(WINDOW *main_window,
  278. const char *title, const char *prompt,
  279. const char *init, char **resultp, int *result_len)
  280. {
  281. int prompt_lines = 0;
  282. int prompt_width = 0;
  283. WINDOW *win;
  284. WINDOW *prompt_win;
  285. WINDOW *form_win;
  286. PANEL *panel;
  287. int i, x, y, lines, columns, win_lines, win_cols;
  288. int res = -1;
  289. int cursor_position = strlen(init);
  290. int cursor_form_win;
  291. char *result = *resultp;
  292. getmaxyx(stdscr, lines, columns);
  293. if (strlen(init)+1 > *result_len) {
  294. *result_len = strlen(init)+1;
  295. *resultp = result = xrealloc(result, *result_len);
  296. }
  297. /* find the widest line of msg: */
  298. prompt_lines = get_line_no(prompt);
  299. for (i = 0; i < prompt_lines; i++) {
  300. const char *line = get_line(prompt, i);
  301. int len = get_line_length(line);
  302. prompt_width = max(prompt_width, len);
  303. }
  304. if (title)
  305. prompt_width = max(prompt_width, strlen(title));
  306. win_lines = min(prompt_lines+6, lines-2);
  307. win_cols = min(prompt_width+7, columns-2);
  308. prompt_lines = max(win_lines-6, 0);
  309. prompt_width = max(win_cols-7, 0);
  310. /* place dialog in middle of screen */
  311. y = (lines-win_lines)/2;
  312. x = (columns-win_cols)/2;
  313. strncpy(result, init, *result_len);
  314. result[*result_len - 1] = '\0';
  315. /* create the windows */
  316. win = newwin(win_lines, win_cols, y, x);
  317. prompt_win = derwin(win, prompt_lines+1, prompt_width, 2, 2);
  318. form_win = derwin(win, 1, prompt_width, prompt_lines+3, 2);
  319. keypad(form_win, TRUE);
  320. wattrset(form_win, attr_input_field);
  321. wattrset(win, attr_input_box);
  322. box(win, 0, 0);
  323. wattrset(win, attr_input_heading);
  324. if (title)
  325. mvwprintw(win, 0, 3, "%s", title);
  326. /* print message */
  327. wattrset(prompt_win, attr_input_text);
  328. fill_window(prompt_win, prompt);
  329. mvwprintw(form_win, 0, 0, "%*s", prompt_width, " ");
  330. cursor_form_win = min(cursor_position, prompt_width-1);
  331. mvwprintw(form_win, 0, 0, "%s",
  332. result + cursor_position-cursor_form_win);
  333. /* create panels */
  334. panel = new_panel(win);
  335. /* show the cursor */
  336. curs_set(1);
  337. touchwin(win);
  338. refresh_all_windows(main_window);
  339. while ((res = wgetch(form_win))) {
  340. int len = strlen(result);
  341. switch (res) {
  342. case 10: /* ENTER */
  343. case 27: /* ESCAPE */
  344. case KEY_F(F_HELP):
  345. case KEY_F(F_EXIT):
  346. case KEY_F(F_BACK):
  347. break;
  348. case 8: /* ^H */
  349. case 127: /* ^? */
  350. case KEY_BACKSPACE:
  351. if (cursor_position > 0) {
  352. memmove(&result[cursor_position-1],
  353. &result[cursor_position],
  354. len-cursor_position+1);
  355. cursor_position--;
  356. cursor_form_win--;
  357. len--;
  358. }
  359. break;
  360. case KEY_DC:
  361. if (cursor_position >= 0 && cursor_position < len) {
  362. memmove(&result[cursor_position],
  363. &result[cursor_position+1],
  364. len-cursor_position+1);
  365. len--;
  366. }
  367. break;
  368. case KEY_UP:
  369. case KEY_RIGHT:
  370. if (cursor_position < len) {
  371. cursor_position++;
  372. cursor_form_win++;
  373. }
  374. break;
  375. case KEY_DOWN:
  376. case KEY_LEFT:
  377. if (cursor_position > 0) {
  378. cursor_position--;
  379. cursor_form_win--;
  380. }
  381. break;
  382. case KEY_HOME:
  383. cursor_position = 0;
  384. cursor_form_win = 0;
  385. break;
  386. case KEY_END:
  387. cursor_position = len;
  388. cursor_form_win = min(cursor_position, prompt_width-1);
  389. break;
  390. default:
  391. if ((isgraph(res) || isspace(res))) {
  392. /* one for new char, one for '\0' */
  393. if (len+2 > *result_len) {
  394. *result_len = len+2;
  395. *resultp = result = realloc(result,
  396. *result_len);
  397. }
  398. /* insert the char at the proper position */
  399. memmove(&result[cursor_position+1],
  400. &result[cursor_position],
  401. len-cursor_position+1);
  402. result[cursor_position] = res;
  403. cursor_position++;
  404. cursor_form_win++;
  405. len++;
  406. } else {
  407. mvprintw(0, 0, "unknown key: %d\n", res);
  408. }
  409. break;
  410. }
  411. if (cursor_form_win < 0)
  412. cursor_form_win = 0;
  413. else if (cursor_form_win > prompt_width-1)
  414. cursor_form_win = prompt_width-1;
  415. wmove(form_win, 0, 0);
  416. wclrtoeol(form_win);
  417. mvwprintw(form_win, 0, 0, "%*s", prompt_width, " ");
  418. mvwprintw(form_win, 0, 0, "%s",
  419. result + cursor_position-cursor_form_win);
  420. wmove(form_win, 0, cursor_form_win);
  421. touchwin(win);
  422. refresh_all_windows(main_window);
  423. if (res == 10) {
  424. res = 0;
  425. break;
  426. } else if (res == 27 || res == KEY_F(F_BACK) ||
  427. res == KEY_F(F_EXIT)) {
  428. res = KEY_EXIT;
  429. break;
  430. } else if (res == KEY_F(F_HELP)) {
  431. res = 1;
  432. break;
  433. }
  434. }
  435. /* hide the cursor */
  436. curs_set(0);
  437. del_panel(panel);
  438. delwin(prompt_win);
  439. delwin(form_win);
  440. delwin(win);
  441. return res;
  442. }
  443. /* refresh all windows in the correct order */
  444. void refresh_all_windows(WINDOW *main_window)
  445. {
  446. update_panels();
  447. touchwin(main_window);
  448. refresh();
  449. }
  450. void show_scroll_win(WINDOW *main_window,
  451. const char *title,
  452. const char *text)
  453. {
  454. (void)show_scroll_win_ext(main_window, title, (char *)text, NULL, NULL, NULL, NULL);
  455. }
  456. /* layman's scrollable window... */
  457. int show_scroll_win_ext(WINDOW *main_window, const char *title, char *text,
  458. int *vscroll, int *hscroll,
  459. extra_key_cb_fn extra_key_cb, void *data)
  460. {
  461. int res;
  462. int total_lines = get_line_no(text);
  463. int x, y, lines, columns;
  464. int start_x = 0, start_y = 0;
  465. int text_lines = 0, text_cols = 0;
  466. int total_cols = 0;
  467. int win_cols = 0;
  468. int win_lines = 0;
  469. int i = 0;
  470. WINDOW *win;
  471. WINDOW *pad;
  472. PANEL *panel;
  473. bool done = false;
  474. if (hscroll)
  475. start_x = *hscroll;
  476. if (vscroll)
  477. start_y = *vscroll;
  478. getmaxyx(stdscr, lines, columns);
  479. /* find the widest line of msg: */
  480. total_lines = get_line_no(text);
  481. for (i = 0; i < total_lines; i++) {
  482. const char *line = get_line(text, i);
  483. int len = get_line_length(line);
  484. total_cols = max(total_cols, len+2);
  485. }
  486. /* create the pad */
  487. pad = newpad(total_lines+10, total_cols+10);
  488. wattrset(pad, attr_scrollwin_text);
  489. fill_window(pad, text);
  490. win_lines = min(total_lines+4, lines-2);
  491. win_cols = min(total_cols+2, columns-2);
  492. text_lines = max(win_lines-4, 0);
  493. text_cols = max(win_cols-2, 0);
  494. /* place window in middle of screen */
  495. y = (lines-win_lines)/2;
  496. x = (columns-win_cols)/2;
  497. win = newwin(win_lines, win_cols, y, x);
  498. keypad(win, TRUE);
  499. /* show the help in the help window, and show the help panel */
  500. wattrset(win, attr_scrollwin_box);
  501. box(win, 0, 0);
  502. wattrset(win, attr_scrollwin_heading);
  503. mvwprintw(win, 0, 3, " %s ", title);
  504. panel = new_panel(win);
  505. /* handle scrolling */
  506. while (!done) {
  507. copywin(pad, win, start_y, start_x, 2, 2, text_lines,
  508. text_cols, 0);
  509. print_in_middle(win,
  510. text_lines+2,
  511. text_cols,
  512. "<OK>",
  513. attr_dialog_menu_fore);
  514. wrefresh(win);
  515. res = wgetch(win);
  516. switch (res) {
  517. case KEY_NPAGE:
  518. case ' ':
  519. case 'd':
  520. start_y += text_lines-2;
  521. break;
  522. case KEY_PPAGE:
  523. case 'u':
  524. start_y -= text_lines+2;
  525. break;
  526. case KEY_HOME:
  527. start_y = 0;
  528. break;
  529. case KEY_END:
  530. start_y = total_lines-text_lines;
  531. break;
  532. case KEY_DOWN:
  533. case 'j':
  534. start_y++;
  535. break;
  536. case KEY_UP:
  537. case 'k':
  538. start_y--;
  539. break;
  540. case KEY_LEFT:
  541. case 'h':
  542. start_x--;
  543. break;
  544. case KEY_RIGHT:
  545. case 'l':
  546. start_x++;
  547. break;
  548. default:
  549. if (extra_key_cb) {
  550. size_t start = (get_line(text, start_y) - text);
  551. size_t end = (get_line(text, start_y + text_lines) - text);
  552. if (extra_key_cb(res, start, end, data)) {
  553. done = true;
  554. break;
  555. }
  556. }
  557. }
  558. if (res == 0 || res == 10 || res == 27 || res == 'q' ||
  559. res == KEY_F(F_HELP) || res == KEY_F(F_BACK) ||
  560. res == KEY_F(F_EXIT))
  561. break;
  562. if (start_y < 0)
  563. start_y = 0;
  564. if (start_y >= total_lines-text_lines)
  565. start_y = total_lines-text_lines;
  566. if (start_x < 0)
  567. start_x = 0;
  568. if (start_x >= total_cols-text_cols)
  569. start_x = total_cols-text_cols;
  570. }
  571. if (hscroll)
  572. *hscroll = start_x;
  573. if (vscroll)
  574. *vscroll = start_y;
  575. del_panel(panel);
  576. delwin(win);
  577. refresh_all_windows(main_window);
  578. return res;
  579. }