Example #1
0
/* implement basic frame work to build a field input */
char *
input_string (WINDOW * win, int pos_y, int pos_x, size_t max_width,
              const char *str, int enable_case, int *toggle_case)
{
  char *s = xmalloc (max_width + 1), *tmp;
  size_t i, c, pos = 0, x = 0, quit = 1, len = 0, size_x = 0, size_y = 0;

  getmaxyx (win, size_y, size_x);
  size_x -= 4;

  /* are we setting a default string */
  if (str) {
    len = MIN (max_width, strlen (str));
    memcpy (s, str, len);
    s[len] = '\0';

    x = pos = 0;
    /* is the default str length greater than input field? */
    if (strlen (s) > size_x) {
      tmp = xstrdup (&s[0]);
      tmp[size_x] = '\0';
      mvwprintw (win, pos_y, pos_x, "%s", tmp);
      free (tmp);
    } else {
      mvwprintw (win, pos_y, pos_x, "%s", s);
    }
  } else {
    s[0] = '\0';
  }

  if (enable_case)
    mvwprintw (win, size_y - 2, 1, " %s", CSENSITIVE);

  wmove (win, pos_y, pos_x + x);
  wrefresh (win);

  curs_set (1);
  while (quit) {
    c = wgetch (stdscr);
    switch (c) {
    case 1:    /* ^a   */
    case 262:  /* HOME */
      pos = x = 0;
      break;
    case 5:
    case 360:  /* END of line */
      if (strlen (s) > size_x) {
        x = size_x;
        pos = strlen (s) - size_x;
      } else {
        pos = 0;
        x = strlen (s);
      }
      break;
    case 7:    /* ^g  */
    case 27:   /* ESC */
      pos = x = 0;
      if (str && *str == '\0')
        s[0] = '\0';
      quit = 0;
      break;
    case 9:    /* TAB   */
      if (!enable_case)
        break;
      *toggle_case = *toggle_case == 0 ? 1 : 0;
      if (*toggle_case)
        mvwprintw (win, size_y - 2, 1, " %s", CISENSITIVE);
      else if (!*toggle_case)
        mvwprintw (win, size_y - 2, 1, " %s", CSENSITIVE);
      break;
    case 21:   /* ^u */
      s[0] = '\0';
      pos = x = 0;
      break;
    case 8:    /* xterm-256color */
    case 127:
    case KEY_BACKSPACE:
      if (pos + x > 0) {
        memmove (&s[(pos + x) - 1], &s[pos + x], (max_width - (pos + x)) + 1);
        if (pos <= 0)
          x--;
        else
          pos--;
      }
      break;
    case KEY_LEFT:
      if (x > 0)
        x--;
      else if (pos > 0)
        pos--;
      break;
    case KEY_RIGHT:
      if ((x + pos) < strlen (s)) {
        if (x < size_x)
          x++;
        else
          pos++;
      }
      break;
    case 0x0a:
    case 0x0d:
    case KEY_ENTER:
      quit = 0;
      break;
    default:
      if (strlen (s) == max_width)
        break;
      if (!isprint (c))
        break;

      if (strlen (s) == pos) {
        s[pos + x] = c;
        s[pos + x + 1] = '\0';
        waddch (win, c);
      } else {
        memmove (&s[pos + x + 1], &s[pos + x], strlen (&s[pos + x]) + 1);
        s[pos + x] = c;
      }
      if ((x + pos) < max_width) {
        if (x < size_x)
          x++;
        else
          pos++;
      }
    }
    tmp = xstrdup (&s[pos > 0 ? pos : 0]);
    tmp[MIN (strlen (tmp), size_x)] = '\0';
    for (i = strlen (tmp); i < size_x; i++)
      mvwprintw (win, pos_y, pos_x + i, "%s", " ");
    mvwprintw (win, pos_y, pos_x, "%s", tmp);
    free (tmp);

    wmove (win, pos_y, pos_x + x);
    wrefresh (win);
  }
  curs_set (0);
  return s;
}
Example #2
0
//------------------------------------------------------------------------------
int wadd_wch( WINDOW* win, const cchar_t* wch )
{
    __QCS_FCONTEXT( "wadd_wch" );

    return wch ? waddch( win, *wch ) : ERR;
}
Example #3
0
/*
 * Display a dialog box with two buttons - Yes and No
 */
int dialog_yesno(const char *title, const char *prompt, int height, int width)
{
    int i, x, y, key = 0, button = 0;
    WINDOW *dialog;

do_resize:
    if (getmaxy(stdscr) < (height + YESNO_HEIGTH_MIN))
        return -ERRDISPLAYTOOSMALL;
    if (getmaxx(stdscr) < (width + YESNO_WIDTH_MIN))
        return -ERRDISPLAYTOOSMALL;

    /* center dialog box on screen */
    x = (getmaxx(stdscr) - width) / 2;
    y = (getmaxy(stdscr) - height) / 2;

    draw_shadow(stdscr, y, x, height, width);

    dialog = newwin(height, width, y, x);
    keypad(dialog, TRUE);

    draw_box(dialog, 0, 0, height, width,
             dlg.dialog.atr, dlg.border.atr);
    wattrset(dialog, dlg.border.atr);
    mvwaddch(dialog, height - 3, 0, ACS_LTEE);
    for (i = 0; i < width - 2; i++)
        waddch(dialog, ACS_HLINE);
    wattrset(dialog, dlg.dialog.atr);
    waddch(dialog, ACS_RTEE);

    print_title(dialog, title, width);

    wattrset(dialog, dlg.dialog.atr);
    print_autowrap(dialog, prompt, width - 2, 1, 3);

    print_buttons(dialog, height, width, 0);

    while (key != KEY_ESC) {
        key = wgetch(dialog);
        switch (key) {
        case 'Y':
        case 'y':
            delwin(dialog);
            return 0;
        case 'N':
        case 'n':
            delwin(dialog);
            return 1;

        case TAB:
        case KEY_LEFT:
        case KEY_RIGHT:
            button = ((key == KEY_LEFT ? --button : ++button) < 0) ? 1 : (button > 1 ? 0 : button);

            print_buttons(dialog, height, width, button);
            wrefresh(dialog);
            break;
        case ' ':
        case '\n':
            delwin(dialog);
            return button;
        case KEY_ESC:
            key = on_key_esc(dialog);
            break;
        case KEY_RESIZE:
            delwin(dialog);
            on_key_resize();
            goto do_resize;
        }
    }

    delwin(dialog);
    return key;		/* ESC pressed */
}
Example #4
0
File: ndwin.c Project: Orc/ndialog
/*
 * drawbox: draw a box with an optional horizontal dividing line.
 */
void
drawbox(WINDOW *win,			/* ... in the given WINDOW */
        int y, int x,			/* at this origin */
	int height, int width,		/* this high, this wide */
	int slice,			/* with a dividing line */
	int sunlight, int shade)	/* cheesy 3-d effects */
{
    int i, j;
    int right = width-1,
	bottom = height-1;

    for (i = 0; i < height; i++) {
	wmove(win, i+y, x);
	for (j = 0; j < width; j++) {
	    if (i == 0)			/* topline */
		if (j == 0) {		/* upper left corner */
		    setcolor(win, sunlight);
		    waddch(win, ACS_ULCORNER);
		}
		else if (j == right) {	/* upper right corner */
		    setcolor(win, shade);
		    waddch(win, ACS_URCORNER);
		}
		else {
		    setcolor(win, sunlight);
		    waddch(win, ACS_HLINE);
		}
	    else if (i == bottom)	/* bottom line */
		if (j == 0) {		/* lower left corner */
		    setcolor(win, sunlight);
		    waddch(win, ACS_LLCORNER);
		}
		else if (j == right) {	/* lower right corner */
		    setcolor(win, shade);
		    waddch(win, ACS_LRCORNER);
		}
		else {
		    setcolor(win, shade);
		    waddch(win, ACS_HLINE);
		}
	    else if (i == slice)	/* dividing line */
		if (j == 0) {		/* left side */
		    setcolor(win, sunlight);
		    waddch(win, ACS_LTEE);
		}
		else if (j == right) {	/* or right side */
		    setcolor(win, shade);
		    waddch(win, ACS_RTEE);
		}
		else {
		    setcolor(win, sunlight);
		    waddch(win, ACS_HLINE);
		}
	    else {
		if (j == 0) {		/* left side */
		    setcolor(win, sunlight);
		    waddch(win, ACS_VLINE);
		}
		else if (j == right) {	/* or right side */
		    setcolor(win, shade);
		    waddch(win, ACS_VLINE);
		}
		else {
		    setcolor(win, WINDOW_COLOR);
		    waddch(win, ' ');
		}
	    }
	}
    }
} /* drawbox */
Example #5
0
//------------------------------------------------------------------------------
int waddch( WINDOW* win, const chtype ch )
{
	__QCS_FCONTEXT( "waddch" );

    int x, y;
    chtype text, attr;
    bool xlat;

    PDC_LOG(("waddch() - called: win=%p ch=%x (text=%c attr=0x%x)\n",
             win, ch, ch & A_CHARTEXT, ch & A_ATTRIBUTES));

    if( !win )
	{
        return ERR;
	}

    x = win->_curx;
    y = win->_cury;

    if( y > win->_maxy || x > win->_maxx || y < 0 || x < 0 )
	{
        return ERR;
	}

    xlat = !SP->raw_out && !(ch & A_ALTCHARSET);
    text = ch & A_CHARTEXT;
    attr = ch & A_ATTRIBUTES;

    if( xlat && ( text < ' ' || text == 0x7f ) )
    {
        int x2;

        switch( text )
        {
        case '\t':
            for( x2 = ( ( x / TABSIZE ) + 1 ) * TABSIZE; x < x2; x++ )
            {
                if( waddch( win, attr | ' ' ) == ERR )
				{
                    return ERR;
				}

                // if tab to next line, exit the loop

                if( !win->_curx )
				{
                    break;
				}
            }
            return 0;

        case '\n':
            // if lf -> crlf

            if( !SP->raw_out )
			{
                x = 0;
			}

            wclrtoeol( win );

            if( ++y > win->_bmarg )
            {
                y--;

                if( wscrl( win, 1 ) == ERR )
				{
                    return ERR;
				}
            }

            break;

        case '\b':
            // don't back over left margin

            if( --x < 0 )
        case '\r':
			{
                x = 0;
			}
            break;

        case 0x7f:

            if( waddch( win, attr | '^' ) == ERR )
			{
                return ERR;
			}

            return waddch( win, attr | '?' );

        default:
            // handle control chars

            if( waddch( win, attr | '^' ) == ERR )
			{
                return ERR;
			}

            return waddch( win, ch + '@' );
        }
    }
    else
    {
        /* If the incoming character doesn't have its own attribute,
           then use the current attributes for the window. If it has
           attributes but not a color component, OR the attributes to
           the current attributes for the window. If it has a color
           component, use the attributes solely from the incoming
           character. */

        if( !( attr & A_COLOR ) )
		{
            attr |= win->_attrs;
		}

        /* wrs (4/10/93): Apply the same sort of logic for the window 
           background, in that it only takes precedence if other color 
           attributes are not there and that the background character 
           will only print if the printing character is blank. */

        if( !( attr & A_COLOR ) )
		{
            attr |= win->_bkgd & A_ATTRIBUTES;
		}
        else
		{
            attr |= win->_bkgd & ( A_ATTRIBUTES ^ A_COLOR );
		}

        if( text == ' ' )
		{
            text = win->_bkgd & A_CHARTEXT;
		}

        // Add the attribute back into the character.

        text |= attr;

        /* Only change _firstch/_lastch if the character to be added is
           different from the character/attribute that is already in
           that position in the window. */

        if( win->_y[ y ][ x ] != text )
        {
            if( win->_firstch[ y ] == _NO_CHANGE )
			{
                win->_firstch[ y ] = win->_lastch[ y ] = x;
			}
            else
			{
                if( x < win->_firstch[ y ] )
				{
                    win->_firstch[ y ] = x;
				}
                else
				{
                    if( x > win->_lastch[ y ] )
					{
                        win->_lastch[ y ] = x;
					}
				}
			}

            win->_y[ y ][ x ] = text;
        }

        if( ++x >= win->_maxx )
        {
            // wrap around test

            x = 0;

            if( ++y > win->_bmarg )
            {
                y--;

                if( wscrl( win, 1 ) == ERR )
                {
                    PDC_sync( win );
                    return ERR;
                }
            }
        }
    }

    win->_curx = x;
    win->_cury = y;

    if( win->_immed )
	{
        wrefresh( win );
	}

    if( win->_sync )
	{
        wsyncup( win );
	}

    return 0;
}
Example #6
0
/* Readline callback.
   Redisplay the command line with its prompt after readline has
   changed the edited text.  */
