Back to index

tetex-bin  3.0
Defines | Functions
gauge.c File Reference
#include "dialog.h"

Go to the source code of this file.

Defines

#define BUFLEN   1024

Functions

int dialog_guage (char *title, char *prompt, int height, int width, int percent)

Define Documentation

#define BUFLEN   1024

Definition at line 25 of file gauge.c.


Function Documentation

int dialog_guage ( char *  title,
char *  prompt,
int  height,
int  width,
int  percent 
)

Definition at line 35 of file gauge.c.

{
  int i, x, y;
  char buf[BUFLEN];
  char prompt_buf[BUFLEN];
  WINDOW *dialog;

  /* center dialog box on screen */
  x = (COLS - width)/2;
  y = (LINES - height)/2;

#ifdef HAVE_NCURSES
  if (use_shadow)
    draw_shadow(stdscr, y, x, height, width);
#endif
  dialog = newwin(height, width, y, x);
  keypad(dialog, TRUE);

  do {
      werase(dialog);
      draw_box(dialog, 0, 0, height, width, dialog_attr, border_attr);

      if (title != NULL) {
         wattrset(dialog, title_attr);
         wmove(dialog, 0, (width - strlen(title))/2 - 1);
         waddch(dialog, ' ');
         waddstr(dialog, title);
         waddch(dialog, ' ');
      }

      wattrset(dialog, dialog_attr);
      print_autowrap(dialog, prompt, width-2, 1, 2);

      draw_box(dialog, height - 4, 3, 3, width - 6, dialog_attr, border_attr);

      wmove(dialog, height - 3, 4);
      wattrset(dialog, title_attr);
      for (i = 0; i < (width - 8); i++) {
         waddch(dialog, ' ');
      }

      wattrset(dialog, title_attr);
      wmove(dialog, height - 3, (width / 2) - 2);
      sprintf(buf, "%3d%%", percent);
      waddstr(dialog, buf);

      x = (percent * (width - 8)) / 100;
      wattrset(dialog, item_selected_attr);
      wmove(dialog, height - 3, 4);
      for (i = 0; i < x; i++) {
         waddch(dialog, winch(dialog));
      }
  
      wrefresh(dialog);

      if (feof(stdin)) {
         break;
      }
      
      fgets(buf, BUFLEN, stdin);
      if (buf[0] == 'X') {
         /* Next line is percentage */
         fgets(buf, BUFLEN, stdin);
         percent = atoi(buf);

         /* Rest is message text */
         prompt_buf[0] = '\0';
         while (strncmp(fgets(buf, BUFLEN, stdin), "XXX", 3)) {
             strcat(prompt_buf, buf);
         }
         prompt = prompt_buf;
      } else {
         percent = atoi(buf);
      }
  } while (1);
  
  delwin(dialog);
  return(0);
}

Here is the call graph for this function:

Here is the caller graph for this function: