home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume16 / pcomm2 / part06 / s_prompt.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-09-14  |  2.9 KB  |  141 lines

  1. /*
  2.  * Prompting routines used in the setup menus.
  3.  */
  4.  
  5. #include <stdio.h>
  6. #include <curses.h>
  7. #include "config.h"
  8. #include "misc.h"
  9.  
  10. /*
  11.  * Prompt for a string at line 21 (with optional line 22 for additional
  12.  * information).  Display the new string in bold at its original location
  13.  * in the menu.  Used in virtually all of the *_setup() routines.
  14.  */
  15.  
  16. char *
  17. str_prompt(win, y, x, p1, p2)
  18. WINDOW *win;
  19. int y, x;
  20. char *p1, *p2;
  21. {
  22.     extern char *null_ptr;
  23.     char *ans, *get_str();
  24.                     /* print first prompt last */
  25.     mvwaddstr(win, 22, 0, p2);
  26.     mvwaddstr(win, 21, 0, p1);
  27.     waddstr(win, ": ");
  28.     wrefresh(win);
  29.  
  30.     if ((ans = get_str(win, 39, "", "")) == NULL)
  31.         return(NULL);
  32.                     /* check the value */
  33.     if (!strcmp(ans, " "))
  34.         ans = null_ptr;
  35.                     /* display the value in bold */
  36.     clear_line(win, y, x, 0);
  37.     wattrstr(win, A_BOLD, ans);
  38.  
  39.     return(ans);
  40. }
  41.  
  42. /*
  43.  * Same as above, except we return a single character.
  44.  */
  45.  
  46. char
  47. chr_prompt(win, y, x, p1, p2)
  48. WINDOW *win;
  49. int y, x;
  50. char *p1, *p2;
  51. {
  52.     char *ans, *get_str();
  53.                     /* print first prompt last */
  54.     mvwaddstr(win, 22, 0, p2);
  55.     mvwaddstr(win, 21, 0, p1);
  56.     waddstr(win, ": ");
  57.     wrefresh(win);
  58.  
  59.     if ((ans = get_str(win, 1, "", "")) == NULL)
  60.         return(NULL);
  61.                     /* display the value in bold */
  62.     mvwaddstr(win, y, x, "  ");
  63.     wrefresh(win);
  64.     mvwattrstr(win, y, x, A_BOLD, ans);
  65.  
  66.     return(*ans);
  67. }
  68.  
  69. /*
  70.  * Same as above, except that it prompts for a three digit number.
  71.  */
  72.  
  73. int
  74. num_prompt(win, y, x, p1, p2)
  75. WINDOW *win;
  76. int y, x;
  77. char *p1, *p2;
  78. {
  79.     int i;
  80.                     /* print first prompt last */
  81.     mvwaddstr(win, 22, 0, p2);
  82.     mvwaddstr(win, 21, 0, p1);
  83.     waddstr(win, ": ");
  84.     wrefresh(win);
  85.  
  86.     if ((i = get_num(win, 3)) == -1)
  87.         return(-1);
  88.                     /* display the value in bold */
  89.     mvwaddstr(win, y, x, "    ");
  90.     wrefresh(win);
  91.     mvwattrnum(win, y, x, A_BOLD, i);
  92.                     /* return the number */
  93.     return(i);
  94. }
  95.  
  96. /*
  97.  * Prompts for a selection from a menu.  We display the prompt lines,
  98.  * and show the choices one at a time.  The user selects the currently
  99.  * showing choice by hitting a carriage return.  Unlike the similar
  100.  * routines in d_prompt(), the first choice shown is not necessarily
  101.  * the current.
  102.  */
  103.  
  104. char *v_yes[3] = {"YES", "NO", NULL};
  105.  
  106. char *
  107. menu_prompt(win, y, x, p, menu)
  108. WINDOW *win;
  109. int y, x;
  110. char *p, *menu[];
  111. {
  112.     char ans;
  113.     int i, cy, cx;
  114.                     /* print first prompt last */
  115.     mvwaddstr(win, 22, 0, "Press any key to change, or <CR> to accept");
  116.     mvwaddstr(win, 21, 0, p);
  117.     waddstr(win, ": ");
  118.                     /* show first choice */
  119.     i = 0;
  120.     getyx(win, cy, cx);
  121.     mvwprintw(win, cy, cx, "%-30.30s", menu[i]);
  122.     wmove(win, cy, cx);
  123.     wrefresh(win);
  124.                     /* show the choices one at a time */
  125.     while ((ans = wgetch(win)) != '\r') {
  126.         i++;
  127.         if (menu[i] == NULL)
  128.             i = 0;
  129.         if (ans == ESC)
  130.             return(NULL);
  131.         mvwprintw(win, cy, cx, "%-30.30s", menu[i]);
  132.         wmove(win, cy, cx);
  133.         wrefresh(win);
  134.     }
  135.                     /* display the value in bold */
  136.     clear_line(win, y, x, 0);
  137.     wattrstr(win, A_BOLD, menu[i]);
  138.                     /* return the value */
  139.     return(menu[i]);
  140. }
  141.