void
tui_redisplay_readline (void)
{
  int prev_col;
  int height;
  int col;
  int c_pos;
  int c_line;
  int in;
  WINDOW *w;
  const char *prompt;
  int start_line;

  /* Detect when we temporarily left SingleKey and now the readline
     edit buffer is empty, automatically restore the SingleKey
     mode.  The restore must only be done if the command has finished.
     The command could call prompt_for_continue and we must not
     restore SingleKey so that the prompt and normal keymap are used.  */
  if (tui_current_key_mode == TUI_ONE_COMMAND_MODE && rl_end == 0
      && !gdb_in_secondary_prompt_p (current_ui))
    tui_set_key_mode (TUI_SINGLE_KEY_MODE);

  if (tui_current_key_mode == TUI_SINGLE_KEY_MODE)
    prompt = "";
  else
    prompt = tui_rl_saved_prompt;
  
  c_pos = -1;
  c_line = -1;
  w = TUI_CMD_WIN->generic.handle;
  start_line = TUI_CMD_WIN->detail.command_info.start_line;
  wmove (w, start_line, 0);
  prev_col = 0;
  height = 1;
  for (in = 0; prompt && prompt[in]; in++)
    {
      waddch (w, prompt[in]);
      col = getcurx (w);
      if (col <= prev_col)
        height++;
      prev_col = col;
    }
  for (in = 0; in <= rl_end; in++)
    {
      unsigned char c;
      
      if (in == rl_point)
	{
          getyx (w, c_line, c_pos);
	}

      if (in == rl_end)
        break;

      c = (unsigned char) rl_line_buffer[in];
      if (CTRL_CHAR (c) || c == RUBOUT)
	{
          waddch (w, '^');
          waddch (w, CTRL_CHAR (c) ? UNCTRL (c) : '?');
	}
      else if (c == '\t')
	{
	  /* Expand TABs, since ncurses on MS-Windows doesn't.  */
	  col = getcurx (w);
	  do
	    {
	      waddch (w, ' ');
	      col++;
	    } while ((col % 8) != 0);
	}
      else
	{
          waddch (w, c);
	}
      if (c == '\n')
	TUI_CMD_WIN->detail.command_info.start_line = getcury (w);
      col = getcurx (w);
      if (col < prev_col)
        height++;
      prev_col = col;
    }
  wclrtobot (w);
  TUI_CMD_WIN->detail.command_info.start_line = getcury (w);
  if (c_line >= 0)
    wmove (w, c_line, c_pos);
  TUI_CMD_WIN->detail.command_info.start_line -= height - 1;

  wrefresh (w);
  fflush(stdout);
}
Example #7
0
/* Readline callback.
   Redisplay the command line with its prompt after readline has
   changed the edited text.  */
void
tui_redisplay_readline (void)
{
  int prev_col;
  int height;
  int col, line;
  int c_pos;
  int c_line;
  int in;
  WINDOW *w;
  char *prompt;
  int start_line;

  /* Detect when we temporarily left SingleKey and now the readline
     edit buffer is empty, automatically restore the SingleKey
     mode.  */
  if (tui_current_key_mode == TUI_ONE_COMMAND_MODE && rl_end == 0)
    tui_set_key_mode (TUI_SINGLE_KEY_MODE);

  if (tui_current_key_mode == TUI_SINGLE_KEY_MODE)
    prompt = "";
  else
    prompt = tui_rl_saved_prompt;
  
  c_pos = -1;
  c_line = -1;
  w = TUI_CMD_WIN->generic.handle;
  start_line = TUI_CMD_WIN->detail.command_info.start_line;
  wmove (w, start_line, 0);
  prev_col = 0;
  height = 1;
  for (in = 0; prompt && prompt[in]; in++)
    {
      waddch (w, prompt[in]);
      getyx (w, line, col);
      if (col < prev_col)
        height++;
      prev_col = col;
    }
  for (in = 0; in < rl_end; in++)
    {
      unsigned char c;
      
      c = (unsigned char) rl_line_buffer[in];
      if (in == rl_point)
	{
          getyx (w, c_line, c_pos);
	}

      if (CTRL_CHAR (c) || c == RUBOUT)
	{
          waddch (w, '^');
          waddch (w, CTRL_CHAR (c) ? UNCTRL (c) : '?');
	}
      else
	{
          waddch (w, c);
	}
      if (c == '\n')
        {
          getyx (w, TUI_CMD_WIN->detail.command_info.start_line,
                 TUI_CMD_WIN->detail.command_info.curch);
        }
      getyx (w, line, col);
      if (col < prev_col)
        height++;
      prev_col = col;
    }
  wclrtobot (w);
  getyx (w, TUI_CMD_WIN->detail.command_info.start_line,
         TUI_CMD_WIN->detail.command_info.curch);
  if (c_line >= 0)
    {
      wmove (w, c_line, c_pos);
      TUI_CMD_WIN->detail.command_info.cur_line = c_line;
      TUI_CMD_WIN->detail.command_info.curch = c_pos;
    }
  TUI_CMD_WIN->detail.command_info.start_line -= height - 1;

  wrefresh (w);
  fflush(stdout);
}
Example #8
0
/*
 * Display a symbol on somebody's window, processing some control
 * characters while we are at it.
 */
void
display(xwin_t *win, wchar_t *wc)
{

	/*
	 * Alas, can't use variables in C switch statement.
	 * Workaround these 3 cases with goto.
	 */
	if (*wc == win->kill)
		goto kill;
	else if (*wc == win->cerase)
		goto cerase;
	else if (*wc == win->werase)
		goto werase;

	switch (*wc) {
	case L'\n':
	case L'\r':
		wadd_wch(win->x_win, makecchar(L'\n'));
		getyx(win->x_win, win->x_line, win->x_col);
		wrefresh(win->x_win);
		return;

	case 004:
		if (win == &my_win) {
			/* Ctrl-D clears the screen. */
			werase(my_win.x_win);
			getyx(my_win.x_win, my_win.x_line, my_win.x_col);
			wrefresh(my_win.x_win);
			werase(his_win.x_win);
			getyx(his_win.x_win, his_win.x_line, his_win.x_col);
			wrefresh(his_win.x_win);
		}
		return;

	/* Erase character. */
	case 010:	/* BS */
	case 0177:	/* DEL */
cerase:
		wmove(win->x_win, win->x_line, max(--win->x_col, 0));
		getyx(win->x_win, win->x_line, win->x_col);
		waddch(win->x_win, ' ');
		wmove(win->x_win, win->x_line, win->x_col);
		getyx(win->x_win, win->x_line, win->x_col);
		wrefresh(win->x_win);
		return;

	case 027:	/* ^W */
werase:
	    {
		/*
		 * On word erase search backwards until we find
		 * the beginning of a word or the beginning of
		 * the line.
		 */
		int endcol, xcol, c;

		endcol = win->x_col;
		xcol = endcol - 1;
		while (xcol >= 0) {
			c = readwin(win->x_win, win->x_line, xcol);
			if (c != ' ')
				break;
			xcol--;
		}
		while (xcol >= 0) {
			c = readwin(win->x_win, win->x_line, xcol);
			if (c == ' ')
				break;
			xcol--;
		}
		wmove(win->x_win, win->x_line, xcol + 1);
		for (int i = xcol + 1; i < endcol; i++)
			waddch(win->x_win, ' ');
		wmove(win->x_win, win->x_line, xcol + 1);
		getyx(win->x_win, win->x_line, win->x_col);
		wrefresh(win->x_win);
		return;
	    }

	case 025:	/* ^U */
kill:
		wmove(win->x_win, win->x_line, 0);
		wclrtoeol(win->x_win);
		getyx(win->x_win, win->x_line, win->x_col);
		wrefresh(win->x_win);
		return;

	case L'\f':
		if (win == &my_win)
			wrefresh(curscr);
		return;

	case L'\7':
		write(STDOUT_FILENO, wc, sizeof(*wc));
		return;
	}


	if (iswprint(*wc) || *wc == L'\t')
		wadd_wch(win->x_win, makecchar(*wc));
	else
		beep();

	getyx(win->x_win, win->x_line, win->x_col);
	wrefresh(win->x_win);
}
/*
 * Display text from a file in a dialog box.
 */
int dialog_textbox(const char *title, const char *file, int height, int width)
{
	int i, x, y, cur_x, cur_y, fpos, key = 0;
	int passed_end;
	char search_term[MAX_LEN + 1];
	WINDOW *dialog, *text;

	search_term[0] = '\0';	/* no search term entered yet */

	/* Open input file for reading */
	if ((fd = open(file, O_RDONLY)) == -1) {
		endwin();
		fprintf(stderr, "\nCan't open input file in dialog_textbox().\n");
		exit(-1);
	}
	/* Get file size. Actually, 'file_size' is the real file size - 1,
	   since it's only the last byte offset from the beginning */
	if ((file_size = lseek(fd, 0, SEEK_END)) == -1) {
		endwin();
		fprintf(stderr, "\nError getting file size in dialog_textbox().\n");
		exit(-1);
	}
	/* Restore file pointer to beginning of file after getting file size */
	if (lseek(fd, 0, SEEK_SET) == -1) {
		endwin();
		fprintf(stderr, "\nError moving file pointer in dialog_textbox().\n");
		exit(-1);
	}
	/* Allocate space for read buffer */
	if ((buf = malloc(BUF_SIZE + 1)) == NULL) {
		endwin();
		fprintf(stderr, "\nCan't allocate memory in dialog_textbox().\n");
		exit(-1);
	}
	if ((bytes_read = read(fd, buf, BUF_SIZE)) == -1) {
		endwin();
		fprintf(stderr, "\nError reading file in dialog_textbox().\n");
		exit(-1);
	}
	buf[bytes_read] = '\0';	/* mark end of valid data */
	page = buf;		/* page is pointer to start of page to be displayed */

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

	draw_shadow(stdscr, y, x, height, width);

	dialog = newwin(height, width, y, x);
	keypad(dialog, TRUE);

	/* Create window for text region, used for scrolling text */
	text = subwin(dialog, height - 4, width - 2, y + 1, x + 1);
	wattrset(text, dialog_attr);
	wbkgdset(text, dialog_attr & A_COLOR);

	keypad(text, TRUE);

	/* register the new window, along with its borders */
	draw_box(dialog, 0, 0, height, width, dialog_attr, border_attr);

	wattrset(dialog, border_attr);
	mvwaddch(dialog, height - 3, 0, ACS_LTEE);
	for (i = 0; i < width - 2; i++)
		waddch(dialog, ACS_HLINE);
	wattrset(dialog, dialog_attr);
	wbkgdset(dialog, dialog_attr & A_COLOR);
	waddch(dialog, ACS_RTEE);

	print_title(dialog, title, width);

	print_button(dialog, " Exit ", height - 2, width / 2 - 4, TRUE);
	wnoutrefresh(dialog);
	getyx(dialog, cur_y, cur_x);	/* Save cursor position */

	/* Print first page of text */
	attr_clear(text, height - 4, width - 2, dialog_attr);
	print_page(text, height - 4, width - 2);
	print_position(dialog, height, width);
	wmove(dialog, cur_y, cur_x);	/* Restore cursor position */
	wrefresh(dialog);

	while ((key != ESC) && (key != '\n')) {
		key = wgetch(dialog);
		switch (key) {
		case 'E':	/* Exit */
		case 'e':
		case 'X':
		case 'x':
			delwin(dialog);
			free(buf);
			close(fd);
			return 0;
		case 'g':	/* First page */
		case KEY_HOME:
			if (!begin_reached) {
				begin_reached = 1;
				/* First page not in buffer? */
				if ((fpos = lseek(fd, 0, SEEK_CUR)) == -1) {
					endwin();
					fprintf(stderr, "\nError moving file pointer in dialog_textbox().\n");
					exit(-1);
				}
				if (fpos > bytes_read) {	/* Yes, we have to read it in */
					if (lseek(fd, 0, SEEK_SET) == -1) {
						endwin();
						fprintf(stderr, "\nError moving file pointer in "
							        "dialog_textbox().\n");
						exit(-1);
					}
					if ((bytes_read =
					     read(fd, buf, BUF_SIZE)) == -1) {
						endwin();
						fprintf(stderr, "\nError reading file in dialog_textbox().\n");
						exit(-1);
					}
					buf[bytes_read] = '\0';
				}
				page = buf;
				print_page(text, height - 4, width - 2);
				print_position(dialog, height, width);
				wmove(dialog, cur_y, cur_x);	/* Restore cursor position */
				wrefresh(dialog);
			}
			break;
		case 'G':	/* Last page */
		case KEY_END:

			end_reached = 1;
			/* Last page not in buffer? */
			if ((fpos = lseek(fd, 0, SEEK_CUR)) == -1) {
				endwin();
				fprintf(stderr, "\nError moving file pointer in dialog_textbox().\n");
				exit(-1);
			}
			if (fpos < file_size) {	/* Yes, we have to read it in */
				if (lseek(fd, -BUF_SIZE, SEEK_END) == -1) {
					endwin();
					fprintf(stderr, "\nError moving file pointer in dialog_textbox().\n");
					exit(-1);
				}
				if ((bytes_read =
				     read(fd, buf, BUF_SIZE)) == -1) {
					endwin();
					fprintf(stderr, "\nError reading file in dialog_textbox().\n");
					exit(-1);
				}
				buf[bytes_read] = '\0';
			}
			page = buf + bytes_read;
			back_lines(height - 4);
			print_page(text, height - 4, width - 2);
			print_position(dialog, height, width);
			wmove(dialog, cur_y, cur_x);	/* Restore cursor position */
			wrefresh(dialog);
			break;
		case 'K':	/* Previous line */
		case 'k':
		case KEY_UP:
			if (!begin_reached) {
				back_lines(page_length + 1);

				/* We don't call print_page() here but use scrolling to ensure
				   faster screen update. However, 'end_reached' and
				   'page_length' should still be updated, and 'page' should
				   point to start of next page. This is done by calling
				   get_line() in the following 'for' loop. */
				scrollok(text, TRUE);
				wscrl(text, -1);	/* Scroll text region down one line */
				scrollok(text, FALSE);
				page_length = 0;
				passed_end = 0;
				for (i = 0; i < height - 4; i++) {
					if (!i) {
						/* print first line of page */
						print_line(text, 0, width - 2);
						wnoutrefresh(text);
					} else
						/* Called to update 'end_reached' and 'page' */
						get_line();
					if (!passed_end)
						page_length++;
					if (end_reached && !passed_end)
						passed_end = 1;
				}

				print_position(dialog, height, width);
				wmove(dialog, cur_y, cur_x);	/* Restore cursor position */
				wrefresh(dialog);
			}
			break;
		case 'B':	/* Previous page */
		case 'b':
		case KEY_PPAGE:
			if (begin_reached)
				break;
			back_lines(page_length + height - 4);
			print_page(text, height - 4, width - 2);
			print_position(dialog, height, width);
			wmove(dialog, cur_y, cur_x);
			wrefresh(dialog);
			break;
		case 'J':	/* Next line */
		case 'j':
		case KEY_DOWN:
			if (!end_reached) {
				begin_reached = 0;
				scrollok(text, TRUE);
				scroll(text);	/* Scroll text region up one line */
				scrollok(text, FALSE);
				print_line(text, height - 5, width - 2);
				wnoutrefresh(text);
				print_position(dialog, height, width);
				wmove(dialog, cur_y, cur_x);	/* Restore cursor position */
				wrefresh(dialog);
			}
			break;
		case KEY_NPAGE:	/* Next page */
		case ' ':
			if (end_reached)
				break;

			begin_reached = 0;
			print_page(text, height - 4, width - 2);
			print_position(dialog, height, width);
			wmove(dialog, cur_y, cur_x);
			wrefresh(dialog);
			break;
		case '0':	/* Beginning of line */
		case 'H':	/* Scroll left */
		case 'h':
		case KEY_LEFT:
			if (hscroll <= 0)
				break;

			if (key == '0')
				hscroll = 0;
			else
				hscroll--;
			/* Reprint current page to scroll horizontally */
			back_lines(page_length);
			print_page(text, height - 4, width - 2);
			wmove(dialog, cur_y, cur_x);
			wrefresh(dialog);
			break;
		case 'L':	/* Scroll right */
		case 'l':
		case KEY_RIGHT:
			if (hscroll >= MAX_LEN)
				break;
			hscroll++;
			/* Reprint current page to scroll horizontally */
			back_lines(page_length);
			print_page(text, height - 4, width - 2);
			wmove(dialog, cur_y, cur_x);
			wrefresh(dialog);
			break;
		case ESC:
			break;
		}
	}

	delwin(dialog);
	free(buf);
	close(fd);
	return -1;		/* ESC pressed */
}
Example #10
0
void CursedWindow::putChar(int ch)
{
  waddch(contentWindow, ch);
  wrefresh(contentWindow);
}
Example #11
0
static ctrls_show_t* eq_ctrls_gen (WINDOW *eq_win, int nbands) {


	/* Power*/
  WINDOW *db_win;
  /* Frequency */
  WINDOW *hz_win;
  /* Bandwidth */
  WINDOW *bw_win;

  /* Structs */
  ctrls_show_t *ctrls;

  db_show_t *db;
  hz_show_t *hz;
  bw_show_t *bw;

  
	int i;
  int max_ro,max_co,maxy,h_gap,v_gap;
  int v_bar_h,h_bar_h;
  int nctrls = 3;
	int h_offs = 0;
  int v_offs = 0;
  

  ctrls = calloc (1,sizeof (ctrls_show_t));

  ctrls->db = calloc (1,sizeof (db_show_t));
  ctrls->hz = calloc (1,sizeof (hz_show_t));
  ctrls->bw = calloc (1,sizeof (bw_show_t));

  db = ctrls->db;
  hz = ctrls->hz;
  bw = ctrls->bw;
  

  db->slider_p = calloc (nbands,sizeof (PANEL*));
  db->bar_p = calloc (nbands,sizeof (PANEL*));

  db->bar_w = calloc (nbands,sizeof (WINDOW*));
  db->slider_w = calloc (nbands,sizeof (WINDOW*));

  hz->cell_w = calloc (nbands,sizeof (WINDOW*));
  hz->cell_p = calloc (nbands,sizeof (PANEL*));

  bw->bar_w = calloc (nbands,sizeof (WINDOW*));
  bw->slider_w = calloc (nbands,sizeof (WINDOW*));
  bw->cell_w = calloc (nbands,sizeof (WINDOW*));

  bw->bar_p = calloc (nbands,sizeof (PANEL*));
  bw->slider_p = calloc (nbands,sizeof (PANEL*));
  bw->cell_p = calloc (nbands,sizeof (PANEL*));


	getmaxyx (eq_win,max_ro,max_co);

  max_co = floor (max_co / nctrls);

	h_gap = floor (max_co / nbands);
  v_gap = floor (max_ro*0.7 / nbands);

  /* Start Drawing */

  maxy = getmaxy (eq_win);

	db_win = newwin (max_ro*0.7,max_co,maxy * 0.20,max_co*0);
  db->pan = new_panel (db_win);
  //box (db_win,0,0);

  hz_win =  newwin (max_ro*0.7,max_co,maxy * 0.20,max_co*1);
  hz->pan = new_panel (hz_win);
  //box (hz_win,0,0);

  bw_win = newwin (max_ro*0.7,max_co,maxy * 0.20,max_co*2);
  bw->pan = new_panel (bw_win);
  //box (bw_win,0,0);

  v_bar_h = floor (getmaxy(db_win)*0.80) + 2;
  h_bar_h = floor (getmaxx(bw_win)*0.80) + 2;

  for (i=0;i<nbands;i++) {

    /* Power */

    db->bar_w[i] = newwin (v_bar_h,3,getbegy (db_win) + getmaxy (db_win) - (v_bar_h) - 2 , ( getbegx (db_win) + ((getmaxx (db_win)/nbands) / 2) ) + h_offs - 2);

    db->bar_p[i] = new_panel (db->bar_w[i]);

    wattron (db->bar_w[i],A_BOLD | COLOR_PAIR (4));
    box (db->bar_w[i],ACS_VLINE,ACS_HLINE);

    db->slider_w[i] = newwin (1,8,getbegy (db->bar_w[i])+ (v_bar_h/2),getbegx (db->bar_w[i]) - 2 );

    wattron (db->slider_w[i],A_BOLD |COLOR_PAIR (8));
    wprintw (db->slider_w[i],"     dB");

    db->slider_p[i] = new_panel (db->slider_w[i]);


    /* Frequency */

    hz->cell_w[i] = newwin (1+2,7+2,( getbegy (hz_win) + ((getmaxy (hz_win)/nbands) / 2) ) + v_offs - 1, getbegx (hz_win) + (getmaxx (hz_win) / 2) - 5);
    hz->cell_p[i] = new_panel (hz->cell_w[i]);
    wattron (hz->cell_w[i], A_BOLD | COLOR_PAIR (4));
    box (hz->cell_w[i],0,0);

    wattron (hz->cell_w[i],COLOR_PAIR (8));
    mvwprintw (hz->cell_w[i],1,1,"     Hz");

    /* Bandwidth */

    bw->bar_w[i] = newwin (2,h_bar_h,( getbegy (bw_win) + ((getmaxy (bw_win)/nbands) / 2) ) + v_offs, getbegx (bw_win) + (getmaxx (bw_win) / 2) - (h_bar_h/2));
    bw->bar_p[i] = new_panel (bw->bar_w[i]);
    wattron (bw->bar_w[i], A_BOLD | COLOR_PAIR (4));
    box (bw->bar_w[i],0,0);

    bw->slider_w[i] = newwin (2,1,getbegy (bw->bar_w[i]) ,getbegx (bw->bar_w[i]) + (h_bar_h/2) -1 );
    bw->slider_p[i] = new_panel (bw->slider_w[i]);

    wattron (bw->slider_w[i],COLOR_PAIR (1));
    waddch (bw->slider_w[i],' '|A_REVERSE);
    waddch (bw->slider_w[i],' '|A_REVERSE);

    bw->cell_w[i] = newwin (1,4,getbegy (bw->bar_w[i]) + 3,getbegx (bw->bar_w[i]) + (h_bar_h/2) - 2);
    bw->cell_p[i] = new_panel (bw->cell_w[i]);
    wattron (bw->cell_w[i],A_BOLD | COLOR_PAIR (8));
    wprintw (bw->cell_w[i],"    ");


    h_offs += h_gap;
    v_offs += v_gap;
  }


	update_panels ();
	doupdate ();


	return ctrls;
}
Example #12
0
/*
 * read_scroll:
 *	Let the hero read a scroll
 */
int read_scroll()
{
	struct object *obj;
	struct linked_list *item;
	int i, j, wh;
	unsigned long ch, nch;
	struct room *rp;
	struct linked_list *titem;
	char buf[LINLEN];
	bool bless, curse;

	if ((item = get_item("read", SCROLL)) == NULL)
		return 0;
	obj = OBJPTR(item);
	if (obj->o_type != SCROLL) {
		msg("Nothing to read.");
		after = FALSE;
		return 0;
	}
	msg("As you read the scroll, it vanishes.");
	wh = obj->o_which;
	bless = o_on(obj, ISBLESS);
	curse = o_on(obj, ISCURSED);
	del_pack(item);		/* Get rid of the thing */

	/*
	 * Calculate the effect it has on the hero
	 */
	switch(wh) {
	case S_KNOWALL:
		if (!curse) {
			idenpack();				/* identify all the pack */
			msg("You feel more knowledgable.");
			chg_abil(WIS,1,TRUE);
			s_know[S_KNOWALL] = TRUE;
		}
	when S_CONFUSE:
		if (!curse) {
			/*
			 * Scroll of monster confusion.  Give him that power.
			 */
			msg("Your hands begin to glow red.");
			player.t_flags |= CANHUH;
			s_know[S_CONFUSE] = TRUE;
		}
	when S_LIGHT:
		rp = player.t_room;
		if (!curse) {
			if (rp == NULL) {
				s_know[S_LIGHT] = TRUE;
				msg("The corridor glows and then fades.");
			}
			else {
				if (rf_on(rp,ISDARK)) {
					s_know[S_LIGHT] = TRUE;
					msg("The room is lit.");
					rp->r_flags &= ~ISDARK;
				}
				light(&hero);
				mvwaddch(cw, hero.y, hero.x, PLAYER);
			}
		}
	when S_ARMOR:
		if (!curse) {
			if (cur_armor != NULL && o_off(cur_armor,ISPROT)) {
				s_know[S_ARMOR] = TRUE;
				msg("Your armor glows faintly for a moment.");
				if (o_on(cur_armor,ISCURSED))
					cur_armor->o_ac = armors[cur_armor->o_which].a_class;
				else
					cur_armor->o_ac--;
				resoflg(cur_armor,ISCURSED);
			}
		}
	when S_HOLD:
		if (!curse) {
			/*
			 * Hold monster scroll.  Stop all monsters within 3 spaces
			 * from chasing after the hero.
			 */
			int x,y;
			struct linked_list *mon;

			for (x = hero.x - 3; x <= hero.x + 3; x++) {
				for (y = hero.y - 3; y <= hero.y + 3; y++) {
					if (y > 0 && x > 0 && isalpha(mvwinch(mw, y, x))) {
						if ((mon = find_mons(y, x)) != NULL) {
							struct thing *th;

							th = THINGPTR(mon);
							th->t_flags &= ~ISRUN;
							th->t_flags |= ISHELD;
							th->t_flags |= ISSTUCK;
						}
					}
				}
			}
		}
	when S_SLEEP:
		/*
		 * Scroll which makes you fall asleep
		 */
		if (!bless) {
			s_know[S_SLEEP] = TRUE;
			msg("You fall asleep.");
			player.t_nocmd += 4 + rnd(SLEEPTIME);
		}
	when S_CREATE:
		if (!bless) {
			if (makemons(mtlev[rnd(levcount)]->m_show))
				s_know[S_CREATE] = TRUE;
			else
				msg("You hear a faint cry of anguish in the distance.");
		}
	when S_IDENT:
		if (!curse) {
			msg("This scroll is an identify scroll");
			s_know[S_IDENT] = TRUE;
			whatis(NULL);
		}
	when S_MAP:
		if (curse)
			break;
		s_know[S_MAP] = TRUE;
		addmsg("Oh, now this scroll has a ");
		if (rnd(100) < 10 || bless) {
			addmsg("very detailed map on it.");
			endmsg();
			displevl();
		}
		else {
			addmsg("map on it.");
			endmsg();
			overwrite(stdscr, hw);
			for (i = 1; i < LINES - 2; i++) {
				for (j = 0; j < COLS; j++) {
					switch (nch = ch = mvwinch(hw, i, j)) {
						case SECRETDOOR:
							nch = DOOR;
							mvaddch(i, j, nch);
						case '-':
						case '|':
						case DOOR:
						case PASSAGE:
						case ' ':
						case STAIRS:
							if (mvwinch(mw, i, j) != ' ') {
								struct thing *it;
								struct linked_list *blah;

								blah = find_mons(i, j);
								if (blah != NULL) {
									it = THINGPTR(blah);
									if (it->t_oldch == ' ')
										it->t_oldch = nch;
								}
							}
							break;
						default:
							nch = ' ';
					}
					if (nch != ch)
						waddch(hw, nch);
				}
			}
			overlay(cw, hw);
			overwrite(hw, cw);
		}
	when S_GFIND:
		if (!curse) {
			int gtotal = 0;
			struct room *rp;

			wclear(hw);
			for (rp = rooms; rp < &rooms[MAXROOMS]; rp++) {
				gtotal += rp->r_goldval;
				if (rp->r_goldval != 0 &&
				  mvinch(rp->r_gold.y,rp->r_gold.x) == GOLD)
					mvwaddch(hw,rp->r_gold.y,rp->r_gold.x,GOLD);
			}
			if (gtotal) {
				s_know[S_GFIND] = TRUE;
				msg("You begin to feel greedy and sense gold.");
				overlay(hw,cw);
			}
			else
				msg("You begin to feel a pull downward.");
		}
	when S_TELEP:
		if (!curse) {
			int rm;
			struct room *cur_room;

			cur_room = player.t_room;
			rm = teleport(rndspot, &player);
			if (cur_room != &rooms[rm])
				s_know[S_TELEP] = TRUE;
		}
	when S_ENCH:
		if (!curse) {
			if (cur_weapon == NULL || (cur_weapon != NULL &&
			  (o_on(cur_weapon,ISPROT) || cur_weapon->o_type != WEAPON)))
				msg("You feel a strange sense of loss.");
			else {
				s_know[S_ENCH] = TRUE;
				if (o_on(cur_weapon,ISCURSED)) {
					resoflg(cur_weapon,ISCURSED);
					cur_weapon->o_hplus = rnd(2);
					cur_weapon->o_dplus = rnd(2);
				}
				else {		/* weapon was not cursed here */
					if (rnd(100) < 50)
						cur_weapon->o_hplus += 1;
					else
						cur_weapon->o_dplus += 1;
				}
				setoflg(cur_weapon, ISKNOW);
				msg("Your %s glows blue for a moment.",
				  w_magic[cur_weapon->o_which].mi_name);
			}
		}
	when S_SCARE:
		/*
		 * A monster will refuse to step on a scare monster scroll
		 * if it is dropped.  Thus reading it is a mistake and produces
		 * laughter at the poor rogue's boo boo.
		 */
		msg("You hear maniacal laughter in the distance.");
	when S_REMOVE:
		if (!curse) {
			if (cur_armor != NULL && o_off(cur_armor,ISPROT))
				resoflg(cur_armor,ISCURSED);
			if (cur_weapon != NULL && o_off(cur_weapon,ISPROT))
				resoflg(cur_weapon,ISCURSED);
			if (cur_ring[LEFT]!=NULL && o_off(cur_ring[LEFT],ISPROT))
				resoflg(cur_ring[LEFT],ISCURSED);
			if (cur_ring[RIGHT]!=NULL && o_off(cur_ring[RIGHT],ISPROT))
				resoflg(cur_ring[RIGHT],ISCURSED);
			msg("You feel as if somebody is watching over you.");
			s_know[S_REMOVE] = TRUE;
		}
	when S_AGGR:
		if (!bless) {
			if (mlist != NULL) {
				aggravate();
				msg("You hear a high pitched humming noise.");
				s_know[S_AGGR] = TRUE;
			}
		}
	when S_NOP:
		msg("This scroll seems to be blank.");
	when S_GENOCIDE:
		if (!curse) {
			msg("You have been granted the boon of genocide.");
			genocide();
			s_know[S_GENOCIDE] = TRUE;
		}
	when S_DCURSE:
		if (!bless) {
			struct linked_list *ll;
			struct object *lb;

			msg("Your pack shudders.");
			for (ll = pack ; ll != NULL ; ll = next(ll)) {
				lb = OBJPTR(ll);
				if (o_off(lb,ISPROT)) {
					resoflg(lb, ISBLESS);
					setoflg(lb, ISCURSED);
				}
			}
		}
	when S_DLEVEL:
		if (!bless) {
			int much = rnd(9) - 4;

			if (much != 0) {
				level += much;
				if (level < 1)
					level = 1;
				mpos = 0;
				new_level(NORMLEV);		/* change levels */
				msg("You are whisked away to another region.");
				s_know[S_DLEVEL] = TRUE;
			}
		}
	when S_PROTECT:
		if (!curse) {
			struct linked_list *ll;
			struct object *lb;

			msg("You are granted the power of protection.");
			if ((ll = get_item("protect",0)) != NULL) {
				lb = OBJPTR(ll);
				setoflg(lb,ISPROT);
				mpos = 0;
				msg("Protected %s.",inv_name(lb,TRUE));
			}
			s_know[S_PROTECT] = TRUE;
		}
	when S_ALLENCH:
		if (!curse) {
			struct linked_list *ll;
			struct object *lb;
			int howmuch, ac, good;

			msg("You are granted the power of enchantment.");
			good = TRUE;
			if ((ll = get_item("enchant",0)) != NULL) {
				lb = OBJPTR(ll);
				resoflg(lb,ISCURSED);
				resoflg(lb,ISPROT);
				howmuch = rnd(3) + 1;
				switch(lb->o_type) {
					case RING:
						if (lb->o_ac < 0)
							lb->o_ac = 0;
						lb->o_ac += howmuch;
					when ARMOR:
						ac = armors[lb->o_which].a_class;
						if (lb->o_ac > ac)
							lb->o_ac = ac;
						lb->o_ac -= howmuch;
					when STICK:
						lb->o_charges += howmuch + 10;
					when WEAPON:
						if (lb->o_dplus < 0)
							lb->o_dplus = 0;
						if (lb->o_hplus < 0)
							lb->o_hplus = 0;
						lb->o_hplus += howmuch;
						lb->o_dplus += howmuch;
					otherwise:
						msg("You are injured as the scroll flashes & bursts into flames !!!");
						chg_hpt(-roll(6,6),FALSE,K_SCROLL);
						good = FALSE;
				}
				if (good) {
					mpos = 0;
					msg("Enchanted %s.",inv_name(lb,TRUE));
				}
			}
			s_know[S_ALLENCH] = TRUE;
		}
	when S_BLESS:
		if (!curse) {
			struct linked_list *ll;
			struct object *lb;

			msg("Your pack glistens brightly.");
			for (ll = pack ; ll != NULL ; ll = next(ll)) {
				whatis(ll);
				lb = OBJPTR(ll);
				resoflg(lb,ISCURSED);
				setoflg(lb,ISBLESS);
			}
		}
	when S_MAKEIT:
		if (!curse) {
			msg("You have been endowed with the power of creation.");
			s_know[S_MAKEIT] = TRUE;
			create_obj(TRUE);
		}
	when S_BAN: {
		int howdeep;
		char *ptr;

		if (bless) {
			if (level > 6) {
				howdeep = 1 + rnd(5);
				ptr = "elevated to the upper";
			}
			else {
				howdeep = -1;
				bless = FALSE;
			}
		}
		else {
			howdeep = level + 10 + rnd(20) + (curse * 20);
			ptr = "banished to the lower";
		}
		if ((!bless && level < howdeep) || bless) {
			level = howdeep;
			new_level(NORMLEV);
			mpos = 0;
			msg("You are %s regions.", ptr);
			s_know[S_BAN] = TRUE;
		}
	}
	when S_CWAND:
		if (!curse) {
			struct linked_list *ll;
			struct object *lb;
			bool wands = FALSE;

			for (ll = pack ; ll != NULL ; ll = next(ll)) {
				lb = OBJPTR(ll);
				if (lb->o_type == STICK) {
					whatis(ll);
					setoflg(lb, ISKNOW);
					resoflg(lb, ISCURSED);
					lb->o_charges += rnd(11) + 5;
					wands = TRUE;
				}
			}
			if (wands) {
				msg("Your sticks gleam.");
				s_know[wh] = TRUE;
			}
		}
	when S_LOCTRAP: {
		struct trap *trp;

		if (ntraps > 0) {
			for (trp = &traps[0]; trp < &traps[ntraps]; trp++)
				trp->tr_flags |= ISFOUND;
			look(FALSE);
			msg("You now recognize pitfalls.");
			s_know[S_LOCTRAP] = TRUE;
		}
	}
	otherwise:
		msg("What a puzzling scroll!");
		return 0;
	}
Example #13
0
void wputch(WINDOW *w, nc_color FG, long ch)
{
    wattron(w, FG);
    waddch(w, ch);
    wattroff(w, FG);
}
Example #14
0
int HEXTUI_actionmenu() {
  int m = 0;
#ifdef HEXT_PLATFORM_CURSES
  /*                        w, h,x, y       */
  WINDOW* am_win = newwin( 10,10,1,10);		

  wattron( am_win, A_REVERSE );
  
  wmove( am_win, 1, 0 );		/* move to beginning of line */
  waddch( am_win, ' ' );		/* insert blank before (inner-margin) */
  /* TODO:: if is mnemonic, then */
  wattron( am_win, A_UNDERLINE );
  /* */
  waddch( am_win, 'E' );
  wattroff( am_win, A_UNDERLINE );
  waddch( am_win, 'd' );
  waddch( am_win, 'i' );
  waddch( am_win, 't' );
  waddch( am_win, '\t' );
  waddch( am_win, '>' );
  waddch( am_win, ' ' );		/* insert blank after (inner-margin) */
  //mvwprintw( am_win, 1, 1, "dit\t\t> " );	/* including trailing space */

  
  
  wattron( am_win, A_UNDERLINE );
	wmove( am_win, 2, 0 );	
	waddch( am_win, 'V' );
	wattroff( am_win, A_UNDERLINE );

	mvwprintw( am_win, 2, 1, "iew\t->" );

	wattron( am_win, A_UNDERLINE );
	wmove( am_win, 3, 0 );	
	waddch( am_win, 'C' );
	wattroff( am_win, A_UNDERLINE );

	mvwprintw( am_win, 3, 1, "onsole\t^C" );

	wattron( am_win, A_UNDERLINE );
	wmove( am_win, 4, 0 );	
	waddch( am_win, 'A' );
	wattroff( am_win, A_UNDERLINE );

	mvwprintw( am_win, 4, 1, "bout\t^G" );

	mvwprintw( am_win, 5, 0, "________" );

	wattron( am_win, A_UNDERLINE );
	wmove( am_win, 6, 0 );	
	waddch( am_win, 'Q' );
	wattroff( am_win, A_UNDERLINE );
	mvwprintw( am_win, 6, 1, "uit\t^Q" );



	wattron( am_win, A_UNDERLINE );
	wmove( am_win, 0, 0 );
	waddch( am_win, 'F' );
	wattroff( am_win, A_UNDERLINE );
	mvwprintw( am_win, 0, 1, "ile\t->" );

  wmove( am_win, 0, 0 );		
  wattroff( am_win, A_REVERSE );
  
  wrefresh( am_win );
  
  m = getch();

  delwin(am_win);
#endif
return m;
}
Example #15
0
wgetnstr_events(WINDOW *win,
		char *str,
		int maxlen,
		EVENTLIST_1st(_nc_eventlist * evl))
{
    SCREEN *sp = _nc_screen_of(win);
    TTY buf;
    bool oldnl, oldecho, oldraw, oldcbreak;
    char erasec;
    char killc;
    char *oldstr;
    int ch;
    int y, x;

    T((T_CALLED("wgetnstr(%p,%p, %d)"), win, str, maxlen));

    if (!win)
	returnCode(ERR);

    _nc_get_tty_mode(&buf);

    oldnl = sp->_nl;
    oldecho = sp->_echo;
    oldraw = sp->_raw;
    oldcbreak = sp->_cbreak;
    nl();
    noecho();
    noraw();
    cbreak();

    erasec = erasechar();
    killc = killchar();

    oldstr = str;
    getyx(win, y, x);

    if (is_wintouched(win) || (win->_flags & _HASMOVED))
	wrefresh(win);

    while ((ch = wgetch_events(win, evl)) != ERR) {
	/*
	 * Some terminals (the Wyse-50 is the most common) generate
	 * a \n from the down-arrow key.  With this logic, it's the
	 * user's choice whether to set kcud=\n for wgetch();
	 * terminating *getstr() with \n should work either way.
	 */
	if (ch == '\n'
	    || ch == '\r'
	    || ch == KEY_DOWN
	    || ch == KEY_ENTER) {
	    if (oldecho == TRUE
		&& win->_cury == win->_maxy
		&& win->_scroll)
		wechochar(win, (chtype) '\n');
	    break;
	}
#ifdef KEY_EVENT
	if (ch == KEY_EVENT)
	    break;
#endif
#ifdef KEY_RESIZE
	if (ch == KEY_RESIZE)
	    break;
#endif
	if (ch == erasec || ch == KEY_LEFT || ch == KEY_BACKSPACE) {
	    if (str > oldstr) {
		str = WipeOut(win, y, x, oldstr, str, oldecho);
	    }
	} else if (ch == killc) {
	    while (str > oldstr) {
		str = WipeOut(win, y, x, oldstr, str, oldecho);
	    }
	} else if (ch >= KEY_MIN
		   || (maxlen >= 0 && str - oldstr >= maxlen)) {
	    beep();
	} else {
	    *str++ = (char) ch;
	    if (oldecho == TRUE) {
		int oldy = win->_cury;
		if (waddch(win, (chtype) ch) == ERR) {
		    /*
		     * We can't really use the lower-right
		     * corner for input, since it'll mess
		     * up bookkeeping for erases.
		     */
		    win->_flags &= ~_WRAPPED;
		    waddch(win, (chtype) ' ');
		    str = WipeOut(win, y, x, oldstr, str, oldecho);
		    continue;
		} else if (win->_flags & _WRAPPED) {
		    /*
		     * If the last waddch forced a wrap &
		     * scroll, adjust our reference point
		     * for erasures.
		     */
		    if (win->_scroll
			&& oldy == win->_maxy
			&& win->_cury == win->_maxy) {
			if (--y <= 0) {
			    y = 0;
			}
		    }
		    win->_flags &= ~_WRAPPED;
		}
		wrefresh(win);
	    }
	}
    }

    win->_curx = 0;
    win->_flags &= ~_WRAPPED;
    if (win->_cury < win->_maxy)
	win->_cury++;
    wrefresh(win);

    /* Restore with a single I/O call, to fix minor asymmetry between
     * raw/noraw, etc.
     */
    sp->_nl = oldnl;
    sp->_echo = oldecho;
    sp->_raw = oldraw;
    sp->_cbreak = oldcbreak;

    _nc_set_tty_mode(&buf);

    *str = '\0';
    if (ch == ERR)
	returnCode(ch);

    T(("wgetnstr returns %s", _nc_visbuf(oldstr)));

#ifdef KEY_EVENT
    if (ch == KEY_EVENT)
	returnCode(ch);
#endif
#ifdef KEY_RESIZE
    if (ch == KEY_RESIZE)
	returnCode(ch);
#endif

    returnCode(OK);
}
Example #16
0
/*
 * Display some text on somebody's window, processing some control
 * characters while we are at it.
 */
void
display(xwin_t *win, char *text, int size)
{
	int i;
	char cch;

	for (i = 0; i < size; i++) {
		if (*text == '\n' || *text == '\r') {
			waddch(win->x_win, '\n');
			getyx(win->x_win, win->x_line, win->x_col);
			text++;
			continue;
		}
		if (*text == 004 && win == &my_win) {
			/* control-D clears the screen */
			werase(my_win.x_win);
			getyx(my_win.x_win, my_win.x_line, my_win.x_col);
			wrefresh(my_win.x_win);
			werase(his_win.x_win);
			getyx(his_win.x_win, his_win.x_line, his_win.x_col);
			wrefresh(his_win.x_win);
			text++;
			continue;
		}

		/* erase character */
		if (   *text == win->cerase
		    || *text == 010     /* BS */
		    || *text == 0177    /* DEL */
		   ) {
			wmove(win->x_win, win->x_line, max(--win->x_col, 0));
			getyx(win->x_win, win->x_line, win->x_col);
			waddch(win->x_win, ' ');
			wmove(win->x_win, win->x_line, win->x_col);
			getyx(win->x_win, win->x_line, win->x_col);
			text++;
			continue;
		}
		/*
		 * On word erase search backwards until we find
		 * the beginning of a word or the beginning of
		 * the line.
		 */
		if (   *text == win->werase
		    || *text == 027     /* ^W */
		   ) {
			int endcol, xcol, ii, c;

			endcol = win->x_col;
			xcol = endcol - 1;
			while (xcol >= 0) {
				c = readwin(win->x_win, win->x_line, xcol);
				if (c != ' ')
					break;
				xcol--;
			}
			while (xcol >= 0) {
				c = readwin(win->x_win, win->x_line, xcol);
				if (c == ' ')
					break;
				xcol--;
			}
			wmove(win->x_win, win->x_line, xcol + 1);
			for (ii = xcol + 1; ii < endcol; ii++)
				waddch(win->x_win, ' ');
			wmove(win->x_win, win->x_line, xcol + 1);
			getyx(win->x_win, win->x_line, win->x_col);
			text++;
			continue;
		}
		/* line kill */
		if (   *text == win->kill
		    || *text == 025     /* ^U */
		   ) {
			wmove(win->x_win, win->x_line, 0);
			wclrtoeol(win->x_win);
			getyx(win->x_win, win->x_line, win->x_col);
			text++;
			continue;
		}
		if (*text == '\f') {
			if (win == &my_win)
				wrefresh(curscr);
			text++;
			continue;
		}
		if (*text == '\7') {
			write(STDOUT_FILENO, text, 1);
			text++;
			continue;
		}
		if (!isprint((unsigned char)*text) && *text != '\t') {
			waddch(win->x_win, '^');
			getyx(win->x_win, win->x_line, win->x_col);
			cch = (*text & 63) + 64;
			waddch(win->x_win, cch);
		} else
			waddch(win->x_win, (unsigned char)*text);
		getyx(win->x_win, win->x_line, win->x_col);
		text++;
	}
	wrefresh(win->x_win);
}
Example #17
0
_nc_Post_Item(const MENU * menu, const ITEM * item)
{
  int i;
  chtype ch;
  int item_x, item_y;
  int count = 0;
  bool isfore = FALSE, isback = FALSE, isgrey = FALSE;
  int name_len;
  int desc_len;

  assert(menu->win);

  getyx(menu->win, item_y, item_x);

  /* We need a marker iff
     - it is a onevalued menu and it is the current item
     - or it has a selection value
   */
  wattron(menu->win, menu->back);
  if (item->value || (item == menu->curitem))
    {
      if (menu->marklen)
	{
	  /* In a multi selection menu we use the fore attribute
	     for a selected marker that is not the current one.
	     This improves visualization of the menu, because now
	     always the 'normal' marker denotes the current
	     item. */
	  if (!(menu->opt & O_ONEVALUE) && item->value && item != menu->curitem)
	    {
	      wattron(menu->win, menu->fore);
	      isfore = TRUE;
	    }
	  waddstr(menu->win, menu->mark);
	  if (isfore)
	    {
	      wattron(menu->win, menu->fore);
	      isfore = FALSE;
	    }
	}
    }
  else				/* otherwise we have to wipe out the marker area */
    for (ch = ' ', i = menu->marklen; i > 0; i--)
      waddch(menu->win, ch);
  wattroff(menu->win, menu->back);
  count += menu->marklen;

  /* First we have to calculate the attribute depending on selectability
     and selection status
   */
  if (!(item->opt & O_SELECTABLE))
    {
      wattron(menu->win, menu->grey);
      isgrey = TRUE;
    }
  else
    {
      if (item->value || item == menu->curitem)
	{
	  wattron(menu->win, menu->fore);
	  isfore = TRUE;
	}
      else
	{
	  wattron(menu->win, menu->back);
	  isback = TRUE;
	}
    }

  waddnstr(menu->win, item->name.str, item->name.length);
  name_len = _nc_Calculate_Text_Width(&(item->name));
  for (ch = ' ', i = menu->namelen - name_len; i > 0; i--)
    {
      waddch(menu->win, ch);
    }
  count += menu->namelen;

  /* Show description if required and available */
  if ((menu->opt & O_SHOWDESC) && menu->desclen > 0)
    {
      int m = menu->spc_desc / 2;
      int cy = -1, cx = -1;

      for (ch = ' ', i = 0; i < menu->spc_desc; i++)
	{
	  if (i == m)
	    {
	      waddch(menu->win, menu->pad);
	      getyx(menu->win, cy, cx);
	    }
	  else
	    waddch(menu->win, ch);
	}
      if (item->description.length)
	waddnstr(menu->win, item->description.str, item->description.length);
      desc_len = _nc_Calculate_Text_Width(&(item->description));
      for (ch = ' ', i = menu->desclen - desc_len; i > 0; i--)
	{
	  waddch(menu->win, ch);
	}
      count += menu->desclen + menu->spc_desc;

      if (menu->spc_rows > 1)
	{
	  int j, k, ncy, ncx;

	  assert(cx >= 0 && cy >= 0);
	  getyx(menu->win, ncy, ncx);
	  if (isgrey)
	    wattroff(menu->win, menu->grey);
	  else if (isfore)
	    wattroff(menu->win, menu->fore);
	  wattron(menu->win, menu->back);
	  for (j = 1; j < menu->spc_rows; j++)
	    {
	      if ((item_y + j) < getmaxy(menu->win))
		{
		  wmove(menu->win, item_y + j, item_x);
		  for (k = 0; k < count; k++)
		    waddch(menu->win, ' ');
		}
	      if ((cy + j) < getmaxy(menu->win))
		(void)mvwaddch(menu->win, cy + j, cx - 1, menu->pad);
	    }
	  wmove(menu->win, ncy, ncx);
	  if (!isback)
	    wattroff(menu->win, menu->back);
	}
    }

  /* Remove attributes */
  if (isfore)
    wattroff(menu->win, menu->fore);
  if (isback)
    wattroff(menu->win, menu->back);
  if (isgrey)
    wattroff(menu->win, menu->grey);
}
Example #18
0
int dialog_menu(const char *title, const char *prompt,
                const void *selected, int *s_scroll)
{
	int i, j, x, y, box_x, box_y;
	int height, width, menu_height;
	int key = 0, button = 0, scroll = 0, choice = 0;
	int first_item =  0, max_choice;
	WINDOW *dialog, *menu;

do_resize:
	height = getmaxy(stdscr);
	width = getmaxx(stdscr);
	if (height < 15 || width < 65)
		return -ERRDISPLAYTOOSMALL;

	height -= 4;
	width  -= 5;
	menu_height = height - 10;

	max_choice = MIN(menu_height, item_count());

	
	x = (COLS - width) / 2;
	y = (LINES - height) / 2;

	draw_shadow(stdscr, y, x, height, width);

	dialog = newwin(height, width, y, x);
	keypad(dialog, TRUE);

	draw_box(dialog, 0, 0, height, width,
		 dlg.dialog.atr, dlg.border.atr);
	wattrset(dialog, dlg.border.atr);
	mvwaddch(dialog, height - 3, 0, ACS_LTEE);
	for (i = 0; i < width - 2; i++)
		waddch(dialog, ACS_HLINE);
	wattrset(dialog, dlg.dialog.atr);
	wbkgdset(dialog, dlg.dialog.atr & A_COLOR);
	waddch(dialog, ACS_RTEE);

	print_title(dialog, title, width);

	wattrset(dialog, dlg.dialog.atr);
	print_autowrap(dialog, prompt, width - 2, 1, 3);

	menu_width = width - 6;
	box_y = height - menu_height - 5;
	box_x = (width - menu_width) / 2 - 1;

	
	menu = subwin(dialog, menu_height, menu_width,
		      y + box_y + 1, x + box_x + 1);
	keypad(menu, TRUE);

	
	draw_box(dialog, box_y, box_x, menu_height + 2, menu_width + 2,
		 dlg.menubox_border.atr, dlg.menubox.atr);

	if (menu_width >= 80)
		item_x = (menu_width - 70) / 2;
	else
		item_x = 4;

	
	item_foreach()
		if (selected && (selected == item_data()))
			choice = item_n();
	
	scroll = *s_scroll;
	if ((scroll <= choice) && (scroll + max_choice > choice) &&
	   (scroll >= 0) && (scroll + max_choice <= item_count())) {
		first_item = scroll;
		choice = choice - scroll;
	} else {
		scroll = 0;
	}
	if ((choice >= max_choice)) {
		if (choice >= item_count() - max_choice / 2)
			scroll = first_item = item_count() - max_choice;
		else
			scroll = first_item = choice - max_choice / 2;
		choice = choice - scroll;
	}

	
	for (i = 0; i < max_choice; i++) {
		print_item(first_item + i, i, i == choice);
	}

	wnoutrefresh(menu);

	print_arrows(dialog, item_count(), scroll,
		     box_y, box_x + item_x + 1, menu_height);

	print_buttons(dialog, height, width, 0);
	wmove(menu, choice, item_x + 1);
	wrefresh(menu);

	while (key != KEY_ESC) {
		key = wgetch(menu);

		if (key < 256 && isalpha(key))
			key = tolower(key);

		if (strchr("ynmh", key))
			i = max_choice;
		else {
			for (i = choice + 1; i < max_choice; i++) {
				item_set(scroll + i);
				j = first_alpha(item_str(), "YyNnMmHh");
				if (key == tolower(item_str()[j]))
					break;
			}
			if (i == max_choice)
				for (i = 0; i < max_choice; i++) {
					item_set(scroll + i);
					j = first_alpha(item_str(), "YyNnMmHh");
					if (key == tolower(item_str()[j]))
						break;
				}
		}

		if (i < max_choice ||
		    key == KEY_UP || key == KEY_DOWN ||
		    key == '-' || key == '+' ||
		    key == KEY_PPAGE || key == KEY_NPAGE) {
			
			print_item(scroll + choice, choice, FALSE);

			if (key == KEY_UP || key == '-') {
				if (choice < 2 && scroll) {
					
					do_scroll(menu, &scroll, -1);

					print_item(scroll, 0, FALSE);
				} else
					choice = MAX(choice - 1, 0);

			} else if (key == KEY_DOWN || key == '+') {
				print_item(scroll+choice, choice, FALSE);

				if ((choice > max_choice - 3) &&
				    (scroll + max_choice < item_count())) {
					
					do_scroll(menu, &scroll, 1);

					print_item(scroll+max_choice - 1,
						   max_choice - 1, FALSE);
				} else
					choice = MIN(choice + 1, max_choice - 1);

			} else if (key == KEY_PPAGE) {
				scrollok(menu, TRUE);
				for (i = 0; (i < max_choice); i++) {
					if (scroll > 0) {
						do_scroll(menu, &scroll, -1);
						print_item(scroll, 0, FALSE);
					} else {
						if (choice > 0)
							choice--;
					}
				}

			} else if (key == KEY_NPAGE) {
				for (i = 0; (i < max_choice); i++) {
					if (scroll + max_choice < item_count()) {
						do_scroll(menu, &scroll, 1);
						print_item(scroll+max_choice-1,
							   max_choice - 1, FALSE);
					} else {
						if (choice + 1 < max_choice)
							choice++;
					}
				}
			} else
				choice = i;

			print_item(scroll + choice, choice, TRUE);

			print_arrows(dialog, item_count(), scroll,
				     box_y, box_x + item_x + 1, menu_height);

			wnoutrefresh(dialog);
			wrefresh(menu);

			continue;	
		}

		switch (key) {
		case KEY_LEFT:
		case TAB:
		case KEY_RIGHT:
			button = ((key == KEY_LEFT ? --button : ++button) < 0)
			    ? 2 : (button > 2 ? 0 : button);

			print_buttons(dialog, height, width, button);
			wrefresh(menu);
			break;
		case ' ':
		case 's':
		case 'y':
		case 'n':
		case 'm':
		case '/':
			
			*s_scroll = scroll;
			delwin(menu);
			delwin(dialog);
			item_set(scroll + choice);
			item_set_selected(1);
			switch (key) {
			case 's':
				return 3;
			case 'y':
				return 3;
			case 'n':
				return 4;
			case 'm':
				return 5;
			case ' ':
				return 6;
			case '/':
				return 7;
			}
			return 0;
		case 'h':
		case '?':
			button = 2;
		case '\n':
			*s_scroll = scroll;
			delwin(menu);
			delwin(dialog);
			item_set(scroll + choice);
			item_set_selected(1);
			return button;
		case 'e':
		case 'x':
			key = KEY_ESC;
			break;
		case KEY_ESC:
			key = on_key_esc(menu);
			break;
		case KEY_RESIZE:
			on_key_resize();
			delwin(menu);
			delwin(dialog);
			goto do_resize;
		}
	}
	delwin(menu);
	delwin(dialog);
	return key;		
}
Example #19
0
/*
 * Display a dialog box for inputing a string
 */
int dialog_inputbox(const char *title, const char *prompt, int height, int width,
                    const char *init)
{
	int i, x, y, box_y, box_x, box_width;
	int input_x = 0, key = 0, button = -1;
	int show_x, len, pos;
	char *instr = dialog_input_result;
	WINDOW *dialog;

	if (!init)
		instr[0] = '\0';
	else
		strcpy(instr, init);

do_resize:
	if (getmaxy(stdscr) <= (height - 2))
		return -ERRDISPLAYTOOSMALL;
	if (getmaxx(stdscr) <= (width - 2))
		return -ERRDISPLAYTOOSMALL;

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

	draw_shadow(stdscr, y, x, height, width);

	dialog = newwin(height, width, y, x);
	keypad(dialog, TRUE);

	draw_box(dialog, 0, 0, height, width,
		 dlg.dialog.atr, dlg.border.atr);
	wattrset(dialog, dlg.border.atr);
	mvwaddch(dialog, height - 3, 0, ACS_LTEE);
	for (i = 0; i < width - 2; i++)
		waddch(dialog, ACS_HLINE);
	wattrset(dialog, dlg.dialog.atr);
	waddch(dialog, ACS_RTEE);

	print_title(dialog, title, width);

	wattrset(dialog, dlg.dialog.atr);
	print_autowrap(dialog, prompt, width - 2, 1, 3);

	/* Draw the input field box */
	box_width = width - 6;
	getyx(dialog, y, x);
	box_y = y + 2;
	box_x = (width - box_width) / 2;
	draw_box(dialog, y + 1, box_x - 1, 3, box_width + 2,
		 dlg.dialog.atr, dlg.border.atr);

	print_buttons(dialog, height, width, 0);

	/* Set up the initial value */
	wmove(dialog, box_y, box_x);
	wattrset(dialog, dlg.inputbox.atr);

	len = strlen(instr);
	pos = len;

	if (len >= box_width) {
		show_x = len - box_width + 1;
		input_x = box_width - 1;
		for (i = 0; i < box_width - 1; i++)
			waddch(dialog, instr[show_x + i]);
	} else {
		show_x = 0;
		input_x = len;
		waddstr(dialog, instr);
	}

	wmove(dialog, box_y, box_x + input_x);

	wrefresh(dialog);

	while (key != KEY_ESC) {
		key = wgetch(dialog);

		if (button == -1) {	/* Input box selected */
			switch (key) {
			case TAB:
			case KEY_UP:
			case KEY_DOWN:
				break;
			case KEY_BACKSPACE:
			case 127:
				if (pos) {
					wattrset(dialog, dlg.inputbox.atr);
					if (input_x == 0) {
						show_x--;
					} else
						input_x--;

					if (pos < len) {
						for (i = pos - 1; i < len; i++) {
							instr[i] = instr[i+1];
						}
					}

					pos--;
					len--;
					instr[len] = '\0';
					wmove(dialog, box_y, box_x);
					for (i = 0; i < box_width; i++) {
						if (!instr[show_x + i]) {
							waddch(dialog, ' ');
							break;
						}
						waddch(dialog, instr[show_x + i]);
					}
					wmove(dialog, box_y, input_x + box_x);
					wrefresh(dialog);
				}
				continue;
			case KEY_LEFT:
				if (pos > 0) {
					if (input_x > 0) {
						wmove(dialog, box_y, --input_x + box_x);
					} else if (input_x == 0) {
						show_x--;
						wmove(dialog, box_y, box_x);
						for (i = 0; i < box_width; i++) {
							if (!instr[show_x + i]) {
								waddch(dialog, ' ');
								break;
							}
							waddch(dialog, instr[show_x + i]);
						}
						wmove(dialog, box_y, box_x);
					}
					pos--;
				}
				continue;
			case KEY_RIGHT:
				if (pos < len) {
					if (input_x < box_width - 1) {
						wmove(dialog, box_y, ++input_x + box_x);
					} else if (input_x == box_width - 1) {
						show_x++;
						wmove(dialog, box_y, box_x);
						for (i = 0; i < box_width; i++) {
							if (!instr[show_x + i]) {
								waddch(dialog, ' ');
								break;
							}
							waddch(dialog, instr[show_x + i]);
						}
						wmove(dialog, box_y, input_x + box_x);
					}
					pos++;
				}
				continue;
			default:
				if (key < 0x100 && isprint(key)) {
					if (len < MAX_LEN) {
						wattrset(dialog, dlg.inputbox.atr);
						if (pos < len) {
							for (i = len; i > pos; i--)
								instr[i] = instr[i-1];
							instr[pos] = key;
						} else {
							instr[len] = key;
						}
						pos++;
						len++;
						instr[len] = '\0';

						if (input_x == box_width - 1) {
							show_x++;
						} else {
							input_x++;
						}

						wmove(dialog, box_y, box_x);
						for (i = 0; i < box_width; i++) {
							if (!instr[show_x + i]) {
								waddch(dialog, ' ');
								break;
							}
							waddch(dialog, instr[show_x + i]);
						}
						wmove(dialog, box_y, input_x + box_x);
						wrefresh(dialog);
					} else
						flash();	/* Alarm user about overflow */
					continue;
				}
			}
		}
		switch (key) {
		case 'O':
		case 'o':
			delwin(dialog);
			return 0;
		case 'H':
		case 'h':
			delwin(dialog);
			return 1;
		case KEY_UP:
		case KEY_LEFT:
			switch (button) {
			case -1:
				button = 1;	/* Indicates "Help" button is selected */
				print_buttons(dialog, height, width, 1);
				break;
			case 0:
				button = -1;	/* Indicates input box is selected */
				print_buttons(dialog, height, width, 0);
				wmove(dialog, box_y, box_x + input_x);
				wrefresh(dialog);
				break;
			case 1:
				button = 0;	/* Indicates "OK" button is selected */
				print_buttons(dialog, height, width, 0);
				break;
			}
			break;
		case TAB:
		case KEY_DOWN:
		case KEY_RIGHT:
			switch (button) {
			case -1:
				button = 0;	/* Indicates "OK" button is selected */
				print_buttons(dialog, height, width, 0);
				break;
			case 0:
				button = 1;	/* Indicates "Help" button is selected */
				print_buttons(dialog, height, width, 1);
				break;
			case 1:
				button = -1;	/* Indicates input box is selected */
				print_buttons(dialog, height, width, 0);
				wmove(dialog, box_y, box_x + input_x);
				wrefresh(dialog);
				break;
			}
			break;
		case ' ':
		case '\n':
			delwin(dialog);
			return (button == -1 ? 0 : button);
		case 'X':
		case 'x':
			key = KEY_ESC;
			break;
		case KEY_ESC:
			key = on_key_esc(dialog);
			break;
		case KEY_RESIZE:
			delwin(dialog);
			on_key_resize();
			goto do_resize;
		}
	}

	delwin(dialog);
	return KEY_ESC;		/* ESC pressed */
}
Example #20
0
/*
 * Display a dialog box with a list of options that can be turned on or off
 */
int dialog_checklist(char *title, char *prompt, int height, int width, int list_height, int item_no, char **items)
{
  int i, x, y, cur_x, cur_y, box_x, box_y, key = 0, button = 0, choice = 0,
      scrolli = 0, max_choice, *status;
  WINDOW *dialog, *list;

  /* Allocate space for storing item on/off status */
  if ((status = malloc(sizeof(int)*item_no)) == NULL) {
    endwin();
    fprintf(stderr, "\nCan't allocate memory in dialog_checklist().\n");
    exit(-1);
  }
  /* Initializes status */
  for (i = 0; i < item_no; i++)
    status[i] = !strcasecmp(items[i*3 + 2], "on");

  max_choice = MIN(list_height, item_no);

  /* 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);

  draw_box(dialog, 0, 0, height, width, dialog_attr, border_attr);
  wattrset(dialog, border_attr);
  wmove(dialog, height-3, 0);
  waddch(dialog, ACS_LTEE);
  for (i = 0; i < width-2; i++)
    waddch(dialog, ACS_HLINE);
  wattrset(dialog, dialog_attr);
  waddch(dialog, ACS_RTEE);
  wmove(dialog, height-2, 1);
  for (i = 0; i < width-2; i++)
    waddch(dialog, ' ');

  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, 1, 3);

  list_width = width-6;
  getyx(dialog, cur_y, cur_x);
  box_y = cur_y + 1;
  box_x = (width - list_width)/2 - 1;

  /* create new window for the list */
  list = subwin(dialog, list_height, list_width, y + box_y + 1, x + box_x + 1);
  keypad(list, TRUE);

  /* draw a box around the list items */
  draw_box(dialog, box_y, box_x, list_height+2, list_width+2, menubox_border_attr, menubox_attr);

  check_x = 0;
  item_x = 0;
  /* Find length of longest item in order to center checklist */
  for (i = 0; i < item_no; i++) {
    check_x = MAX(check_x, strlen(items[i*3]) + strlen(items[i*3 + 1]) + 6);
    item_x = MAX(item_x, strlen(items[i*3]));
  }
  check_x = (list_width - check_x) / 2;
  item_x = check_x + item_x + 6;

  /* Print the list */
  for (i = 0; i < max_choice; i++)
    print_item(list, items[i*3], items[i*3 + 1], status[i], i, i == choice);
  wnoutrefresh(list);

  if (list_height < item_no) {
    wattrset(dialog, darrow_attr);
    wmove(dialog, box_y + list_height + 1, box_x + check_x + 5);
    waddch(dialog, ACS_DARROW);
    wmove(dialog, box_y + list_height + 1, box_x + check_x + 6);
    waddstr(dialog, "(+)");
  }

  x = width/2-11;
  y = height-2;
  print_button(dialog, "Cancel", y, x+14, FALSE);
  print_button(dialog, "  OK  ", y, x, TRUE);
  wrefresh(dialog);

  while (key != ESC) {
    key = wgetch(dialog);
    /* Check if key pressed matches first character of any item tag in list */
    for (i = 0; i < max_choice; i++)
      if (toupper(key) == toupper(items[(scrolli+i)*3][0]))
        break;

    if (i < max_choice || (key >= '1' && key <= MIN('9', '0'+max_choice)) || 
        key == KEY_UP || key == KEY_DOWN || key == ' ' ||
        key == '+' || key == '-' ) {
      if (key >= '1' && key <= MIN('9', '0'+max_choice))
        i = key - '1';
      else if (key == KEY_UP || key == '-') {
        if (!choice) {
          if (scrolli) {
#ifdef BROKEN_WSCRL
    /* wscrl() in ncurses 1.8.1 seems to be broken, causing a segmentation
       violation when scrolling windows of height = 4, so scrolling is not
       used for now */
            scrolli--;
            getyx(dialog, cur_y, cur_x);    /* Save cursor position */
            /* Reprint list to scroll down */
            for (i = 0; i < max_choice; i++)
              print_item(list, items[(scrolli+i)*3], items[(scrolli+i)*3 + 1], status[scrolli+i], i, i == choice);

#else

            /* Scroll list down */
            getyx(dialog, cur_y, cur_x);    /* Save cursor position */
            if (list_height > 1) {
              /* De-highlight current first item before scrolling down */
              print_item(list, items[scrolli*3], items[scrolli*3 + 1], status[scrolli], 0, FALSE);
              scrollok(list, TRUE);
              wscrl(list, -1);
              scrollok(list, FALSE);
            }
            scrolli--;
            print_item(list, items[scrolli*3], items[scrolli*3 + 1], status[scrolli], 0, TRUE);
#endif
            wnoutrefresh(list);

            /* print the up/down arrows */
            wmove(dialog, box_y, box_x + check_x + 5);
            wattrset(dialog, scrolli ? uarrow_attr : menubox_attr);
            waddch(dialog, scrolli ? ACS_UARROW : ACS_HLINE);
            wmove(dialog, box_y, box_x + check_x + 6);
            waddch(dialog, scrolli ? '(' : ACS_HLINE);
            wmove(dialog, box_y, box_x + check_x + 7);
            waddch(dialog, scrolli ? '-' : ACS_HLINE);
            wmove(dialog, box_y, box_x + check_x + 8);
            waddch(dialog, scrolli ? ')' : ACS_HLINE);
            wattrset(dialog, darrow_attr);
            wmove(dialog, box_y + list_height + 1, box_x + check_x + 5);
            waddch(dialog, ACS_DARROW);
            wmove(dialog, box_y + list_height + 1, box_x + check_x + 6);
            waddch(dialog, '(');
            wmove(dialog, box_y + list_height + 1, box_x + check_x + 7);
            waddch(dialog, '+');
            wmove(dialog, box_y + list_height + 1, box_x + check_x + 8);
            waddch(dialog, ')');
            wmove(dialog, cur_y, cur_x);  /* Restore cursor position */
            wrefresh(dialog);
          }
          continue;    /* wait for another key press */
        }
        else
          i = choice - 1;
      }
      else if (key == KEY_DOWN || key == '+') {
        if (choice == max_choice - 1) {
          if (scrolli+choice < item_no-1) {
#ifdef BROKEN_WSCRL
    /* wscrl() in ncurses 1.8.1 seems to be broken, causing a segmentation
       violation when scrolling windows of height = 4, so scrolling is not
       used for now */
            scrolli++;
            getyx(dialog, cur_y, cur_x);    /* Save cursor position */
            /* Reprint list to scroll up */
            for (i = 0; i < max_choice; i++)
              print_item(list, items[(scrolli+i)*3], items[(scrolli+i)*3 + 1], status[scrolli+i], i, i == choice);

#else

            /* Scroll list up */
            getyx(dialog, cur_y, cur_x);    /* Save cursor position */
            if (list_height > 1) {
              /* De-highlight current last item before scrolling up */
              print_item(list, items[(scrolli+max_choice-1)*3], items[(scrolli+max_choice-1)*3 + 1], status[scrolli+max_choice-1], max_choice-1, FALSE);
              scrollok(list, TRUE);
              scroll(list);
              scrollok(list, FALSE);
            }
            scrolli++;
            print_item(list, items[(scrolli+max_choice-1)*3], items[(scrolli+max_choice-1)*3 + 1], status[scrolli+max_choice-1], max_choice-1, TRUE);
#endif
            wnoutrefresh(list);

            /* print the up/down arrows */
            wattrset(dialog, uarrow_attr);
            wmove(dialog, box_y, box_x + check_x + 5);
            waddch(dialog, ACS_UARROW);
            wmove(dialog, box_y, box_x + check_x + 6);
            waddstr(dialog, "(-)");
            wmove(dialog, box_y + list_height + 1, box_x + check_x + 5);
            wattrset(dialog, scrolli+choice < item_no-1 ? darrow_attr : menubox_border_attr);
            waddch(dialog, scrolli+choice < item_no-1 ? ACS_DARROW : ACS_HLINE);
            wmove(dialog, box_y + list_height + 1, box_x + check_x + 6);
            waddch(dialog, scrolli+choice < item_no-1 ? '(' : ACS_HLINE);
            wmove(dialog, box_y + list_height + 1, box_x + check_x + 7);
            waddch(dialog, scrolli+choice < item_no-1 ? '+' : ACS_HLINE);
            wmove(dialog, box_y + list_height + 1, box_x + check_x + 8);
            waddch(dialog, scrolli+choice < item_no-1 ? ')' : ACS_HLINE);
            wmove(dialog, cur_y, cur_x);  /* Restore cursor position */
            wrefresh(dialog);
          }
          continue;    /* wait for another key press */
        }
        else
          i = choice + 1;
      }
      else if (key == ' ') {    /* Toggle item status */
        status[scrolli+choice] = !status[scrolli+choice];
        getyx(dialog, cur_y, cur_x);    /* Save cursor position */
        wmove(list, choice, check_x);
        wattrset(list, check_selected_attr);
        wprintw(list, "[%c]", status[scrolli+choice] ? 'X' : ' ');
        wnoutrefresh(list);
        wmove(dialog, cur_y, cur_x);  /* Restore cursor to previous position */
        wrefresh(dialog);
        continue;    /* wait for another key press */
      }

      if (i != choice) {
        /* De-highlight current item */
        getyx(dialog, cur_y, cur_x);    /* Save cursor position */
        print_item(list, items[(scrolli+choice)*3], items[(scrolli+choice)*3 + 1], status[scrolli+choice], choice, FALSE);

        /* Highlight new item */
        choice = i;
        print_item(list, items[(scrolli+choice)*3], items[(scrolli+choice)*3 + 1], status[scrolli+choice], choice, TRUE);
        wnoutrefresh(list);
        wmove(dialog, cur_y, cur_x);  /* Restore cursor to previous position */
        wrefresh(dialog);
      }
      continue;    /* wait for another key press */
    }

    switch (key) {
      case 'O':
      case 'o':
        delwin(dialog);
        for (i = 0; i < item_no; i++)
	    if (status[i]) {
		if (separate_output) {
		    fprintf(stderr, "%s\n", items[i*3]);
		} else {
		    fprintf(stderr, "\"%s\" ", items[i*3]);
		}
	    }
        free(status);
        return 0;
      case 'C':
      case 'c':
        delwin(dialog);
        free(status);
        return 1;
      case TAB:
      case KEY_LEFT:
      case KEY_RIGHT:
        if (!button) {
          button = 1;    /* Indicates "Cancel" button is selected */
          print_button(dialog, "  OK  ", y, x, FALSE);
          print_button(dialog, "Cancel", y, x+14, TRUE);
        }
        else {
          button = 0;    /* Indicates "OK" button is selected */
          print_button(dialog, "Cancel", y, x+14, FALSE);
          print_button(dialog, "  OK  ", y, x, TRUE);
        }
        wrefresh(dialog);
        break;
      case ' ':
      case '\n':
        delwin(dialog);
        if (!button)
          for (i = 0; i < item_no; i++)
	      if (status[i]) {
		  if (separate_output) {
		      fprintf(stderr, "%s\n", items[i*3]);
		  } else {
		      fprintf(stderr, "\"%s\" ", items[i*3]);
		  }
	      }
        free(status);
        return button;
      case ESC:
        break;
    }
  }

  delwin(dialog);
  free(status);
  return -1;    /* ESC pressed */
}
Example #21
0
static void
show_panels(PANEL * px[MAX_PANELS + 1])
{
    static const char *help[] =
    {
	"",
	"Commands are letter/digit pairs.  Digits are the panel number.",
	"",
	"  b - put the panel on the bottom of the stack",
	"  c - create the panel",
	"  d - delete the panel",
	"  h - hide the panel",
	"  m - move the panel (M for continuous move)",
	"  r - resize the panel",
	"  s - show the panel",
	"  b - put the panel on the top of the stack"
    };

    struct {
	bool valid;
	bool hidden;
	PANEL *above;
	PANEL *below;
    } table[MAX_PANELS + 1];

    WINDOW *win;
    PANEL *pan;
    int j;

    memset(table, 0, sizeof(table));
    for (j = 1; j <= MAX_PANELS; ++j) {
	table[j].valid = (px[j] != 0);
	if (table[j].valid) {
	    table[j].hidden = panel_hidden(px[j]);
	    table[j].above = panel_above(px[j]);
	    table[j].below = panel_below(px[j]);
	}
    }

    if ((win = newwin(LINES - 1, COLS, 0, 0)) != 0) {
	keypad(win, TRUE);
	if ((pan = new_panel(win)) != 0) {
	    werase(win);
	    mvwprintw(win, 0, 0, "Panels:\n");
	    for (j = 1; j <= MAX_PANELS; ++j) {
		if (table[j].valid) {
		    wprintw(win, " %d:", j);
		    if (table[j].hidden) {
			waddstr(win, " hidden");
		    } else {
			if (table[j].above) {
			    wprintw(win, " above %d",
				    which_panel(px, table[j].above));
			}
			if (table[j].below) {
			    wprintw(win, "%s below %d",
				    table[j].above ? "," : "",
				    which_panel(px, table[j].below));
			}
		    }
		    waddch(win, '\n');
		}
	    }
	    for (j = 0; j < (int) SIZEOF(help); ++j) {
		if (wprintw(win, "%s\n", help[j]) == ERR)
		    break;
	    }
	    wgetch(win);
	    del_panel(pan);
	    pflush();
	}
	delwin(win);
    }
}
Example #22
0
//adds a character to the window
int mvwaddch(WINDOW *win, int y, int x, const chtype ch)
{
   if (wmove(win,y,x)==0) return 0;
   return waddch(win, ch);
};
Example #23
0
void
shNCursesInterface::winPutchar (Window win, const char c)
{
    waddch (mWin[win], c);
}
Example #24
0
static int
test_opaque(int level, char **argv, WINDOW *stswin)
{
    WINDOW *txtbox = 0;
    WINDOW *txtwin = 0;
    FILE *fp;
    int ch;
    int txt_x = 0, txt_y = 0;
    int base_y;
    bool in_status = FALSE;
    int active = 0;

    if (argv[level] == 0) {
	beep();
	return FALSE;
    }

    if (level > 1) {
	txtbox = newwin(LINES - BASE_Y, COLS - level, BASE_Y, level);
	box(txtbox, 0, 0);
	wnoutrefresh(txtbox);

	txtwin = derwin(txtbox,
			getmaxy(txtbox) - 2,
			getmaxx(txtbox) - 2,
			1, 1);
	base_y = 0;
    } else {
	txtwin = stdscr;
	base_y = BASE_Y;
    }

    keypad(txtwin, TRUE);	/* enable keyboard mapping */
    (void) cbreak();		/* take input chars one at a time, no wait for \n */
    (void) noecho();		/* don't echo input */

    txt_y = base_y;
    txt_x = 0;
    wmove(txtwin, txt_y, txt_x);

    if ((fp = fopen(argv[level], "r")) != 0) {
	while ((ch = fgetc(fp)) != EOF) {
	    if (waddch(txtwin, UChar(ch)) != OK) {
		break;
	    }
	}
	fclose(fp);
    } else {
	wprintw(txtwin, "Cannot open:\n%s", argv[1]);
    }

    for (;;) {
	if (in_status) {
	    to_keyword(stswin, active);

	    ch = wgetch(stswin);
	    show_opaque(stswin, txtwin, TRUE, active);
	    if (Quit(ch))
		break;

	    switch (ch) {
	    case '\t':
		in_status = FALSE;
		break;
	    case KEY_DOWN:
	    case 'j':
		if (active < (int) SIZEOF(bool_funcs) - 1)
		    active++;
		else
		    beep();
		break;
	    case KEY_UP:
	    case 'k':
		if (active > 0)
		    active--;
		else
		    beep();
		break;
	    case ' ':
		bool_funcs[active].func(txtwin,
					!bool_funcs[active].func(txtwin, -1));
		break;
	    default:
		beep();
		break;
	    }
	    show_opaque(stswin, txtwin, FALSE, in_status ? active : -1);
	} else {
	    ch = mvwgetch(txtwin, txt_y, txt_x);
	    show_opaque(stswin, txtwin, TRUE, -1);
	    if (Quit(ch))
		break;

	    switch (ch) {
	    case '\t':
		in_status = TRUE;
		break;
	    case KEY_DOWN:
	    case 'j':
		if (txt_y < getmaxy(txtwin) - 1)
		    txt_y++;
		else
		    beep();
		break;
	    case KEY_UP:
	    case 'k':
		if (txt_y > base_y)
		    txt_y--;
		else
		    beep();
		break;
	    case KEY_LEFT:
	    case 'h':
		if (txt_x > 0)
		    txt_x--;
		else
		    beep();
		break;
	    case KEY_RIGHT:
	    case 'l':
		if (txt_x < getmaxx(txtwin) - 1)
		    txt_x++;
		else
		    beep();
		break;
	    case 'w':
		test_opaque(level + 1, argv, stswin);
		if (txtbox != 0) {
		    touchwin(txtbox);
		    wnoutrefresh(txtbox);
		} else {
		    touchwin(txtwin);
		    wnoutrefresh(txtwin);
		}
		break;
	    default:
		beep();
		napms(100);
		break;
	    }

	    show_opaque(stswin, txtwin, FALSE, -1);
	}
    }
    if (level > 1) {
	delwin(txtwin);
	delwin(txtbox);
    }
    return TRUE;
}
Example #25
0
//------------------------------------------------------------------------------
int addch( const chtype ch )
{
    __QCS_FCONTEXT( "addch" );

    return waddch( stdscr, ch );
}
Example #26
0
/*
 * Display text from a file in a dialog box.
 */
int dialog_textbox(const char *title, const char *tbuf,
		   int initial_height, int initial_width)
{
	int i, x, y, cur_x, cur_y, key = 0;
	int height, width, boxh, boxw;
	int passed_end;
	WINDOW *dialog, *box;

	begin_reached = 1;
	end_reached = 0;
	page_length = 0;
	hscroll = 0;
	buf = tbuf;
	page = buf;	/* page is pointer to start of page to be displayed */

do_resize:
	getmaxyx(stdscr, height, width);
	if (height < 8 || width < 8)
		return -ERRDISPLAYTOOSMALL;
	if (initial_height != 0)
		height = initial_height;
	else
		if (height > 4)
			height -= 4;
		else
			height = 0;
	if (initial_width != 0)
		width = initial_width;
	else
		if (width > 5)
			width -= 5;
		else
			width = 0;

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

	draw_shadow(stdscr, y, x, height, width);

	dialog = newwin(height, width, y, x);
	keypad(dialog, TRUE);

	/* Create window for box region, used for scrolling text */
	boxh = height - 4;
	boxw = width - 2;
	box = subwin(dialog, boxh, boxw, y + 1, x + 1);
	wattrset(box, dlg.dialog.atr);
	wbkgdset(box, dlg.dialog.atr & A_COLOR);

	keypad(box, TRUE);

	/* register the new window, along with its borders */
	draw_box(dialog, 0, 0, height, width,
		 dlg.dialog.atr, dlg.border.atr);

	wattrset(dialog, dlg.border.atr);
	mvwaddch(dialog, height - 3, 0, ACS_LTEE);
	for (i = 0; i < width - 2; i++)
		waddch(dialog, ACS_HLINE);
	wattrset(dialog, dlg.dialog.atr);
	wbkgdset(dialog, dlg.dialog.atr & A_COLOR);
	waddch(dialog, ACS_RTEE);

	print_title(dialog, title, width);

	print_button(dialog, gettext(" Exit "), height - 2, width / 2 - 4, TRUE);
	wnoutrefresh(dialog);
	getyx(dialog, cur_y, cur_x);	/* Save cursor position */

	/* Print first page of text */
	attr_clear(box, boxh, boxw, dlg.dialog.atr);
	refresh_text_box(dialog, box, boxh, boxw, cur_y, cur_x);

	while ((key != KEY_ESC) && (key != '\n')) {
		key = wgetch(dialog);
		switch (key) {
		case 'E':	/* Exit */
		case 'e':
		case 'X':
		case 'x':
			delwin(box);
			delwin(dialog);
			return 0;
		case 'g':	/* First page */
		case KEY_HOME:
			if (!begin_reached) {
				begin_reached = 1;
				page = buf;
				refresh_text_box(dialog, box, boxh, boxw,
						 cur_y, cur_x);
			}
			break;
		case 'G':	/* Last page */
		case KEY_END:

			end_reached = 1;
			/* point to last char in buf */
			page = buf + strlen(buf);
			back_lines(boxh);
			refresh_text_box(dialog, box, boxh, boxw,
					 cur_y, cur_x);
			break;
		case 'K':	/* Previous line */
		case 'k':
		case KEY_UP:
			if (!begin_reached) {
				back_lines(page_length + 1);

				/* We don't call print_page() here but use
				 * scrolling to ensure faster screen update.
				 * However, 'end_reached' and 'page_length'
				 * should still be updated, and 'page' should
				 * point to start of next page. This is done
				 * by calling get_line() in the following
				 * 'for' loop. */
				scrollok(box, TRUE);
				wscrl(box, -1);	/* Scroll box region down one line */
				scrollok(box, FALSE);
				page_length = 0;
				passed_end = 0;
				for (i = 0; i < boxh; i++) {
					if (!i) {
						/* print first line of page */
						print_line(box, 0, boxw);
						wnoutrefresh(box);
					} else
						/* Called to update 'end_reached' and 'page' */
						get_line();
					if (!passed_end)
						page_length++;
					if (end_reached && !passed_end)
						passed_end = 1;
				}

				print_position(dialog);
				wmove(dialog, cur_y, cur_x);	/* Restore cursor position */
				wrefresh(dialog);
			}
			break;
		case 'B':	/* Previous page */
		case 'b':
		case KEY_PPAGE:
			if (begin_reached)
				break;
			back_lines(page_length + boxh);
			refresh_text_box(dialog, box, boxh, boxw,
					 cur_y, cur_x);
			break;
		case 'J':	/* Next line */
		case 'j':
		case KEY_DOWN:
			if (!end_reached) {
				begin_reached = 0;
				scrollok(box, TRUE);
				scroll(box);	/* Scroll box region up one line */
				scrollok(box, FALSE);
				print_line(box, boxh - 1, boxw);
				wnoutrefresh(box);
				print_position(dialog);
				wmove(dialog, cur_y, cur_x);	/* Restore cursor position */
				wrefresh(dialog);
			}
			break;
		case KEY_NPAGE:	/* Next page */
		case ' ':
			if (end_reached)
				break;

			begin_reached = 0;
			refresh_text_box(dialog, box, boxh, boxw,
					 cur_y, cur_x);
			break;
		case '0':	/* Beginning of line */
		case 'H':	/* Scroll left */
		case 'h':
		case KEY_LEFT:
			if (hscroll <= 0)
				break;

			if (key == '0')
				hscroll = 0;
			else
				hscroll--;
			/* Reprint current page to scroll horizontally */
			back_lines(page_length);
			refresh_text_box(dialog, box, boxh, boxw,
					 cur_y, cur_x);
			break;
		case 'L':	/* Scroll right */
		case 'l':
		case KEY_RIGHT:
			if (hscroll >= MAX_LEN)
				break;
			hscroll++;
			/* Reprint current page to scroll horizontally */
			back_lines(page_length);
			refresh_text_box(dialog, box, boxh, boxw,
					 cur_y, cur_x);
			break;
		case KEY_ESC:
			key = on_key_esc(dialog);
			break;
		case KEY_RESIZE:
			back_lines(height);
			delwin(box);
			delwin(dialog);
			on_key_resize();
			goto do_resize;
		}
	}
	delwin(box);
	delwin(dialog);
	return key;		/* ESC pressed */
}
Example #27
0
static void display_aplist(WINDOW *w_aplst)
{
	char s[IW_ESSID_MAX_SIZE << 3];
	const char *sort_type[] = {
		[SO_CHAN]	= "Chan",
		[SO_SIGNAL]	= "Sig",
		[SO_MAC]        = "Mac",
		[SO_ESSID]	= "Essid",
		[SO_OPEN]	= "Open",
		[SO_CHAN_SIG]	= "Ch/Sg",
		[SO_OPEN_SIG]	= "Op/Sg"
	};
	int i, col, line = START_LINE;
	struct scan_entry *cur;

	/* Scanning can take several seconds - do not refresh if locked. */
	if (pthread_mutex_trylock(&sr.mutex))
		return;

	if (sr.head || *sr.msg)
		for (i = 1; i <= MAXYLEN; i++)
			mvwclrtoborder(w_aplst, i, 1);

	if (!sr.head)
		waddstr_center(w_aplst, WAV_HEIGHT/2 - 1, sr.msg);

	sort_scan_list(&sr.head);

	/* Truncate overly long access point lists to match screen height. */
	for (cur = sr.head; cur && line < MAXYLEN; line++, cur = cur->next) {
		col = CP_SCAN_NON_AP;

		if (!WLAN_CAPABILITY_IS_STA_BSS(cur->bss_capa) && (cur->bss_capa & WLAN_CAPABILITY_ESS)) {
			col = cur->has_key ? CP_SCAN_CRYPT : CP_SCAN_UNENC;
		}

		wmove(w_aplst, line, 1);
		if (!*cur->essid) {
			sprintf(s, "%-*s ", sr.max_essid_len, "<hidden ESSID>");
			wattron(w_aplst, COLOR_PAIR(col));
			waddstr(w_aplst, s);
		} else if (str_is_ascii(cur->essid)) {
			sprintf(s, "%-*s ", sr.max_essid_len, cur->essid);
			waddstr_b(w_aplst, s);
			wattron(w_aplst, COLOR_PAIR(col));
		} else {
			sprintf(s, "%-*s ", sr.max_essid_len, "<cryptic ESSID>");
			wattron(w_aplst, COLOR_PAIR(col));
			waddstr(w_aplst, s);
		}
		waddstr(w_aplst, ether_addr(&cur->ap_addr));

		wattroff(w_aplst, COLOR_PAIR(col));

		fmt_scan_entry(cur, s, sizeof(s));
		waddstr(w_aplst, " ");
		waddstr(w_aplst, s);
	}

	if (sr.num.entries < MAX_CH_STATS)
		goto done;

	wmove(w_aplst, MAXYLEN, 1);
	wadd_attr_str(w_aplst, A_REVERSE, "total:");
	sprintf(s, " %d ", sr.num.entries);
	waddstr(w_aplst, s);

	sprintf(s, "%s %ssc", sort_type[conf.scan_sort_order], conf.scan_sort_asc ? "a" : "de");
	wadd_attr_str(w_aplst, A_REVERSE, s);

	if (sr.num.entries + START_LINE > line) {
		sprintf(s, ", %d not shown", sr.num.entries + START_LINE - line);
		waddstr(w_aplst, s);
	}
	if (sr.num.open) {
		sprintf(s, ", %d open", sr.num.open);
		waddstr(w_aplst, s);
	}

	if (sr.num.two_gig && sr.num.five_gig) {
		waddch(w_aplst, ' ');
		wadd_attr_str(w_aplst, A_REVERSE, "5/2GHz:");
		sprintf(s, " %d/%d", sr.num.five_gig, sr.num.two_gig);
		waddstr(w_aplst, s);
	}

	if (sr.channel_stats) {
		waddch(w_aplst, ' ');
		if (conf.scan_sort_order == SO_CHAN && !conf.scan_sort_asc)
			sprintf(s, "bottom-%d:", (int)sr.num.ch_stats);
		else
			sprintf(s, "top-%d:", (int)sr.num.ch_stats);
		wadd_attr_str(w_aplst, A_REVERSE, s);

		for (i = 0; i < sr.num.ch_stats; i++) {
			waddstr(w_aplst, i ? ", " : " ");
			sprintf(s, "ch#%d", sr.channel_stats[i].val);
			wadd_attr_str(w_aplst, A_BOLD, s);
			sprintf(s, " (%d)", sr.channel_stats[i].count);
			waddstr(w_aplst, s);
		}
	}
done:
	pthread_mutex_unlock(&sr.mutex);
	wrefresh(w_aplst);
}
Example #28
0
/*
 * Display a dialog box with two buttons - Yes and No
 */
int
dialog_yesno (const char *title, const char *prompt, int height, int width)
{
    int i, x, y, key = 0, button = 0;
    WINDOW *dialog;

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

    draw_shadow (stdscr, y, x, height, width);

    dialog = newwin (height, width, y, x);
    keypad (dialog, TRUE);

    draw_box (dialog, 0, 0, height, width, dialog_attr, border_attr);
    wattrset (dialog, border_attr);
    mvwaddch (dialog, height-3, 0, ACS_LTEE);
    for (i = 0; i < width - 2; i++)
	waddch (dialog, ACS_HLINE);
    wattrset (dialog, dialog_attr);
    waddch (dialog, ACS_RTEE);

    if (title != NULL && strlen(title) >= width-2 ) {
	/* truncate long title -- mec */
	char * title2 = malloc(width-2+1);
	memcpy( title2, title, width-2 );
	title2[width-2] = '\0';
	title = title2;
    }

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

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

    print_buttons(dialog, height, width, 0);

    while (key != ESC) {
	key = wgetch (dialog);
	switch (key) {
	case 'Y':
	case 'y':
	    delwin (dialog);
	    return 0;
	case 'N':
	case 'n':
	    delwin (dialog);
	    return 1;

	case TAB:
	case KEY_LEFT:
	case KEY_RIGHT:
	    button = ((key == KEY_LEFT ? --button : ++button) < 0)
			? 1 : (button > 1 ? 0 : button);

	    print_buttons(dialog, height, width, button);
	    wrefresh (dialog);
	    break;
	case ' ':
	case '\n':
	    delwin (dialog);
	    return button;
	case ESC:
	    break;
	}
    }

    delwin (dialog);
    return -1;			/* ESC pressed */
}
Example #29
0
void Paint(STATE* state)
{
    size_t X = 0, Y = 0;

    attron(COLOR_PAIR(12) | A_BOLD);
    mvprintw(0, 0, "%s\n", gs_appname);

    move(state->Wy - 1, 0);
    for (X = 0; X < sizeof(state->keymap) / sizeof(int); X++) {
        attron(COLOR_PAIR(15));
        printw("%s", keymap_desc[X]);
        attron(COLOR_PAIR(11));
        printw("[");
        attron(COLOR_PAIR(14));
        printw("%s", keyname(state->keymap[X]));
        attron(COLOR_PAIR(11));
        printw("] ");
    }

    attroff(A_BOLD);
    attron(COLOR_PAIR(13));
    mvprintw(state->Wy - 1, state->Wx - strlen(state->clock),
            "%s", state->clock);

    // begin painting the status window
    if (state->statuswin) {
        StatusWindowPaint(state);
    }

    // begin painting the board
    werase(state->fieldwin);
    wattrset(state->fieldwin, A_NORMAL);
    box(state->fieldwin, 0, 0);

    if (! state->pause_f || state->do_pause_blocks) {
        for (Y = 0; Y < state->By; Y++) {
            wmove(state->fieldwin, Y + 1, 1);
            for (X = 0; X < state->Bx; X++) {
                wattrset(state->fieldwin, A_NORMAL);
                if (state->field[state->Bx * Y + X] == CLEARED) {
                        switch (state->do_clear) {
                        case CLEAR_FLASH:
                            wattron(state->fieldwin, COLOR_PAIR(rand() % 7 + 1));
                            break;
                        case CLEAR_BLANK:
                        default:
                            break;
                    }
                } else {
                    wattron(state->fieldwin, COLOR_PAIR(state->field[state->Bx * Y + X]));
                }

                waddch(state->fieldwin, ' ');
                waddch(state->fieldwin, ' ');
            }
        }
    }

    if (state->pause_f) {
        StatusMessage(state, state->fieldwin, gs_pause);
    }

    wattrset(state->fieldwin, A_NORMAL);
    if (state->game_over_f) {
        StatusMessage(state, state->fieldwin, gs_gameover);
    }


    // paint the tetrad
    if (state->tetrad)
        TetradPaint(state->fieldwin,
                state->tetrad->y + 1,
                state->tetrad->x + 1,
                state->tetrad);

    return;
}
Example #30
0
static void
_win_print_wrapped(WINDOW *win, const char *const message, size_t indent, int pad_indent)
{
    int starty = getcury(win);
    int wordi = 0;
    char *word = malloc(strlen(message) + 1);

    gchar *curr_ch = g_utf8_offset_to_pointer(message, 0);

    while (*curr_ch != '\0') {

        // handle space
        if (*curr_ch == ' ') {
            waddch(win, ' ');
            curr_ch = g_utf8_next_char(curr_ch);

        // handle newline
        } else if (*curr_ch == '\n') {
            waddch(win, '\n');
            _win_indent(win, indent + pad_indent);
            curr_ch = g_utf8_next_char(curr_ch);

        // handle word
        } else {
            wordi = 0;
            int wordlen = 0;
            while (*curr_ch != ' ' && *curr_ch != '\n' && *curr_ch != '\0') {
                size_t ch_len = mbrlen(curr_ch, MB_CUR_MAX, NULL);
                if ((ch_len == (size_t)-2) || (ch_len == (size_t)-1)) {
                    curr_ch++;
                    continue;
                }
                int offset = 0;
                while (offset < ch_len) {
                    word[wordi++] = curr_ch[offset++];
                }
                curr_ch = g_utf8_next_char(curr_ch);
            }
            word[wordi] = '\0';
            wordlen = utf8_display_len(word);

            int curx = getcurx(win);
            int cury = getcury(win);
            int maxx = getmaxx(win);

            // wrap required
            if (curx + wordlen > maxx) {
                int linelen = maxx - (indent + pad_indent);

                // word larger than line
                if (wordlen > linelen) {
                    gchar *word_ch = g_utf8_offset_to_pointer(word, 0);
                    while(*word_ch != '\0') {
                        curx = getcurx(win);
                        cury = getcury(win);
                        gboolean firstline = cury == starty;

                        if (firstline && curx < indent) {
                            _win_indent(win, indent);
                        }
                        if (!firstline && curx < (indent + pad_indent)) {
                            _win_indent(win, indent + pad_indent);
                        }

                        gchar copy[wordi+1];
                        g_utf8_strncpy(copy, word_ch, 1);
                        waddstr(win, copy);

                        word_ch = g_utf8_next_char(word_ch);
                    }

                // newline and print word
                } else {
                    waddch(win, '\n');
                    curx = getcurx(win);
                    cury = getcury(win);
                    gboolean firstline = cury == starty;

                    if (firstline && curx < indent) {
                        _win_indent(win, indent);
                    }
                    if (!firstline && curx < (indent + pad_indent)) {
                        _win_indent(win, indent + pad_indent);
                    }
                    waddstr(win, word);
                }

            // no wrap required
            } else {
                curx = getcurx(win);
                cury = getcury(win);
                gboolean firstline = cury == starty;

                if (firstline && curx < indent) {
                    _win_indent(win, indent);
                }
                if (!firstline && curx < (indent + pad_indent)) {
                    _win_indent(win, indent + pad_indent);
                }
                waddstr(win, word);
            }
        }

        // consume first space of next line
        int curx = getcurx(win);
        int cury = getcury(win);
        gboolean firstline = (cury == starty);

        if (!firstline && curx == 0 && *curr_ch == ' ') {
            curr_ch = g_utf8_next_char(curr_ch);
        }
    }

    free(word);
}