示例#1
0
int 
ifs_cfg(char *title, char *prompt, int height, int width, int y, int x, char *dev)
{
	WINDOW *w;
	int i, n, k, j;
	char titlez[80];
	char devz[80];
	int foo, done, key, set;
	struct device d;
	int ret = -1;
	int dev_id;

	init_dialog();
	dialog_clear();

	draw_shadow(stdscr, y, x, height, width);
	w = newwin(height, width, y, x);

	draw_box(w, 0, 0, height, width, dialog_attr, border_attr);
	wattrset(w, border_attr);
	keypad(w, TRUE);
	/* draw pretty lines outside. */
	/* box(w, ACS_VLINE, ACS_HLINE); */

	wrefresh(w);
	snprintf(titlez, sizeof(titlez), " [ %s ] ", title);

	foo = ((width / 2) - strlen(title));
	wmove(w, 0, foo);
	wattrset(w, title_attr);
	waddstr(w, titlez);
	wattrset(w, border_attr);
	for (i = 1; i < (height - 1); i++) {
		for (n = 1; n < (width - 1); n++) {
			wmove(w, i, n);
			waddch(w, ' ');
		}
	}

	draw_box(w, 2, 3, 12, 44, dialog_attr, border_attr);
	wattrset(w, title_attr);
	wmove(w, 4, 4);
	waddstr(w, "        IP ->");
	draw_box(w, 3, 18, 3, 25, dialog_attr, border_attr);

	wattrset(w, title_attr);
	wmove(w, 7, 4);
	waddstr(w, "   Netmask ->");
	draw_box(w, 6, 18, 3, 25, dialog_attr, border_attr);

	wattrset(w, title_attr);
	wmove(w, 10, 4);
	waddstr(w, "   Gateway ->");
	draw_box(w, 9, 18, 3, 25, dialog_attr, border_attr);

	print_button(w, "Cancel", height - 2, (width / 2) + 3, FALSE);
	print_button(w, "  OK  ", height - 2, (width / 2) - 11, FALSE);

	d.dhcp = DHCP_DISABLED;

	if ((ret = device_exist(dev)) >= 0) {
		wattrset(w, dialog_attr);
		wrefresh(w);
		/* fill in the previously configured values */
		snprintf(d.ip, sizeof(d.ip), "%s", dev_ip(dev));
		if (strlen(d.ip) > 6)
			mvwprintw(w, 4, 19, "%s", d.ip);
		else
			bzero(d.ip, sizeof(d.ip));

		snprintf(d.netmask, sizeof(d.netmask), "%s", dev_netmask(dev));
		if (strlen(d.netmask) > 6)
			mvwprintw(w, 7, 19, "%s", d.netmask);
		else
			bzero(d.netmask, sizeof(d.netmask));

		snprintf(d.gateway, sizeof(d.gateway), "%s", dev_gateway(dev));
		if (strlen(d.gateway) > 6)
			mvwprintw(w, 10, 19, "%s", d.gateway);
		else
			bzero(d.gateway, sizeof(d.gateway));

		snprintf(devz, sizeof(devz), "Editing device %s", dev);
		wmove(w, 1, (width / 2) - (strlen(devz) / 2));
		wattrset(w, dialog_attr);
		waddstr(w, devz);
		wrefresh(w);
	} else {
		bzero(d.ip, sizeof(d.ip));
		bzero(d.netmask, sizeof(d.netmask));
		bzero(d.gateway, sizeof(d.gateway));
		snprintf(devz, sizeof(devz), "Configuring device %s", dev);
		wmove(w, 1, (width / 2) - (strlen(devz) / 2));
		wattrset(w, dialog_attr);
		waddstr(w, devz);
	}


	/* start off in first window. */
	done = key = set = 0;
	j = 1;

	while (!done) {
		wrefresh(w);
		switch (j) {
		case 1:
			wattrset(w, inputbox_attr);
			wrefresh(w);
			print_button(w, "  OK  ", height - 2, (width / 2) - 11, FALSE);
			print_button(w, "Cancel", height - 2, (width / 2) + 3, FALSE);

			if (strlen(d.ip) < 1)
				bzero(d.ip, sizeof(d.ip));

			k = line_edit(w, 4, 19, 23, 23, inputbox_attr, 1, d.ip, DialogInputAttrs);
			if (k == KEY_DOWN) {
				j++;
				break;
			} else if (k == 9) {
				j++;
				break;
			} else if (k == KEY_UP) {
				j = 1;
				break;
			} else if (k == 10) {
				j++;
				break;
			}
			break;

		case 2:
			wattrset(w, inputbox_attr);
			wrefresh(w);
			/*
			 * print_button(w, "  OK
			 * ",height-2,(width/2)-11,FALSE);
			 */

			if (strlen(d.netmask) < 1)
				bzero(d.netmask, sizeof(d.netmask));

			k = line_edit(w, 7, 19, 23, 23, inputbox_attr, 1, d.netmask, DialogInputAttrs);
			if (k == KEY_DOWN) {
				j++;
				break;
			} else if (k == 10) {
				j++;
				break;
			} else if (k == 9) {
				j++;
				break;
			} else if (k == KEY_UP) {
				j = 1;
				break;
			}
			break;

		case 3:
			wattrset(w, inputbox_attr);
			wrefresh(w);
			print_button(w, "  OK  ", height - 2, (width / 2) - 11, FALSE);
			if (strlen(d.gateway) < 1)
				bzero(d.gateway, sizeof(d.gateway));

			k = line_edit(w, 10, 19, 23, 23, inputbox_attr, 1, d.gateway, DialogInputAttrs);
			if (k == KEY_DOWN) {
				j++;
				break;
			} else if (k == 10) {
				j++;
				break;
			} else if (k == 9) {
				j++;
				break;
			} else if (k == KEY_UP) {
				j--;
				break;
			}
			break;

		case 4:
			wattrset(w, title_attr);
			wrefresh(w);
			curs_set(0);
			print_button(w, "  OK  ", height - 2, (width / 2) - 11, TRUE);
			print_button(w, "Cancel", height - 2, (width / 2) + 3, FALSE);
			wrefresh(w);
			key = wgetch(w);
			if (key == KEY_UP) {
				j--;
				break;
			} else if (key == 9) {
				j++;
				break;
			} else if (key == KEY_DOWN) {
				j++;
				break;
			} else if (key == 10) {
				done = 1;
				set = 1;
				break;
			}
			break;

		case 5:
			wattrset(w, title_attr);
			wrefresh(w);
			curs_set(0);
			print_button(w, "  OK  ", height - 2, (width / 2) - 11, FALSE);
			print_button(w, "Cancel", height - 2, (width / 2) + 3, TRUE);
			wrefresh(w);
			key = wgetch(w);
			if (key == KEY_UP) {
				j = 4;
				break;
			} else if (key == KEY_DOWN) {
				j = 4;
				break;
			} else if (key == 9) {
				j = 1;
				break;
			} else if (key == 10) {
				dialog_clear();
				return -1;
				break;
			}
			break;
		}
	}

	if (strlen(d.gateway) > 1) {
		ret = dialog_yesno("ClosedBSD", "Would you like this device to be the default gateway?", -1, -1);
		if (ret == 0) {
			if ((ext_exist()) == -1) {
				d.ext = 1;
			} else {
				dialog_clear();
				ret = dialog_yesno("ClosedBSD", "You already have a default gateway set.  Overwrite?", -1, -1);
				if (ret == 0) {
					unset_ext(d.id);
				} else {
					d.ext = 0;
				}
			}
		} else {
			d.ext = 0;
		}
	} else
		d.ext = 0;

	strcpy(d.device, dev);

	if (set == 1) {
		dialog_clear();
		dev_id = device_exist(d.device);

		switch (dev_id) {
		case -1:
			d.id = next_device_id();
			insert_device(d);
			break;
		default:
			ret = dialog_yesno("ClosedBSD", "This device is already configured. Overwrite?", -1, -1);
			if (ret == 0) {
				d.id = dev_id;
				insert_device(d);
				break;
			} else {
				break;
			}
		}
	}
	dialog_clear();
	wrefresh(w);
	end_dialog();
	return DITEM_SUCCESS | DITEM_RESTORE | DITEM_CONTINUE;
}
示例#2
0
int
dialog_confirm(const char *title, const char *text, const char *options)
{
    WINDOW *dialog_win;
    int c, i, curs, newl, height, width;
    char *str, *tofree, *option, *word;
    int selected = 0;
    int optioncnt = 1;
    int col = 2;
    int line = 3;
    char opts[4][10];

    // Initialize
    memset(opts, 0, 4 * 10);

    // Check how many options exists
    for (i=0; options[i]; i++) {
        if (options[i] == ',')
            optioncnt++;
    }

    // We only support 4 options
    if (optioncnt > 4)
        return -1;

    // Calculate proper width taking into acount longest data
    width = strlen(options) + 6 * optioncnt;
    if (strlen(title) + 4 > width)
        width = strlen(title) + 4;
    if (strlen(text) > width && strlen(text) < 50)
        width = strlen(text);

    // Check we don't want a too big or small window
    if (width > DIALOG_MAX_WIDTH)
        width = DIALOG_MAX_WIDTH;
    if (width < DIALOG_MIN_WIDTH)
        width = DIALOG_MIN_WIDTH;

    // Determine dialog dimensions
    height = 7; // Minimum for header and button lines
    height += (strlen(text) / width);   // Space for the text.
    // Add one extra line for each newline in the text
    for (i=0; text[i]; i++) {
        if (text[i] == '\n')
            height++;
    }

    // Parse each line of payload looking for sdp information
    tofree = str = strdup((char*)options);
    i = 0;
    while ((option = strsep(&str, ",")) != NULL) {
        strcpy(opts[i++], option);
    }
    sng_free(tofree);

    // Create a new panel and show centered
    dialog_win = newwin(height, width, (LINES - height) / 2, (COLS - width) / 2);
    keypad(dialog_win, TRUE);
    curs = curs_set(0);

    // Set the window title
    mvwprintw(dialog_win, 1, (width - strlen(title)) / 2, title);

    // Write border and boxes around the window
    wattron(dialog_win, COLOR_PAIR(CP_BLUE_ON_DEF));
    box(dialog_win, 0, 0);

    mvwhline(dialog_win, 2, 1, ACS_HLINE, width);
    mvwaddch(dialog_win, 2, 0, ACS_LTEE);
    mvwaddch(dialog_win, 2, width - 1, ACS_RTEE);

    mvwhline(dialog_win, height - 3, 1, ACS_HLINE, width);
    mvwaddch(dialog_win, height - 3, 0, ACS_LTEE);
    mvwaddch(dialog_win, height - 3, width - 1, ACS_RTEE);

    // Exit confirmation message message
    wattron(dialog_win, COLOR_PAIR(CP_CYAN_ON_DEF));
    // Write the message into the screen
    tofree = str = strdup((char*)text);
    newl = 0;
    while ((word = strsep(&str, " ")) != NULL) {
        if (word[strlen(word)-1] == '\n') {
            word[strlen(word)-1] = '\0';
            newl = 1;
        }

        if (col + strlen(word) > width - 2) {
            line++;
            col = 2;
        }
        mvwprintw(dialog_win, line, col, "%s", word);
        col += strlen(word) + 1;
        if (newl) {
            line++;
            col = 2;
            newl = 0;
        }
    }
    sng_free(tofree);
    wattroff(dialog_win, COLOR_PAIR(CP_CYAN_ON_DEF));

    for (;;) {
        // A list of available keys in this window
        for (i = 0; i < optioncnt; i++ ) {
            if (i == selected) wattron(dialog_win, A_REVERSE);
            mvwprintw(dialog_win, height - 2, 10 + 10 * i, "[  %s  ]", opts[i]);
            wattroff(dialog_win, A_REVERSE);
        }

        c = wgetch(dialog_win);
        switch (c) {
            case KEY_RIGHT:
                selected++;
                break;
            case KEY_TAB:
            case KEY_LEFT:
                selected--;
                break;
            case KEY_SPACE:
            case KEY_ENTER:
            case KEY_INTRO:
                goto done;
            case KEY_ESC:
                selected = -1;
                goto done;
        }

        // Cycle through ooptions
        if (selected > optioncnt - 1)
            selected = 0;
        if (selected < 0)
            selected = optioncnt - 1;
    }

done:
    delwin(dialog_win);
    curs_set(curs);
    return selected;
}
示例#3
0
int wmenuSelect_ext(WINDOW *window, const int yinfo, const int y, const int x, const struct MenuItem *menuItems, const unsigned int itemLength, const char *available, const int menuType, unsigned int *current, int *real_key)
{
  unsigned int i;
  unsigned int ylast = y;
  int key = 0;

  /*
     if( ( menuType & ( MENU_HORIZ | MENU_VERT ) )==0 )    
     {
     wprintw(window,"Menu without direction. Defaulting horizontal.");
     menuType |= MENU_HORIZ;
     }
   */
  /* Warning: current may be out of bound, not checked */
  /* Make sure that the current is one of the available items */
  while(strchr(available, menuItems[*current].key)==NULL)
  {
    (*current)++ ;
    if( menuItems[*current].key==0 )
    {
      *current = 0;
    }
  }
#if defined(ALL_MOUSE_EVENTS) && defined(ENABLE_MOUSE)
  if((menuType & MENU_ACCEPT_OTHERS)==0 )
    mousemask(ALL_MOUSE_EVENTS, NULL);
#endif

  /* Repeat until allowable choice has been made */
  while( key==0 )
  {
    /* Display the menu */
    ylast = wmenuUpdate( window, yinfo, y, x, menuItems, itemLength, available,
        menuType, *current );
    wrefresh(window);
    /* Don't put wgetch after the following wclrtoeol */
    key = wgetch(window);
    if(real_key!=NULL)
      *real_key=key;

    /* Clear out all prompts and such */
    for( i = y; i < ylast; i ++ )
    {
      wmove(window, i, x );
      wclrtoeol(window);
    }
    wmove(window, yinfo, 0 );
    wclrtoeol(window);
    if(strchr(available, key)==NULL)
    {
      if(key=='2')
	key=KEY_DOWN;
      else if(key=='4')
	key=KEY_LEFT;
      else if(key=='5')
	key=KEY_ENTER;
      else if(key=='6')
	key=KEY_RIGHT;
      else if(key=='8')
	key=KEY_UP;
    }
    /* Cursor keys */
    switch(key)
    {
#if defined(KEY_MOUSE) && defined(ENABLE_MOUSE)
      case KEY_MOUSE:
	if((menuType & MENU_ACCEPT_OTHERS)==0 )
	{
	  MEVENT event;
	  if(getmouse(&event) == OK)
	  {	/* When the user clicks left mouse button */
	    if((event.bstate & BUTTON1_CLICKED) || (event.bstate & BUTTON1_DOUBLE_CLICKED))
	    {
	      key = menu_to_command(yinfo, y_org, x_org, menuItems, itemLength,
		  available, menuType, event.y, event.x);
	    }
	  }
	}
	break;
#endif
      case KEY_UP:
        if( (menuType & MENU_VERT)!=0 )
        {
          do {
            if( (*current)-- == 0 )
            {
              while( menuItems[(*current)+1].key ) (*current) ++ ;
            }
          } while( strchr( available, menuItems[*current].key )==NULL );
          key = 0;
        }
        break;
      case KEY_DOWN:
        if( (menuType & MENU_VERT)!=0 )
        {
          do {
            (*current) ++ ;
            if( menuItems[*current].key==0 ) *current = 0 ;
          } while( strchr( available, menuItems[*current].key )==NULL );
          key = 0;
        }
        break;
      case KEY_RIGHT:
        if( (menuType & MENU_HORIZ)!=0 )
        {
          do {
            (*current) ++ ;
            if( menuItems[*current].key==0 ) 
            {
              *current = 0 ;
            }
          } while( strchr( available, menuItems[*current].key )==NULL );
          key = 0;
        }
        break;
      case KEY_LEFT:
        if( (menuType & MENU_HORIZ) !=0)
        {
          do {
            if( (*current)-- == 0 )
            {
              while( menuItems[(*current) + 1].key ) (*current) ++ ;
            }
          } while( strchr( available, menuItems[*current].key )==NULL );
          key = 0;
        }
        break;
    }
    /* Enter equals to the keyboard shortcut of current menu item */
    if((key==13) || (key==10) || (key==KEY_ENTER) ||
        (((menuType & MENU_VERT) != 0) && ((menuType & MENU_VERT_ARROW2VALID) != 0)
         && (key==KEY_RIGHT || key==KEY_LEFT)))
      key = menuItems[*current].key;
#ifdef PADENTER
    if(key==PADENTER)
      key = menuItems[*current].key;
#endif
    /* Is pressed key among acceptable ones */
    if( key!=0 && (strchr(available, toupper(key))!=NULL || strchr(available, key)!=NULL))
    {
      const unsigned int old_current=*current;
      for(i=0; menuItems[i].key != 0 && menuItems[i].key != key; i++);
      *current=(menuItems[i].key == 0 ? old_current : i);
      break;
    }

    /* Should all keys to be accepted? */
    if( key && (menuType & MENU_ACCEPT_OTHERS)!=0 ) break;
    /* The key has not been accepted so far -> let's reject it */
#ifdef DEBUG
    if( key )
    {
      wmove(window,5,0);
      wprintw(window,"key %03X",key);
      putchar( BELL );
    }
#endif
    key = 0;
  }
  /* Clear out prompts and such */
  for( i = y; i <= ylast; i ++ )
  {
    wmove(window, i, x );
    wclrtoeol(window);
  }
  wmove(window, yinfo, 0 );
  wclrtoeol(window);
  return key;
}
示例#4
0
/* render a list of agents if available */
void
load_agent_list (WINDOW * main_win, char *addr)
{
  GMenu *menu;
  WINDOW *win;

  char buf[256];
  int c, quit = 1, i;
  int y, x, list_h, list_w, menu_w, menu_h;

  if (!conf.list_agents)
    return;

  getmaxyx (stdscr, y, x);
  list_h = y / 2;       /* list window - height */
  list_w = x - 4;       /* list window - width */
  menu_h = list_h - AGENTS_MENU_Y - 1;  /* menu window - height */
  menu_w = list_w - AGENTS_MENU_X - AGENTS_MENU_X;      /* menu window - width */

  win = newwin (list_h, list_w, (y - list_h) / 2, (x - list_w) / 2);
  keypad (win, TRUE);
  wborder (win, '|', '|', '-', '-', '+', '+', '+', '+');

  /* create a new instance of GMenu and make it selectable */
  menu = new_gmenu (win, menu_h, menu_w, AGENTS_MENU_Y, AGENTS_MENU_X);
  if (set_host_agents (addr, load_host_agents_gmenu, menu) == 1)
    goto out;

  post_gmenu (menu);
  snprintf (buf, sizeof buf, "User Agents for %s", addr);
  draw_header (win, buf, " %s", 1, 1, list_w - 2, color_panel_header);
  mvwprintw (win, 2, 2, "[UP/DOWN] to scroll - [q] to close window");
  wrefresh (win);

  while (quit) {
    c = wgetch (stdscr);
    switch (c) {
    case KEY_DOWN:
      gmenu_driver (menu, REQ_DOWN);
      break;
    case KEY_UP:
      gmenu_driver (menu, REQ_UP);
      break;
    case KEY_RESIZE:
    case 'q':
      quit = 0;
      break;
    }
    wrefresh (win);
  }

  touchwin (main_win);
  close_win (win);
  wrefresh (main_win);

out:

  /* clean stuff up */
  for (i = 0; i < menu->size; ++i)
    free (menu->items[i].name);
  if (menu->items)
    free (menu->items);
  free (menu);
}
int printcmdwin( cmdWindowtype *cw, Windowtype *awin, Windowtype *pwin )
	{
		int ch;
		int x = 0;
		int EXIT = 0;
		int cc = 1;

		if( cw->hidden )
			{
				clearcmd( cw );
			}
		else
			{ 
				//collorate
				wattron( cw->win, COLOR_PAIR(1) );

				/*dekorations*/
				box( cw->win, 0, 0 );

				//topp of border, workdirectory of activ window
				for( x = 0; cw->wd[x] != '\0' && x+2 < cw->w -2; x++ )
					{
						mvwprintw( cw->win, 0,x+2,"%c", cw->wd[x] );
					}

				//bottom of border, destinationdir, workdirectory of passiv window
				for( x = 0; cw->ddir[x] != '\0' && x+2 < cw->w -2; x++ )
					{
						mvwprintw( cw->win, 2,x+2,"%c", cw->ddir[x] );
					}

				//print the currentli writen command
				mvwprintw( cw->win, 1, 1, ":_" );
				for( x = 0; x < cw->cruser; x++ )
					{
						mvwprintw( cw->win, 1,x+2,"%c_", cw->currentcmd[0][x] );
					}

				//paint the rest of cw witb background color
				while( x < cw->w -3 )
					{
						mvwprintw( cw->win, 1,x+2," " );
						x++;
					}
			}

		wrefresh( cw->win );
		keypad( cw->win, TRUE );

		/*get commands*/
		while( !EXIT && (ch = wgetch(cw->win)) )
			{ switch ( ch )
					{
						case 0x7f: 		if( cw->cruser > 0 )
					/*backspace*/			{
												mvwprintw(cw->win, 1, 1+cw->cruser, "_ ");
												cw->cruser--;
												cw->currentcmd[0][cw->cruser] = ' ';
												if( cc == 1 )
													cw->currentcmd[1][cw->cruser] = ' ';
											}
										break;

						case KEY_UP: 	if( cc < CMDHISTORY )
					/*up*/					cc++;
													
											clearcmd( cw );

										for( x = 0; x < strlen(cw->currentcmd[cc]); x++ )
											{
												mvwprintw( cw->win, 1,x+2,"%c_", cw->currentcmd[cc][x] );
												cw->currentcmd[0][x] = cw->currentcmd[cc][x];
											}
										cw->cruser = x;
										wrefresh( cw->win );
										break;

						case KEY_DOWN:  if( cc > 0 )
					/*down*/				cc--;

										clearcmd( cw );

										for( x = 0; x < strlen(cw->currentcmd[cc]); x++ )
											{
												mvwprintw( cw->win, 1,x+2,"%c_", cw->currentcmd[cc][x] );
												cw->currentcmd[0][x] = cw->currentcmd[cc][x];
											}
										cw->cruser = x;
										wrefresh( cw->win );
										break;

						case 0xA:		trowcmd( cw, awin, pwin );
					/*Enter*/			clearcmd( cw );
										loadnewdir( awin, awin->wd );
										EXIT = 1;
										break;

						case 0x1B:  	EXIT = 1; 
					/*Escape*/			break;

						default: 		mvwprintw( cw->win, 1, 2+cw->cruser, "%c_", ch );
										cw->currentcmd[0][cw->cruser] = ch;
										cw->currentcmd[1][cw->cruser] = ch;
										cw->cruser++;
										wrefresh( cw->win );
										break;
					}
			}
			
		if( EXIT )
			{
				togglehide( cw );
			}
		
			clearcmd( cw );

		return 1;
	}
示例#6
0
/* render schemes dialog */
void
load_schemes_win (WINDOW * main_win)
{
  GMenu *menu;
  WINDOW *win;
  int c, quit = 1;
  size_t i, n;
  int y, x, h = SCHEME_WIN_H, w = SCHEME_WIN_W;
  int w2 = w - 2;

  /* ###NOTE: 'Custom Scheme' needs to go at the end */
  const char *choices[] = {
    "Monochrome/Default",
    "Green/Original",
    "Custom Scheme"
  };

  n = ARRAY_SIZE (choices);
  getmaxyx (stdscr, y, x);

  win = newwin (h, w, (y - h) / 2, (x - w) / 2);
  keypad (win, TRUE);
  wborder (win, '|', '|', '-', '-', '+', '+', '+', '+');

  /* create a new instance of GMenu and make it selectable */
  menu =
    new_gmenu (win, SCHEME_MENU_H, SCHEME_MENU_W, SCHEME_MENU_Y, SCHEME_MENU_X);
  /* remove custom color option if no custom scheme used */
  menu->size = conf.color_idx == 0 ? n - 1 : n;

  /* add items to GMenu */
  menu->items = (GItem *) xcalloc (n, sizeof (GItem));
  for (i = 0; i < n; ++i) {
    menu->items[i].name = alloc_string (choices[i]);
    menu->items[i].checked = 0;
  }
  post_gmenu (menu);

  draw_header (win, "Scheme Configuration", " %s", 1, 1, w2,
               color_panel_header);
  mvwprintw (win, 2, 2, "[ENTER] to switch scheme");

  wrefresh (win);
  while (quit) {
    c = wgetch (stdscr);
    switch (c) {
    case KEY_DOWN:
      gmenu_driver (menu, REQ_DOWN);
      break;
    case KEY_UP:
      gmenu_driver (menu, REQ_UP);
      break;
    case 32:
    case 0x0a:
    case 0x0d:
    case KEY_ENTER:
      gmenu_driver (menu, REQ_SEL);
      for (i = 0; i < n; ++i) {
        if (menu->items[i].checked != 1)
          continue;
        scheme_chosen (choices[i]);
        break;
      }
      quit = 0;
      break;
    case KEY_RESIZE:
    case 'q':
      quit = 0;
      break;
    }
    wrefresh (win);
  }
  /* clean stuff up */
  for (i = 0; i < n; ++i)
    free (menu->items[i].name);
  free (menu->items);
  free (menu);

  touchwin (main_win);
  close_win (win);
  wrefresh (main_win);
}
示例#7
0
/* render help dialog */
void
load_help_popup (WINDOW * main_win)
{
  int c, quit = 1;
  size_t i, n;
  int y, x, h = HELP_WIN_HEIGHT, w = HELP_WIN_WIDTH;
  int w2 = w - 2;
  WINDOW *win;
  GMenu *menu;

  n = ARRAY_SIZE (help_main);
  getmaxyx (stdscr, y, x);

  win = newwin (h, w, (y - h) / 2, (x - w) / 2);
  keypad (win, TRUE);
  wborder (win, '|', '|', '-', '-', '+', '+', '+', '+');

  /* create a new instance of GMenu and make it selectable */
  menu =
    new_gmenu (win, HELP_MENU_HEIGHT, HELP_MENU_WIDTH, HELP_MENU_Y,
               HELP_MENU_X);
  menu->size = n;

  /* add items to GMenu */
  menu->items = (GItem *) xcalloc (n, sizeof (GItem));
  for (i = 0; i < n; ++i) {
    menu->items[i].name = alloc_string (help_main[i]);
    menu->items[i].checked = 0;
  }
  post_gmenu (menu);

  draw_header (win, "GoAccess Quick Help", " %s", 1, 1, w2, color_panel_header);
  mvwprintw (win, 2, 2, "[UP/DOWN] to scroll - [q] to quit");

  wrefresh (win);
  while (quit) {
    c = wgetch (stdscr);
    switch (c) {
    case KEY_DOWN:
      gmenu_driver (menu, REQ_DOWN);
      break;
    case KEY_UP:
      gmenu_driver (menu, REQ_UP);
      break;
    case KEY_RESIZE:
    case 'q':
      quit = 0;
      break;
    }
    wrefresh (win);
  }
  /* clean stuff up */
  for (i = 0; i < n; ++i)
    free (menu->items[i].name);
  free (menu->items);
  free (menu);

  touchwin (main_win);
  close_win (win);
  wrefresh (main_win);
}
void
dump_window(WINDOW *w)
{
    wgetch(w);
    if (dumpfp != 0) {
	int y, x;
	int oldy, oldx;
	int maxy, maxx;
	int pass;
	char *cvec = 0;
	char *avec = 0;
	char *pvec = 0;
	int ccnt = 0;
	int acnt = 0;
	int pcnt = 0;
	int endy = -1;
	int endx = -1;

	fprintf(dumpfp, "Window %p\n", (void *) w);

	getyx(w, oldy, oldx);
	getmaxyx(w, maxy, maxx);
	fprintf(dumpfp, "size     (%dx%d)\n", maxy, maxx);
	getbegyx(w, y, x);
	fprintf(dumpfp, "begin    (%dx%d)\n", maxy, maxx);
	getyx(w, y, x);
	fprintf(dumpfp, "position (%d,%d)\n", y, x);

	if (maxy > 0 && maxx > 0) {
	    for (pass = 0; pass < 2; ++pass) {
		for (y = 0; y < maxy; ++y) {

		    if (cvec)
			memset(cvec, 0, (size_t) maxx + 1);
		    if (avec)
			memset(avec, 0, (size_t) maxx + 1);
		    if (pvec)
			memset(pvec, 0, (size_t) maxx + 1);

		    for (x = 0; x < maxx; ++x) {
			chtype data = mvwinch(w, y, x);
			chtype temp;
			char cc = (char) ((data & 0xff) ? (data & 0xff) : ' ');
			char aa;
			char pp;

			temp = ((data & A_ATTRIBUTES) & (~A_COLOR));
			if (temp) {
			    if (temp & A_ALTCHARSET) {
				aa = (temp & A_BOLD) ? 'A' : 'a';
			    } else if (temp & A_STANDOUT) {
				aa = (temp & A_BOLD) ? 'S' : 's';
			    } else if (temp & A_REVERSE) {
				aa = (temp & A_BOLD) ? 'R' : 'r';
			    } else if (temp & A_UNDERLINE) {
				aa = (temp & A_BOLD) ? 'U' : 'u';
			    } else {
				aa = (temp & A_BOLD) ? 'b' : '?';
			    }
			} else {
			    aa = ' ';
			}
			if (data & A_COLOR) {
			    if (PAIR_NUMBER((int) data) < 8) {
				pp = (char) ('0' + PAIR_NUMBER((int) data));
			    } else {
				pp = '*';
			    }
			} else {
			    pp = ' ';
			}

			if (pass) {
			    if (cvec)
				cvec[x] = cc;
			    if (avec)
				avec[x] = aa;
			    if (pvec)
				pvec[x] = pp;
			} else {
			    if (cc != ' ' || aa != ' ' || pp != ' ') {
				if (endx < x)
				    endx = x;
				if (endy < y)
				    endy = y;
			    }
			    ccnt += (cc != ' ');
			    acnt += (aa != ' ');
			    pcnt += (pp != ' ');
			}
		    }
		    if (pass) {
			fprintf(dumpfp, "%3d", y + 1);
			if (cvec)
			    fprintf(dumpfp, "\tc|%.*s|\n", maxx, cvec);
			if (avec)
			    fprintf(dumpfp, "\ta|%.*s|\n", maxx, avec);
			if (pvec)
			    fprintf(dumpfp, "\tp|%.*s|\n", maxx, pvec);
		    }
		}
		if (pass) {
		    free(cvec);
		    free(avec);
		    free(pvec);
		} else {
		    fprintf(dumpfp, "%d cells with characters\n", ccnt);
		    fprintf(dumpfp, "%d cells with video-attributes\n", acnt);
		    fprintf(dumpfp, "%d cells with color-attributes\n", pcnt);
		    if (endy < 0 || endx < 0)
			break;
		    /* reduce the dump a little, ignore really blank cells */
		    maxx = endx + 1;
		    maxy = endy + 1;
		    if (ccnt)
			cvec = malloc((size_t) maxx + 1);
		    if (acnt)
			avec = malloc((size_t) maxx + 1);
		    if (pcnt)
			pvec = malloc((size_t) maxx + 1);
		}
	    }
	}
	wmove(w, oldy, oldx);
    }
}
示例#9
0
int main()
{	ITEM **my_items;
	int c;				
	MENU *my_menu;
	int n_choices, i;
	ITEM *cur_item;	
	
	WINDOW *local_win;
	
	initscr();
	cbreak();
	noecho();
	keypad(stdscr, TRUE);
	
	start_color();
	init_pair(1, COLOR_BLUE, COLOR_BLACK);
	
	attron(COLOR_PAIR(1));
	mvprintw((LINES/2)-10,(COLS/3)-25,"%s",title1);
	mvprintw((LINES/2)-9,(COLS/3)-25,"%s",title2);
	mvprintw((LINES/2)-8,(COLS/3)-25,"%s",title3);
	mvprintw((LINES/2)-7,(COLS/3)-25,"%s",title4);
	mvprintw((LINES/2)-6,(COLS/3)-25,"%s",title5);
	attroff(COLOR_PAIR(1));

	//getch();
	mvprintw(((LINES/2)+5), ((COLS/2)-7), "q to Exit");
	refresh();
	
	local_win = newwin(5, 15, ((LINES/2)-2), ((COLS/3)+8));
	
	//box(local_win, 0 , 0);
	wrefresh(local_win);	
	
	n_choices = ARRAY_SIZE(choices);
	my_items = (ITEM **)calloc(n_choices + 1, sizeof(ITEM *));

	for(i = 0; i < n_choices; ++i)
	        my_items[i] = new_item(choices[i],"");//, choices[i]);
	my_items[n_choices] = (ITEM *)NULL;

	my_menu = new_menu((ITEM **)my_items);
	set_menu_win(my_menu, local_win);
	keypad(local_win, TRUE);
	
	post_menu(my_menu);
	wrefresh(local_win);
	while(true)
	{
		c = wgetch(local_win);
 		switch(c)
	    {	case KEY_DOWN:
		        menu_driver(my_menu, REQ_DOWN_ITEM);
				break;
			case KEY_UP:
				menu_driver(my_menu, REQ_UP_ITEM);
				break;	
			case 'a':
				//mvprintw(LINES-3, 0, "Item selected is : %s", item_name(current_item(my_menu)));
				const char *blargh=item_name(current_item(my_menu));
				//mvprintw(LINES-3,0,"Item selected is : %s",blargh);
				switch(blargh[0])
				{
					case 'S'://tart New Game":
						mvprintw(LINES-3,0,"Started New Game");
						break;
					case 'L'://oad Game":
						mvprintw(LINES-3,0,"Loaded Game");
						break;
					case 'O'://ptions":
						mvprintw(LINES-3,0,"Selected Options");
						break;
					case 'H'://elp":
						mvprintw(LINES-3,0,"Selected Help");
						break;
					case 'E'://xit":
						mvprintw(LINES-3,0,"Exiting");
						c='q';
				}
				break;			
		}
		if (c=='q'){
			break;
		}
	}	
	free_item(my_items[0]);
	free_item(my_items[1]);
	free_menu(my_menu);
	endwin();
}
示例#10
0
/*
 * Display a menu for choosing among a number of options
 */
int
dialog_menu (const char *title, const char *prompt, int height, int width,
		int menu_height, const char *current, int item_no,
		const char * const * items)

{
    int i, j, x, y, box_x, box_y;
    int key = 0, button = 0, scroll = 0, choice = 0, first_item = 0, max_choice;
    WINDOW *dialog, *menu;
    FILE *f;

    max_choice = MIN (menu_height, item_no);

    /* 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);
    wbkgdset (dialog, dialog_attr & A_COLOR);
    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);

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

    /* create new window for the menu */
    menu = subwin (dialog, menu_height, menu_width,
		y + box_y + 1, x + box_x + 1);
    keypad (menu, TRUE);

    /* draw a box around the menu items */
    draw_box (dialog, box_y, box_x, menu_height + 2, menu_width + 2,
	      menubox_border_attr, menubox_attr);

    /*
     * Find length of longest item in order to center menu.
     * Set 'choice' to default item. 
     */
    item_x = 0;
    for (i = 0; i < item_no; i++) {
	item_x = MAX (item_x, MIN(menu_width, strlen (items[i * 2 + 1]) + 2));
	if (strcmp(current, items[i*2]) == 0) choice = i;
    }

    item_x = (menu_width - item_x) / 2;

    /* get the scroll info from the temp file */
    if ( (f=fopen("lxdialog.scrltmp","r")) != NULL ) {
	if ( (fscanf(f,"%d\n",&scroll) == 1) && (scroll <= choice) &&
	     (scroll+max_choice > choice) && (scroll >= 0) &&
	     (scroll+max_choice <= item_no) ) {
	    first_item = scroll;
	    choice = choice - scroll;
	    fclose(f);
	} else {
	    scroll=0;
	    remove("lxdialog.scrltmp");
	    fclose(f);
	    f=NULL;
	}
    }
    if ( (choice >= max_choice) || (f==NULL && choice >= max_choice/2) ) {
	if (choice >= item_no-max_choice/2)
	    scroll = first_item = item_no-max_choice;
	else
	    scroll = first_item = choice - max_choice/2;
	choice = choice - scroll;
    }

    /* Print the menu */
    for (i=0; i < max_choice; i++) {
	print_item (menu, items[(first_item + i) * 2 + 1], i, i == choice,
                    (items[(first_item + i)*2][0] != ':'));
    }

    wnoutrefresh (menu);

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

    print_buttons (dialog, height, width, 0);

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

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

	if (strchr("ynm", key))
		i = max_choice;
	else {
        for (i = choice+1; i < max_choice; i++) {
		j = first_alpha(items[(scroll+i)*2+1], "YyNnMm");
		if (key == tolower(items[(scroll+i)*2+1][j]))
                	break;
	}
	if (i == max_choice)
       		for (i = 0; i < max_choice; i++) {
			j = first_alpha(items[(scroll+i)*2+1], "YyNnMm");
			if (key == tolower(items[(scroll+i)*2+1][j]))
                		break;
		}
	}

	if (i < max_choice || 
            key == KEY_UP || key == KEY_DOWN ||
            key == '-' || key == '+' ||
            key == KEY_PPAGE || key == KEY_NPAGE) {

            print_item (menu, items[(scroll+choice)*2+1], choice, FALSE,
                       (items[(scroll+choice)*2][0] != ':'));

	    if (key == KEY_UP || key == '-') {
                if (choice < 2 && scroll) {
	            /* Scroll menu down */
                    scrollok (menu, TRUE);
                    wscrl (menu, -1);
                    scrollok (menu, FALSE);

                    scroll--;

                    print_item (menu, items[scroll * 2 + 1], 0, FALSE,
                               (items[scroll*2][0] != ':'));
		} else
		    choice = MAX(choice - 1, 0);

	    } else if (key == KEY_DOWN || key == '+')  {

		print_item (menu, items[(scroll+choice)*2+1], choice, FALSE,
                                (items[(scroll+choice)*2][0] != ':'));

                if ((choice > max_choice-3) &&
                    (scroll + max_choice < item_no)
                   ) {
		    /* Scroll menu up */
		    scrollok (menu, TRUE);
                    scroll (menu);
                    scrollok (menu, FALSE);

                    scroll++;

                    print_item (menu, items[(scroll+max_choice-1)*2+1],
                               max_choice-1, FALSE,
                               (items[(scroll+max_choice-1)*2][0] != ':'));
                } 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) {
                	wscrl (menu, -1);
                	scroll--;
                	print_item (menu, items[scroll * 2 + 1], 0, FALSE,
                	(items[scroll*2][0] != ':'));
                    } else {
                        if (choice > 0)
                            choice--;
                    }
                }
                scrollok (menu, FALSE);

            } else if (key == KEY_NPAGE) {
                for (i=0; (i < max_choice); i++) {
                    if (scroll+max_choice < item_no) {
			scrollok (menu, TRUE);
			scroll(menu);
			scrollok (menu, FALSE);
                	scroll++;
                	print_item (menu, items[(scroll+max_choice-1)*2+1],
			            max_choice-1, FALSE,
			            (items[(scroll+max_choice-1)*2][0] != ':'));
		    } else {
			if (choice+1 < max_choice)
			    choice++;
		    }
                }

            } else
                choice = i;

            print_item (menu, items[(scroll+choice)*2+1], choice, TRUE,
                       (items[(scroll+choice)*2][0] != ':'));

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

            wnoutrefresh (menu);
            wrefresh (dialog);

	    continue;		/* wait for another key press */
        }

	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 (dialog);
	    break;
	case ' ':
	case 's':
	case 'y':
	case 'n':
	case 'm':
	    /* save scroll info */
	    if ( (f=fopen("lxdialog.scrltmp","w")) != NULL ) {
		fprintf(f,"%d\n",scroll);
		fclose(f);
	    }
	    delwin (dialog);
            fprintf(stderr, "%s\n", items[(scroll + choice) * 2]);
            switch (key) {
            case 's': return 3;
            case 'y': return 3;
            case 'n': return 4;
            case 'm': return 5;
            case ' ': return 6;
            }
	    return 0;
	case 'h':
	case '?':
	    button = 2;
	case '\n':
	    delwin (dialog);
	    if (button == 2) 
            	fprintf(stderr, "%s \"%s\"\n", 
			items[(scroll + choice) * 2],
			items[(scroll + choice) * 2 + 1] +
			first_alpha(items[(scroll + choice) * 2 + 1],""));
	    else
            	fprintf(stderr, "%s\n", items[(scroll + choice) * 2]);

	    remove("lxdialog.scrltmp");
	    return button;
	case 'e':
	case 'x':
	    key = ESC;
	case ESC:
	    break;
	}
    }

    delwin (dialog);
    remove("lxdialog.scrltmp");
    return -1;			/* ESC pressed */
}
示例#11
0
std::string Terminal::GetCommand(){
	std::string output = "";
	time_t commandRequestTime;
	time_t currentTime;
	time(&commandRequestTime);

	//Update status message
	if (status_window) {
		werase(status_window);
		print(status_window,statusStr.at(0).c_str());
	}

	while(true){
		if(SIGNAL_SEGFAULT){ // segmentation fault (SIGSEGV)
			Close();
			return "_SIGSEGV_";
		}
		if(SIGNAL_INTERRUPT){ // ctrl-c (SIGINT)
			SIGNAL_INTERRUPT = false;
			output = "CTRL_C";
			text_length = 0;
			break;
		}
		else if(SIGNAL_TERMSTOP){ // ctrl-z (SIGTSTP)
			SIGNAL_TERMSTOP = false;
			output = "CTRL_Z";
			text_length = 0;
			break;
		}

		flush(); // If there is anything in the stream, dump it to the screen

		//Time out if there is no command within the set interval (default 0.5 s). 
		if (commandTimeout_ > 0) {
			time(&currentTime);
			//If the timeout has passed we simply return the empty output string.
			if (currentTime > commandRequestTime + commandTimeout_) {
				break;
			}
		}
		
		int keypress = wgetch(input_window);
	
		// Check for internal commands
		if(keypress == ERR){ } // No key was pressed in the interval
		else if(keypress == 10){ // Enter key (10)
			std::string temp_cmd = cmd.Get();
			//Reset the position in the history.
			commands.Reset();
			if(temp_cmd != "" && temp_cmd != commands.PeekPrev()){ // Only save this command if it is different than the previous command
				commands.Push(temp_cmd);
			}
			output = temp_cmd;
			std::cout << prompt << output << "\n";
			flush();
			text_length = 0;
			_scrollPosition = 0;
			clear_();
			tabCount = 0;
			break;
		} 
		else if(keypress == '\t' && enableTabComplete) {
			tabCount++;
			output = cmd.Get().substr(0,cursX - offset) + "\t";
			break;
		}
		else if(keypress == 4){ // ctrl-d (EOT)
			output = "CTRL_D";
			text_length = 0;
			clear_();
			tabCount = 0;
			break;
		}
		else if(keypress == 9){ } // Tab key (9)
		else if(keypress == KEY_UP){ // 259
			if(commands.GetIndex() == 0){ commands.Capture(cmd.Get()); }
			std::string temp_cmd = commands.GetPrev();
			if(temp_cmd != "NULL"){
				clear_();
				cmd.Set(temp_cmd);
				in_print_(cmd.Get().c_str());
				text_length = cmd.GetSize();
			}
		}
		else if(keypress == KEY_DOWN){ // 258
			std::string temp_cmd = commands.GetNext();
			if(temp_cmd != "NULL"){
				clear_();
				cmd.Set(temp_cmd);
				in_print_(cmd.Get().c_str());
				text_length = cmd.GetSize();
			}
		}
		else if(keypress == KEY_LEFT){ cursX--; } // 260
		else if(keypress == KEY_RIGHT){ cursX++; } // 261
		else if(keypress == KEY_PPAGE){ //Page up key
			scroll_(-(_winSizeY-2));
		}
		else if(keypress == KEY_NPAGE){ //Page down key
			scroll_(_winSizeY-2);
		}
		else if(keypress == KEY_BACKSPACE){ // 263
			wmove(input_window, 0, --cursX);
			wdelch(input_window);
			cmd.Pop(cursX - offset);
			text_length = cmd.GetSize();
		}
		else if(keypress == KEY_DC){ // Delete character (330)
			//Remove character from terminal
			wdelch(input_window);
			//Remove character from cmd string
			cmd.Pop(cursX - offset);
			text_length = cmd.GetSize();
		}
		else if(keypress == KEY_IC){ cmd.ToggleInsertMode(); } // Insert key (331)
		else if(keypress == KEY_HOME){ cursX = offset; }
		else if(keypress == KEY_END){ cursX = text_length + offset; }
		else if(keypress == KEY_MOUSE) { //Handle mouse events
			MEVENT mouseEvent;
			//Get information about mouse event.
			getmouse(&mouseEvent);
			
			switch (mouseEvent.bstate) {
				//Scroll up
				case BUTTON4_PRESSED:
					scroll_(-3);
					break;
				//Scroll down. (Yes the name is strange.)
				case REPORT_MOUSE_POSITION:
					scroll_(3);
					break;
			}
		}	
		else if(keypress == KEY_RESIZE) {
			//Do nothing with the resize key
		}
		else{ 
			in_char_((char)keypress); 
			cmd.Put((char)keypress, cursX - offset - 1);
			text_length = cmd.GetSize();
		}
		
		// Check for cursor too far to the left
		if(cursX < offset){ cursX = offset; }
	
		// Check for cursor too far to the right
		if(cursX > (text_length + offset)){ cursX = text_length + offset; }
	
		//Update status message
		if (status_window) {
			werase(status_window);
			print(status_window,statusStr.at(0).c_str());
		}

		if (keypress != ERR) tabCount = 0;
		update_cursor_();
		refresh_();
	}
	return output;
}
示例#12
0
int main()
{
    WINDOW *win, *boxing;
    int c;
    int x, y;

    initscr();

    signal(SIGINT, die);
    noecho();
    crmode();

    win = subwin(stdscr,
	    LINES / 2,
	    COLS / 2,
	    LINES / 4,
	    COLS / 4);
    scrollok(win, TRUE);

    boxing = subwin(stdscr,
	    LINES / 2 + 2,
	    COLS / 2 + 2,
	    LINES / 4 - 1,
	    COLS / 4 - 1);

    box(boxing, '!', '-');
    refresh();

    wmove(win, 0, 0);
    wrefresh(win);

    while ((c = wgetch(win)) != '#') {
	if (iscntrl(c)) {
	    switch (c) {
            case CNTRL('E'):
                werase(win);
                wrefresh(win);
                continue;

            case CNTRL('R'):
                wrefresh(curscr);
                continue;

            case CNTRL('['):
                getyx(win, y, x);
                c = wgetch(win);
                if (c == '[' || c == 'O')
                    c = wgetch(win);
                switch (c) {
                case 'H':
                    x = 0;
                    y = 0;
                    goto change;
                case 'A':
                    y--;
                    goto change;
                case 'B':
                    y++;
                    goto change;
                case 'C':
                    x++;
                    goto change;
                case 'D':
                    x--;
change:
                    if (x >= win->_maxx) {
                        x = 0;
                        y++;
                    }
                    if (y >= win->_maxy)
                        y = 0;
                    wmove(win, y, x);
                    wrefresh(win);
                    continue;
                default:
                    break;
                }
                break;
            default:
                continue;
	    }
        }
	waddch(win, c);
	wrefresh(win);
    }
    die(SIGINT);
}
示例#13
0
/*
 * Display a dialog box with a list of options that can be turned on or off
 * The `flag' parameter is used to select between radiolist and checklist.
 */
int
dialog_checklist (const char *title, const char *prompt, int height, int width,
	int list_height, int item_no, const char * const * items, int flag)
	
{
    int i, x, y, box_x, box_y;
    int key = 0, button = 0, choice = 0, scroll = 0, max_choice, *status;
    WINDOW *dialog, *list;

    checkflag = flag;

    /* 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");
	if (!choice && status[i])
            choice = i;
    }

    max_choice = MIN (list_height, item_no);

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

    list_width = width - 6;
    box_y = height - list_height - 5;
    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);

    /* Find length of longest item in order to center checklist */
    check_x = 0;
    for (i = 0; i < item_no; i++) 
	check_x = MAX (check_x, + strlen (items[i * 3 + 1]) + 4);

    check_x = (list_width - check_x) / 2;
    item_x = check_x + 4;

    if (choice >= list_height) {
	scroll = choice - list_height + 1;
	choice -= scroll;
    }

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

    print_arrows(dialog, choice, item_no, scroll,
			box_y, box_x + check_x + 5, list_height);

    print_buttons(dialog, height, width, 0);

    wnoutrefresh (list);
    wnoutrefresh (dialog);
    doupdate ();

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

    	for (i = 0; i < max_choice; i++)
            if (toupper(key) == toupper(items[(scroll+i)*3+1][0]))
                break;


	if ( i < max_choice || key == KEY_UP || key == KEY_DOWN || 
	    key == '+' || key == '-' ) {
	    if (key == KEY_UP || key == '-') {
		if (!choice) {
		    if (!scroll)
			continue;
		    /* Scroll list down */
		    if (list_height > 1) {
			/* De-highlight current first item */
			print_item (list, items[scroll * 3 + 1],
					status[scroll], 0, FALSE);
			scrollok (list, TRUE);
			wscrl (list, -1);
			scrollok (list, FALSE);
		    }
		    scroll--;
		    print_item (list, items[scroll * 3 + 1],
				status[scroll], 0, TRUE);
		    wnoutrefresh (list);

    		    print_arrows(dialog, choice, item_no, scroll,
				box_y, box_x + check_x + 5, list_height);

		    wrefresh (dialog);

		    continue;	/* wait for another key press */
		} else
		    i = choice - 1;
	    } else if (key == KEY_DOWN || key == '+') {
		if (choice == max_choice - 1) {
		    if (scroll + choice >= item_no - 1)
			continue;
		    /* Scroll list up */
		    if (list_height > 1) {
			/* De-highlight current last item before scrolling up */
			print_item (list, items[(scroll + max_choice - 1) * 3 + 1],
				    status[scroll + max_choice - 1],
				    max_choice - 1, FALSE);
			scrollok (list, TRUE);
			scroll (list);
			scrollok (list, FALSE);
		    }
		    scroll++;
		    print_item (list, items[(scroll + max_choice - 1) * 3 + 1],
				status[scroll + max_choice - 1],
				max_choice - 1, TRUE);
		    wnoutrefresh (list);

    		    print_arrows(dialog, choice, item_no, scroll,
				box_y, box_x + check_x + 5, list_height);

		    wrefresh (dialog);

		    continue;	/* wait for another key press */
		} else
		    i = choice + 1;
	    }
	    if (i != choice) {
		/* De-highlight current item */
		print_item (list, items[(scroll + choice) * 3 + 1],
			    status[scroll + choice], choice, FALSE);
		/* Highlight new item */
		choice = i;
		print_item (list, items[(scroll + choice) * 3 + 1],
			    status[scroll + choice], choice, TRUE);
		wnoutrefresh (list);
		wrefresh (dialog);
	    }
	    continue;		/* wait for another key press */
	}
	switch (key) {
	case 'H':
	case 'h':
	case '?':
	    delwin (dialog);
	    free (status);
	    return 1;
	case 'S':
	case 's':
	case ' ':
	case '\n':
	    if (!button) {
		if (flag == FLAG_CHECK) {
		    status[scroll + choice] = !status[scroll + choice];
		    wmove (list, choice, check_x);
		    wattrset (list, check_selected_attr);
		    wprintw (list, "[%c]", status[scroll + choice] ? 'X' : ' ');
		} else {
		    if (!status[scroll + choice]) {
			for (i = 0; i < item_no; i++)
			    status[i] = 0;
			status[scroll + choice] = 1;
			for (i = 0; i < max_choice; i++)
			    print_item (list, items[(scroll + i) * 3 + 1],
					status[scroll + i], i, i == choice);
		    }
		}
		wnoutrefresh (list);
		wrefresh (dialog);
            
		for (i = 0; i < item_no; i++) {
		    if (status[i]) {
			if (flag == FLAG_CHECK) {
			    fprintf (stderr, "\"%s\" ", items[i * 3]);
			} else {
			    fprintf (stderr, "%s", items[i * 3]);
			}

		    }
		}
            }
	    delwin (dialog);
	    free (status);
	    return button;
	case 'X':
	case 'x':
	    key = ESC;
	case ESC:
	    break;
	}

	/* Now, update everything... */
	doupdate ();
    }
    

    delwin (dialog);
    free (status);
    return -1;			/* ESC pressed */
}
示例#14
0
void player::makeUserPlayer(WINDOW*& window)
{
    bool goodInput = false;
    setX(73);
    setY(21);

    //gender
    while(goodInput != true)
    {
        mvwprintw(window, 0, 0, "Are you (M)ale or (F)emale: ");
        char userGender;
        wmove(window, 0, 28);
        userGender = wgetch(window);
        userGender = toupper(userGender);

        if(userGender == 'M' || userGender == 'F')
        {
            goodInput = true;
            gender = userGender;
        }
        else
        {
            goodInput = false;
        }
    }


    goodInput = false;

    //name
    while(goodInput != true)
    {
        werase(window);
        mvwprintw(window, 0, 0, "What is your name: ");
        std::string userName;

        int x = 19; int y = 0; wmove(window, y, x);
        int letterCounter = 0;
        char ch;
        echo();
        while(letterCounter < 12 && ch != '\n')
        {
            ch = wgetch(window);
            if(ch == '\n')
            {
                break;
            }
            else
            {
                userName.push_back(ch);
                mvwaddch(window, y, x, ch);
            }
            letterCounter++;
            x++;
        }

        //userName = string(charName);



        if(userName.size() > 12)
        {
            goodInput = false;
        }
        else
        {
            goodInput = true;
            name = userName;
            name = name.substr(0, letterCounter);
        }
    }
    noecho();
    werase(window);
}
示例#15
0
int getch(void)
{
    return wgetch(mainwin);
}
示例#16
0
int interact(WIDGET *widget)
{
	int c;
	FUNCP f;
	WINDOW *win = widget->win;
	void *wid = widget->wid;
	int desc = widget->desc;

	box(win, ACS_CKBOARD, ACS_CKBOARD);
        wrefresh(win);
        while ((c = wgetch(win)) != '[') {
                switch (c) {
		case KEY_LEFT:
			if (f = widget->direct)
				f(wid, D_LEFT, desc);
			break;
		case KEY_RIGHT:
			if (f = widget->direct)
				f(wid, D_RIGHT, desc);
			break;
		case KEY_UP:
			if (f = widget->direct)
				f(wid, D_UP, desc);
			break;
		case KEY_DOWN:
			if (f = widget->direct)
				f(wid, D_DOWN, desc);
			break;
		case 10: /* Enter */
			if (f = widget->enter)
				/* clear me, waiting for a forward set */
				wborder(win, ' ', ' ', ' ', ' ', 
					     ' ', ' ', ' ', ' ');
				wrefresh(win);

				/* back here */
				f(wid);

				/* back to me, set myself again */
				box(win, ACS_CKBOARD, ACS_CKBOARD);
				wrefresh(win);
			break;
		case '-':  /* 0x2d */
			if (f = widget->backspace)
				f(wid);
			break;
		/* all printable chars */
		case 0x20 ... 0x2c: 
		case 0x2e ... 0x7e:
			if (f = widget->input)
				f(wid, c);
			break;
		default:
			break;
                }
        }
	/* clear me, waiting for a backward set */
	wborder(win, ' ', ' ', ' ', ' ', 
		     ' ', ' ', ' ', ' ');
	wrefresh(win);
	return 0;
}
示例#17
0
int mvwgetch(WINDOW* win, int y, int x)
{
    move(y, x);
    return wgetch(win);
}
示例#18
0
void getinput(struct FIELDLIST *list, struct FIELD *field, int *exitkey)
{
    int ch;
    int y, x;
    int endloop = 0;

    wmove(list->fieldwin, field->ypos, field->xpos);
    wattrset(list->fieldwin, FIELDATTR);
    wprintw(list->fieldwin, "%s", field->buf);
    update_panels();
    doupdate();

    do {
        ch = wgetch(list->fieldwin);
        switch (ch) {
#ifndef DISABLEBS
        case KEY_BACKSPACE:
#endif
        case 7:
        case 8:
        case KEY_DC:
        case KEY_LEFT:
            if (field->tlen > 0) {
                getyx(list->fieldwin, y, x);
                x--;
                wmove(list->fieldwin, y, x);
                wprintw(list->fieldwin, " ");
                wmove(list->fieldwin, y, x);
                field->tlen--;
                field->buf[field->tlen] = '\0';
            }
            break;
        case 9:
        case 27:
        case 24:
        case 13:
        case 10:
        case KEY_UP:
        case KEY_DOWN:
            endloop = 1;
            *exitkey = ch;

            break;
        case 12:
            refresh_screen();
            break;
        default:
            if ((field->tlen < field->len) && ((ch >= 32) && (ch <= 127))) {
                wprintw(list->fieldwin, "%c", ch);
                if (ch == ' ') {
                    getyx(list->fieldwin, y, x);
                    wmove(list->fieldwin, y, x);
                }
                field->buf[field->tlen + 1] = '\0';
                field->buf[field->tlen] = ch;
                field->tlen++;
            }
            break;
        }

        doupdate();
    } while (!endloop);
}
示例#19
0
/* render sort dialog */
void
load_sort_win (WINDOW * main_win, GModule module, GSort * sort)
{
  GMenu *menu;
  WINDOW *win;
  GSortField opts[SORT_MAX_OPTS];

  int c, quit = 1;
  int i = 0, k, n = 0;
  int y, x, h = SORT_WIN_H, w = SORT_WIN_W;
  int w2 = w - 2;

  getmaxyx (stdscr, y, x);

  /* determine amount of sort choices */
  for (i = 0, k = 0; -1 != sort_choices[module][i]; i++) {
    GSortField field = sort_choices[module][i];
    if (SORT_BY_CUMTS == field && !conf.serve_usecs)
      continue;
    else if (SORT_BY_MAXTS == field && !conf.serve_usecs)
      continue;
    else if (SORT_BY_AVGTS == field && !conf.serve_usecs)
      continue;
    else if (SORT_BY_BW == field && !conf.bandwidth)
      continue;
    else if (SORT_BY_PROT == field && !conf.append_protocol)
      continue;
    else if (SORT_BY_MTHD == field && !conf.append_method)
      continue;
    opts[k++] = field;
    n++;
  }

  win = newwin (h, w, (y - h) / 2, (x - w) / 2);
  keypad (win, TRUE);
  wborder (win, '|', '|', '-', '-', '+', '+', '+', '+');

  /* create a new instance of GMenu and make it selectable */
  menu = new_gmenu (win, SORT_MENU_H, SORT_MENU_W, SORT_MENU_Y, SORT_MENU_X);
  menu->size = n;
  menu->selectable = 1;

  /* add items to GMenu */
  menu->items = (GItem *) xcalloc (n, sizeof (GItem));

  /* set choices, checked option and index */
  for (i = 0; i < n; ++i) {
    GSortField field = sort_choices[module][opts[i]];
    if (SORT_BY_HITS == field) {
      menu->items[i].name = alloc_string ("Hits");
      if (sort->field == SORT_BY_HITS) {
        menu->items[i].checked = 1;
        menu->idx = i;
      }
    } else if (SORT_BY_VISITORS == field) {
      menu->items[i].name = alloc_string ("Visitors");
      if (sort->field == SORT_BY_VISITORS) {
        menu->items[i].checked = 1;
        menu->idx = i;
      }
    } else if (SORT_BY_DATA == field) {
      menu->items[i].name = alloc_string ("Data");
      if (sort->field == SORT_BY_DATA) {
        menu->items[i].checked = 1;
        menu->idx = i;
      }
    } else if (SORT_BY_BW == field) {
      menu->items[i].name = alloc_string ("Bandwidth");
      if (sort->field == SORT_BY_BW) {
        menu->items[i].checked = 1;
        menu->idx = i;
      }
    } else if (SORT_BY_AVGTS == field) {
      menu->items[i].name = alloc_string ("Avg. Time Served");
      if (sort->field == SORT_BY_AVGTS) {
        menu->items[i].checked = 1;
        menu->idx = i;
      }
    } else if (SORT_BY_CUMTS == field) {
      menu->items[i].name = alloc_string ("Cum. Time Served");
      if (sort->field == SORT_BY_CUMTS) {
        menu->items[i].checked = 1;
        menu->idx = i;
      }
    } else if (SORT_BY_MAXTS == field) {
      menu->items[i].name = alloc_string ("Max. Time Served");
      if (sort->field == SORT_BY_MAXTS) {
        menu->items[i].checked = 1;
        menu->idx = i;
      }
    } else if (SORT_BY_PROT == field) {
      menu->items[i].name = alloc_string ("Protocol");
      if (sort->field == SORT_BY_PROT) {
        menu->items[i].checked = 1;
        menu->idx = i;
      }
    } else if (SORT_BY_MTHD == field) {
      menu->items[i].name = alloc_string ("Method");
      if (sort->field == SORT_BY_MTHD) {
        menu->items[i].checked = 1;
        menu->idx = i;
      }
    }
  }
  post_gmenu (menu);

  draw_header (win, "Sort active module by", " %s", 1, 1, w2,
               color_panel_header);
  mvwprintw (win, 2, 2, "[ENTER] to select field - [TAB] sort");
  if (sort->sort == SORT_ASC)
    mvwprintw (win, SORT_WIN_H - 2, 1, " %s", SORT_ASC_SEL);
  else
    mvwprintw (win, SORT_WIN_H - 2, 1, " %s", SORT_DESC_SEL);

  wrefresh (win);
  while (quit) {
    c = wgetch (stdscr);
    switch (c) {
    case KEY_DOWN:
      gmenu_driver (menu, REQ_DOWN);
      break;
    case KEY_UP:
      gmenu_driver (menu, REQ_UP);
      break;
    case 9:    /* TAB */
      if (sort->sort == SORT_ASC) {
        /* ascending */
        sort->sort = SORT_DESC;
        mvwprintw (win, SORT_WIN_H - 2, 1, " %s", SORT_DESC_SEL);
      } else {
        /* descending */
        sort->sort = SORT_ASC;
        mvwprintw (win, SORT_WIN_H - 2, 1, " %s", SORT_ASC_SEL);
      }
      break;
    case 32:
    case 0x0a:
    case 0x0d:
    case KEY_ENTER:
      gmenu_driver (menu, REQ_SEL);
      for (i = 0; i < n; ++i) {
        if (menu->items[i].checked != 1)
          continue;
        if (strcmp ("Hits", menu->items[i].name) == 0)
          sort->field = SORT_BY_HITS;
        else if (strcmp ("Visitors", menu->items[i].name) == 0)
          sort->field = SORT_BY_VISITORS;
        else if (strcmp ("Data", menu->items[i].name) == 0)
          sort->field = SORT_BY_DATA;
        else if (strcmp ("Bandwidth", menu->items[i].name) == 0)
          sort->field = SORT_BY_BW;
        else if (strcmp ("Avg. Time Served", menu->items[i].name) == 0)
          sort->field = SORT_BY_AVGTS;
        else if (strcmp ("Cum. Time Served", menu->items[i].name) == 0)
          sort->field = SORT_BY_CUMTS;
        else if (strcmp ("Max. Time Served", menu->items[i].name) == 0)
          sort->field = SORT_BY_MAXTS;
        else if (strcmp ("Protocol", menu->items[i].name) == 0)
          sort->field = SORT_BY_PROT;
        else if (strcmp ("Method", menu->items[i].name) == 0)
          sort->field = SORT_BY_MTHD;
        quit = 0;
        break;
      }
      break;
    case KEY_RESIZE:
    case 'q':
      quit = 0;
      break;
    }
    wrefresh (win);
  }

  /* clean stuff up */
  for (i = 0; i < n; ++i)
    free (menu->items[i].name);
  free (menu->items);
  free (menu);

  touchwin (main_win);
  close_win (win);
  wrefresh (main_win);
}
示例#20
0
// this is where the magic happens
int main(int argc, const char *argv[]) {
  WINDOW *menu_win;
  node_t *curr;
  int len, ch, count, highlight = 1;
  char directions[] = "Use arrow keys to navigate, press enter to select";
  char insert_msg[] = "Enter the element you'd like to insert: ";
  char remove_msg[] = "Enter the element you'd like to remove: ";
  char count_msg[]  = "Enter the element you'd like to count: ";

  // create a new node list
  list_t *node_list = new_list();

  // initialize the ncurses session
  initscr();
  clear();
  noecho();
  cbreak();
  curs_set(0);
  getmaxyx(stdscr, stdscr_rows, stdscr_cols);
  mvprintw(2, 2, "%s", directions);

  // initialize the menu window
  menu_win = newwin(10, 50, ((stdscr_rows-10)/2), ((stdscr_cols-50)/2));
  getmaxyx(menu_win, menu_win_rows, menu_win_cols);
  keypad(menu_win, TRUE);
  print_menu(menu_win, highlight);
  refresh();

  // enter continuous loop to let user use the menu
  while (1) {
    switch(ch = wgetch(menu_win)) {
      case KEY_UP:
        if (highlight == 1)
          highlight = n_choices;
        else
          --highlight;
        break;
      case KEY_DOWN:
        if (highlight == n_choices)
          highlight = 1;
        else
          ++highlight;
        break;
      case 10:
        switch (highlight) {
          case 1: /* print */
            if (node_list->len) {
              len = node_list->len;
              curr = node_list->head->next;
              mvprintw(stdscr_rows - 2, 2, "List elements:");
              clrtoeol();
              while (len--) {
                printw(" %d", curr->val);
                curr = curr->next;
              }
            } else {
              mvprintw(stdscr_rows - 2, 2, "The list is empty");
              clrtoeol();
            }
            break;
          case 2: /* insert one */
            list_insert(node_list, new_node(get_input(insert_msg)));
            mvprintw(stdscr_rows - 2, 2, "Element Inserted!");
            clrtoeol();
            break;
          case 3: /* remove one */
            curr = list_find(node_list, get_input(remove_msg));

            if (curr) {
              list_remove(node_list, curr);
              mvprintw(stdscr_rows - 2, 2, "Element Removed!");
            } else {
              mvprintw(stdscr_rows - 2, 2, "Element Not Found!");
            }

            clrtoeol();
            break;
          case 4: /* remove each */
            curr = list_find(node_list, get_input(remove_msg));

            if (curr) {
              list_remove_each(node_list, curr);
              mvprintw(stdscr_rows - 2, 2, "All Matching Elements Removed!");
            } else {
              mvprintw(stdscr_rows - 2, 2, "Element Not Found!");
            }

            clrtoeol();
            break;
          case 5: /* remove all */
            list_remove_all(node_list);
            mvprintw(stdscr_rows - 2, 2, "All Elements Removed!");
            clrtoeol();
            break;
          case 6: /* count elements */
            mvprintw(stdscr_rows - 2, 2, "List length: %d", node_list->len);
            clrtoeol();
            break;
          case 7: /* count occurrences */
            count = list_count_each(node_list, get_input(count_msg));
            mvprintw(stdscr_rows - 2, 2, "Occurrences: %d", count);
            clrtoeol();
            break;
          case 8: /* exit */
            list_destroy(node_list);
            endwin();
            return 0;
        }
    }

    print_menu(menu_win, highlight);
    refresh();
  }
} /* end main() */
示例#21
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;
}
示例#22
0
文件: prgbox.c 项目: asdlei00/freebsd
/*
 * Display a message box. Program will pause and display an "OK" button
 * if the parameter 'pause' is non-zero.
 */
int dialog_prgbox(unsigned char *title, const unsigned char *line, int height, int width, int pause, int use_shell)
{
  int i, x, y, key = 0;
  WINDOW *dialog;
  FILE *f;
  const unsigned char *name;
  unsigned char *s, buf[MAX_LEN];
  int status;

  if (height < 0 || width < 0) {
    endwin();
    fprintf(stderr, "\nAutosizing is impossible in dialog_prgbox().\n");
    exit(-1);
  }
  width = MAX(width,10);

  if (width > COLS)
	width = COLS;
  if (height > LINES)
	height = LINES;
  /* center dialog box on screen */
  x = DialogX ? DialogX : (COLS - width)/2;
  y = DialogY ? DialogY : (LINES - height)/2;

#ifdef HAVE_NCURSES
  if (use_shadow)
    draw_shadow(stdscr, y, x, height, width);
#endif
  dialog = newwin(height, width, y, x);
  if (dialog == NULL) {
    endwin();
    fprintf(stderr, "\nnewwin(%d,%d,%d,%d) failed, maybe wrong dims\n", height,width,y,x);
    exit(1);
  }
  keypad(dialog, TRUE);

  draw_box(dialog, 0, 0, height, width, dialog_attr, border_attr);

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

  if (!use_shell) {
    char cmdline[MAX_LEN];
    char *av[51], **ap = av, *val, *p;

    strcpy(cmdline, line);
    p = cmdline;
    while ((val = strsep(&p," \t")) != NULL) {
      if (*val != '\0')
	*ap++ = val;
    }
    *ap = NULL;
    f = raw_popen(name = av[0], av, "r");
  } else
    f = raw_popen(name = line, NULL, "r");

  status = -1;
  if (f == NULL) {
  err:
      sprintf(buf, "%s: %s\n", name, strerror(errno));
  prr:
      print_autowrap(dialog, buf, height-(pause?3:1), width-2, width, 1, 2, FALSE, TRUE);
      wrefresh(dialog);
  } else {
    while (fgets(buf, sizeof(buf), f) != NULL) {
      i = strlen(buf);
      if (buf[i-1] == '\n')
	buf[i-1] = '\0';
      s = buf;
      while ((s = strchr(s, '\t')) != NULL)
	*s++ = ' ';
      print_autowrap(dialog, buf, height-(pause?3:1), width-2, width, 1, 2, FALSE, TRUE);
      print_autowrap(dialog, "\n", height-(pause?3:1), width-2, width, 1, 2, FALSE, FALSE);
      wrefresh(dialog);
    }
    if ((status = raw_pclose(f)) == -1)
      goto err;
    if (WIFEXITED(status) && WEXITSTATUS(status) == 127) {
      sprintf(buf, "%s: program not found\n", name);
      goto prr;
    }
  }

  if (pause) {
    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, ' ');
    display_helpline(dialog, height-1, width);
    print_button(dialog, "  OK  ", height-2, width/2-6, TRUE);
    wrefresh(dialog);
    while (key != ESC && key != '\n' && key != ' ' && key != '\r')
      key = wgetch(dialog);
    if (key == '\r')
      key = '\n';
  }
  else {
    key = '\n';
    wrefresh(dialog);
  }

  delwin(dialog);
  return (status);
}
示例#23
0
/* render config log date/format dialog */
int
render_confdlg (GLog * logger, GSpinner * spinner)
{
  GMenu *menu;
  WINDOW *win;

  char *cstm_log, *cstm_date, *cstm_time;
  int c, quit = 1, invalid = 1, y, x, h = CONF_WIN_H, w = CONF_WIN_W;
  int w2 = w - 2;
  size_t i, n, sel;

  /* conf dialog menu options */
  const char *choices[] = {
    "NCSA Combined Log Format",
    "NCSA Combined Log Format with Virtual Host",
    "Common Log Format (CLF)",
    "Common Log Format (CLF) with Virtual Host",
    "W3C",
    "Squid Native Format",
    "CloudFront (Download Distribution)",
    "Google Cloud Storage",
    "AWS Elastic Load Balancing (HTTP/S)"
  };
  n = ARRAY_SIZE (choices);
  getmaxyx (stdscr, y, x);

  win = newwin (h, w, (y - h) / 2, (x - w) / 2);
  keypad (win, TRUE);
  wborder (win, '|', '|', '-', '-', '+', '+', '+', '+');

  /* create a new instance of GMenu and make it selectable */
  menu = new_gmenu (win, CONF_MENU_H, CONF_MENU_W, CONF_MENU_Y, CONF_MENU_X);
  menu->size = n;
  menu->selectable = 1;

  /* add items to GMenu */
  menu->items = (GItem *) xcalloc (n, sizeof (GItem));
  for (i = 0; i < n; ++i) {
    menu->items[i].name = alloc_string (choices[i]);
    sel = get_selected_format_idx ();
    menu->items[i].checked = sel == i ? 1 : 0;
  }
  post_gmenu (menu);

  draw_header (win, "Log Format Configuration", " %s", 1, 1, w2,
               color_panel_header);
  mvwprintw (win, 2, 2, "[SPACE] to toggle - [ENTER] to proceed");

  /* set log format from goaccessrc if available */
  draw_header (win, "Log Format - [c] to add/edit format", " %s", 11, 1, w2,
               color_panel_header);
  if (conf.log_format) {
    log_format = escape_str (conf.log_format);
    mvwprintw (win, 12, 2, "%.*s", CONF_MENU_W, log_format);
    if (conf.log_format)
      free (conf.log_format);
  }

  /* set date format from goaccessrc if available */
  draw_header (win, "Date Format - [d] to add/edit format", " %s", 14, 1, w2,
               color_panel_header);
  if (conf.date_format) {
    date_format = escape_str (conf.date_format);
    mvwprintw (win, 15, 2, "%.*s", CONF_MENU_W, date_format);
    if (conf.date_format)
      free (conf.date_format);
  }

  /* set time format from goaccessrc if available */
  draw_header (win, "Time Format - [t] to add/edit format", " %s", 17, 1, w2,
               color_panel_header);
  if (conf.time_format) {
    time_format = escape_str (conf.time_format);
    mvwprintw (win, 18, 2, "%.*s", CONF_MENU_W, time_format);
    if (conf.time_format)
      free (conf.time_format);
  }

  wrefresh (win);
  while (quit) {
    c = wgetch (stdscr);
    switch (c) {
    case KEY_DOWN:
      gmenu_driver (menu, REQ_DOWN);
      clear_confdlg_status_bar (win, 3, 2, CONF_MENU_W);
      break;
    case KEY_UP:
      gmenu_driver (menu, REQ_UP);
      clear_confdlg_status_bar (win, 3, 2, CONF_MENU_W);
      break;
    case 32:   /* space */
      gmenu_driver (menu, REQ_SEL);
      clear_confdlg_status_bar (win, 12, 1, CONF_MENU_W);
      clear_confdlg_status_bar (win, 15, 1, CONF_MENU_W);
      clear_confdlg_status_bar (win, 18, 1, CONF_MENU_W);

      if (time_format)
        free (time_format);
      if (date_format)
        free (date_format);
      if (log_format)
        free (log_format);

      for (i = 0; i < n; ++i) {
        if (menu->items[i].checked != 1)
          continue;

        date_format = get_selected_date_str (i);
        log_format = get_selected_format_str (i);
        time_format = get_selected_time_str (i);

        mvwprintw (win, 12, 1, " %s", log_format);
        mvwprintw (win, 15, 1, " %s", date_format);
        mvwprintw (win, 18, 1, " %s", time_format);
        break;
      }
      break;
    case 99:   /* c */
      /* clear top status bar */
      clear_confdlg_status_bar (win, 3, 2, CONF_MENU_W);
      wmove (win, 12, 2);

      /* get input string */
      cstm_log = input_string (win, 12, 2, 70, log_format, 0, 0);
      if (cstm_log != NULL && *cstm_log != '\0') {
        if (log_format)
          free (log_format);

        log_format = alloc_string (cstm_log);
        free (cstm_log);
      }
      /* did not set an input string */
      else {
        if (cstm_log)
          free (cstm_log);
        if (log_format) {
          free (log_format);
          log_format = NULL;
        }
      }
      break;
    case 100:  /* d */
      /* clear top status bar */
      clear_confdlg_status_bar (win, 3, 2, CONF_MENU_W);
      wmove (win, 15, 0);

      /* get input string */
      cstm_date = input_string (win, 15, 2, 14, date_format, 0, 0);
      if (cstm_date != NULL && *cstm_date != '\0') {
        if (date_format)
          free (date_format);

        date_format = alloc_string (cstm_date);
        free (cstm_date);
      }
      /* did not set an input string */
      else {
        if (cstm_date)
          free (cstm_date);
        if (date_format) {
          free (date_format);
          date_format = NULL;
        }
      }
      break;
    case 116:  /* t */
      /* clear top status bar */
      clear_confdlg_status_bar (win, 3, 2, CONF_MENU_W);
      wmove (win, 15, 0);

      /* get input string */
      cstm_time = input_string (win, 18, 2, 14, time_format, 0, 0);
      if (cstm_time != NULL && *cstm_time != '\0') {
        if (time_format)
          free (time_format);

        time_format = alloc_string (cstm_time);
        free (cstm_time);
      }
      /* did not set an input string */
      else {
        if (cstm_time)
          free (cstm_time);
        if (time_format) {
          free (time_format);
          time_format = NULL;
        }
      }
      break;
    case 274:  /* F10 */
    case 0x0a:
    case 0x0d:
    case KEY_ENTER:
      /* display status bar error messages */
      if (time_format == NULL)
        draw_header (win, "Select a time format.", " %s", 3, 2, CONF_MENU_W,
                     color_error);
      if (date_format == NULL)
        draw_header (win, "Select a date format.", " %s", 3, 2, CONF_MENU_W,
                     color_error);
      if (log_format == NULL)
        draw_header (win, "Select a log format.", " %s", 3, 2, CONF_MENU_W,
                     color_error);

      if (date_format && log_format && time_format) {
        conf.time_format = unescape_str (time_format);
        conf.date_format = unescape_str (date_format);
        conf.log_format = unescape_str (log_format);

        /* test log against selected settings */
        if (test_format (logger)) {
          invalid = 1;
          draw_header (win, "No valid hits.", " %s", 3, 2, CONF_MENU_W,
                       color_error);

          free (conf.log_format);
          free (conf.date_format);
          free (conf.time_format);
        }
        /* valid data, reset logger & start parsing */
        else {
          reset_struct (logger);
          /* start spinner thread */
          spinner->win = win;
          spinner->y = 3;
          spinner->x = 2;
          spinner->spin_x = CONF_MENU_W;
          spinner->w = CONF_MENU_W;
          spinner->color = color_progress;
          ui_spinner_create (spinner);

          invalid = 0;
          quit = 0;
        }
      }
      break;
    case KEY_RESIZE:
    case 'q':
      quit = 0;
      break;
    }
    pthread_mutex_lock (&spinner->mutex);
    wrefresh (win);
    pthread_mutex_unlock (&spinner->mutex);
  }
  /* clean stuff up */
  for (i = 0; i < n; ++i)
    free (menu->items[i].name);
  free (menu->items);
  free (menu);

  return invalid ? 1 : 0;
}
示例#24
0
menu_item_t *menu_wait(menu_t *menu, int timeout)
{
    int c;
    menu_item_t *ret = NULL;
    assert(menu && menu == _libmenu_menus_l);

    /* Création de la fenêtre si nécessaire */
    if(!_libmenu_window)
    {
        _libmenu_window = newwin(menu->win_h, menu->win_w,
                menu->win_y, menu->win_x);
        keypad(_libmenu_window, TRUE);
        /* Va au premier élément sélectionnable */
        menu->item = _libmenu_selectable_item_after(menu, -1);
        _libmenu_invalid = 1;
    }

    if(_libmenu_invalid)
    {
        _libmenu_drawmenu();
        _libmenu_invalid = 0;
    }

    if(timeout >= 0)
        halfdelay(timeout/100);
    else
        cbreak();
    c = wgetch(_libmenu_window);
    switch(c)
    {
    case KEY_UP:
        menu->item = _libmenu_selectable_item_before(menu, menu->item);
        /* Scrolling */
        if(menu->item != -1 && menu->item < menu->scroll_pos)
            menu->scroll_pos = menu->item;
        _libmenu_drawmenu();
        break;
    case KEY_DOWN:
        menu->item = _libmenu_selectable_item_after(menu, menu->item);
        /* Scrolling */
        if(menu->item >= menu->scroll_pos + menu->win_h-2)
            menu->item = menu->scroll_pos + menu->win_h - 3;
        _libmenu_drawmenu();
        break;
    /* TODO : saut des items non-sélectionnables */
    case 10:
        {
            menu_item_t *i = _libmenu_item_n(menu->items_f, menu->item);
            if(i->type != MENU_ITEM_LABEL)
                return i;
        }
        break;
    case 'q':
    case 'Q':
        ret = MENU_QUIT;
        break;
    }

    nocbreak();
    return ret;
}
示例#25
0
/********************************************************\
 * Description: outputs key command help                *
 * Returns:     none                                    *
\********************************************************/
void printHelp(WINS *win)
{
    WINDOW *ctrl, *help, *small;

    ctrl = newwin(LINES - 2, 9, 1, 1),
    help = newwin(LINES - 2, hex_win_width, 1, 10),
    small = newwin(LINES - 2, ascii_win_width, 1, hex_outline_width + 2);
    
    if ((LINES < 18) || (COLS < 78))			/* min size to display*/
    {
	mvwprintw(help, 0, 0, "Screen too small to display help");
	wmove(help,0,0);
    }
    else
    {
	wmove(ctrl,0,0);
	mvwprintw(ctrl, 0, 1, "Ctrl Key");		/* print in address   */
	mvwprintw(ctrl, 2, 1, "CTRL+?");
	mvwprintw(ctrl, 3, 1, "CTRL+S");
	mvwprintw(ctrl, 4, 1, "CTRL+O");
	mvwprintw(ctrl, 5, 1, "CTRL+G");
	mvwprintw(ctrl, 6, 1, "CTRL+F");
	mvwprintw(ctrl, 7, 1, "CTRL+A");
	mvwprintw(ctrl, 8, 1, "TAB");
	mvwprintw(ctrl, 9, 1, "CTRL+Q");
	mvwprintw(ctrl, 11, 1, "CTRL+U");
	mvwprintw(ctrl, 12, 1, "CTRL+D");
	mvwprintw(ctrl, 13, 1, "CTRL+Z");
	mvwprintw(ctrl, 14, 1, "CTRL+T");
	mvwprintw(ctrl, 15, 1, "CTRL+B");

	mvwprintw(small, 0, 1, "Function Keys");	/* print in ascii     */
	mvwprintw(small, 2, 1, "Help     = F1");
	mvwprintw(small, 3, 1, "Save     = F2");
	mvwprintw(small, 4, 1, "Open     = F3");
	mvwprintw(small, 5, 1, "Goto     = F4");
	mvwprintw(small, 6, 1, "Find     = F5");
	mvwprintw(small, 7, 1, "HexAdres = F6");
	mvwprintw(small, 8, 1, "Hex Edit = F7");
	mvwprintw(small, 9, 1, "Quit     = F8");
	mvwprintw(small, 11, 1, "Page up  = PGUP");
	mvwprintw(small, 12, 1, "Page down= PGDN");

	mvwprintw(help, 0, 10, "HexCurse Keyboard Commands");
	mvwprintw(help, 2, 2, "Help     - you are reading it now");
	mvwprintw(help, 3, 2, "Save     - saves the current file open");
	mvwprintw(help, 4, 2, "Open     - opens a new file");
	mvwprintw(help, 5, 2, "Goto     - goto a specified address");
	mvwprintw(help, 6, 2, "Find     - search for a hex/ascii value");
	mvwprintw(help, 7, 2, "HexAdres - toggle between hex/decimal address");
	mvwprintw(help, 8, 2, "Hex Edit - toggle between hex/ASCII windows");
	mvwprintw(help, 9, 2, "Quit     - exit out of the program");
	mvwprintw(help, 11, 2, "Page up  - scrolls one screen up");
	mvwprintw(help, 12, 2, "Page down- scrolls one screen down");
	mvwprintw(help, 13, 2, "Undo     - reverts last modification");
	mvwprintw(help, 14, 2, "Home     - returns to the top of the file");
	mvwprintw(help, 15, 2, "End      - jumps to the bottom of the file");
	mvwprintw(help, 17, 12, "Press enter to continue");
    }

    wnoutrefresh(ctrl);					/* refresh new wins   */
    wnoutrefresh(help);
    wnoutrefresh(small);
    doupdate();						/* update screen      */

    wgetch(ctrl);					/* wait for a char    */

    delwin(ctrl);					/* delete help wins   */
    delwin(help);
    delwin(small);

    redrawwin(win->hex);				/* redraw previous    */
    redrawwin(win->ascii);
    redrawwin(win->address);

    wnoutrefresh(win->hex);				/* refresh            */
    wnoutrefresh(win->ascii);
    wnoutrefresh(win->address);
    doupdate();						/* update screen      */

}
示例#26
0
bool handleInput(int sock, struct addrinfo * p) {
    int charRead;
    while(true)  {
		if(timeForKeepAlive) {
			sendKeepAlivePacket(sock, p);
			timeForKeepAlive = false;
		}
		handleNetwork(sock, p);
        charRead = wgetch(inputWnd);        
        if(charRead == 127 && nchars > 0) {
            int cy, cx;
            getyx(inputWnd, cy, cx);
            mvwaddch(inputWnd, cy, cx-1, ' ');
			wmove(inputWnd, cy, cx-1);
            line[nchars] = '\0';
            --nchars;
            return true;
        } else if(charRead >= 32 && charRead <= 126 && nchars < MAXLINE) {
            wechochar(inputWnd, charRead);
            line[nchars] = charRead;
            refreshAll();
            ++nchars;
            return true;
        } else if(charRead == '\n') {
            if(strncmp(line, "/exit", std::max(nchars, MAXLINE+1)) == 0) {
                return false;
            } else if(strncmp(line, "/join ", 6) == 0) {
                sendJoinPacket(sock, p, &(line[6]));
				memset(curChannel, '\0', CHANNEL_MAX+1);
				strncpy(curChannel, &(line[6]), CHANNEL_MAX);
				channelsJoined.insert(curChannel);
			} else if(strncmp(line, "/switch ", 8) == 0) {
				char chanName[CHANNEL_MAX+1];
				memset(chanName, '\0', CHANNEL_MAX+1);
				strncpy(chanName, &(line[8]), CHANNEL_MAX);
				if(channelsJoined.count(chanName) > 0) {
					strncpy(curChannel, chanName, CHANNEL_MAX);
				} else {
					char err[256];
					snprintf(err, 256, "you have not subscribed to channel %.32s", chanName);
					printErrorMsg(err);
				}
            } else if(strncmp(line, "/leave ", 7) == 0) {
                sendLeavePacket(sock, p, &(line[7]));
				memset(curChannel, '\0', CHANNEL_MAX+1);
				strncpy(curChannel, &(line[7]), CHANNEL_MAX);
				channelsJoined.erase(curChannel);
				memset(curChannel, '\0', CHANNEL_MAX);
			} else if(strncmp(line, "/list", 5) == 0) {
				sendListPacket(sock, p);
			} else if(strncmp(line, "/who ", 5) == 0) {
				sendWhoPacket(sock, p, &(line[5]));
            } else if(line[0] == '/') {
				printErrorMsg("unrecognized command");
			} else if(curChannel[0] != '\0'){
				sendSayPacket(sock, p, curChannel, line);
			}
            //wprintw(wnd, "%s\n", line);
            memset(line, '\0', MAXLINE+1);
            clearInput();
            return true;
        }
    };
}
示例#27
0
int start_ncurses(const char *prog_name, const char *real_prog_name)
{
#if defined(DJGPP) || defined(__MINGW32__)
  if(initscr()==NULL)
  {
    log_critical("initscr() has failed. Exiting\n");
    printf("initscr() has failed. Exiting\n");
    printf("Press Enter key to quit.\n");
    (void)getchar();
    return 1;
  }
#else
  get_newterm(real_prog_name);
  if(screenp==NULL)
  {
    log_critical("Terminfo file is missing.\n");
#if defined(__CYGWIN__)
    printf("The terminfo file '63\\cygwin' is missing.\n");
#else
    printf("Terminfo file is missing.\n");
#endif
    printf("Extract all files and subdirectories before running the program.\n");
    printf("Press Enter key to quit.\n");
    (void)getchar();
    return 1;
  }
#endif
  /* Should solve a problem with users who redefined the colors */
  if(has_colors())
  {
    start_color();
#ifdef HAVE_ASSUME_DEFAULT_COLORS
    assume_default_colors(COLOR_WHITE,COLOR_BLACK);
#endif
    init_pair(1, COLOR_RED, COLOR_BLACK);
    init_pair(2, COLOR_GREEN, COLOR_BLACK);
  }
  noecho();
#ifndef DJGPP
  nonl(); /*don't use for Dos version but enter will work with it... dilema */
#endif
  /*  intrflush(stdscr, FALSE); */
  cbreak();
  curs_set(0);
  {
    int quit=0;
    while(LINES>=8 && LINES<MINIMUM_LINES && quit==0)
    {
      aff_copy(stdscr);
      wmove(stdscr,4,0);
      wprintw(stdscr,"%s need %d lines to work.", prog_name, MINIMUM_LINES);
      wmove(stdscr,5,0);
      wprintw(stdscr,"Please enlarge the terminal.");
      wmove(stdscr,LINES-2,0);
      wattrset(stdscr, A_REVERSE);
      waddstr(stdscr,"[ Quit ]");
      wattroff(stdscr, A_REVERSE);
      wrefresh(stdscr);
      switch(wgetch(stdscr))
      {
	case 'q':
	case 'Q':
	case KEY_ENTER:
#ifdef PADENTER
	case PADENTER:
#endif
	case '\n':
	case '\r':
	  quit=1;
	  break;
      }
    }
  }
  if(LINES < MINIMUM_LINES)
  {
    end_ncurses();
    printf("%s need %d lines to work.\nPlease enlarge the terminal and restart %s.\n", prog_name, MINIMUM_LINES, prog_name);
    log_critical("Terminal has only %d lines\n",LINES);
    return 1;
  }
  return 0;
}
示例#28
0
int main(int argc, char *argv[])
{
    WINDOW *p;
    FILE *f;
    int ch;
    initscr();
    savetty();
    noecho();//disable auto-echoing
    cbreak();//making getch() work without a buffer I.E. raw characters
    keypad(stdscr,TRUE);//allows use of special keys, namely the arrow keys
    clear();    // empty the screen
    timeout(0);
    
    /* create a new pad */
    p = newpad(WIDE,COLS);
    keypad(p, TRUE);
    if( p == NULL )
        printf("Unable to create new pad\n");
    
    load_file(p, f, argv[1]); // open and load the file on the screen
    
    
    /* display the pad’s contents on the screen */
    prefresh(p,0, 0, 0,0, LINES-1,COLS-1);
    int c, cursorY=0, cursorX=0, linseCount = 0;
    while((c=wgetch(p))!='q'){
        switch(c){
            case KEY_LEFT:
                if(cursorX != 0)
                    cursorX--;
                break;
            case KEY_RIGHT:
                if (cursorX != COLS-1)
                    cursorX++;
                break;
            case KEY_UP:
                if(cursorY==0  && linseCount==0)
                    break;
                else if(cursorY == linseCount){
                    cursorY--;
                    linseCount--;
                    prefresh(p,linseCount, 0, 0,0, LINES-1,COLS-1);
                }
                else
                    cursorY--;
                break;
            case KEY_DOWN:
                if(cursorY==LINES-1  && linseCount==WIDE-1)
                    break;
                else if(cursorY == linseCount+LINES-1){
                    cursorY++;
                    linseCount++;
                    prefresh(p,linseCount, 0, 0,0, LINES-1,COLS-1);
                }
                else
                    cursorY++;
                break;
        }
        wmove(p,cursorY,cursorX);
        prefresh(p,linseCount, 0, 0,0, LINES-1,COLS-1);
    }
    endwin();
    return 0;
}
示例#29
0
int get_string(WINDOW *window, char *str, const int len, const char *def)
{
  int c;
  int i = 0;
  int x, y;
  int use_def = FALSE;
  curs_set(1);
  getyx(window, y, x);
  str[0] = 0;

  if (def != NULL) {
    mvwaddstr(window,y, x, def);
    wmove(window,y, x);
    use_def = TRUE;
  }

  wrefresh(window);
  while ((c = wgetch(window)) != '\n' && c != key_CR
#ifdef PADENTER
      && c!= PADENTER
#endif
      )
  {
    switch (c) {
      /* escape is generated by enter from keypad */
      /*
	 case key_ESC:
	 wmove(window,y, x);
	 wclrtoeol(window);
	 curs_set(0);
	 wrefresh(window);
	 return GS_key_ESCAPE;
	 */
      case KEY_DC:
      case KEY_BACKSPACE:
	if (i > 0) {
	  str[--i] = 0;
	  mvwaddch(window, y, x+i, ' ');
	  wmove(window,y, x+i);
	} else if (use_def) {
	  wclrtoeol(window);
	  use_def = FALSE;
	}
	break;
      default:
	if (i < len && isprint(c)) {
	  mvwaddch(window, y, x+i, c);
	  if (use_def) {
	    wclrtoeol(window);
	    use_def = FALSE;
	  }
	  str[i++] = c;
	  str[i] = 0;
	}
    }
    wrefresh(window);
  }
  curs_set(0);
  wrefresh(window);
  if (use_def)
    return GS_DEFAULT;
  else
    return i;
}
示例#30
0
int
call_list_help(PANEL *panel)
{
    WINDOW *help_win;
    int height, width;

    // Create a new panel and show centered
    height = 28;
    width = 65;
    help_win = newwin(height, width, (LINES - height) / 2, (COLS - width) / 2);

    // Set the window title
    mvwprintw(help_win, 1, 25, "Call List Help");

    // Write border and boxes around the window
    wattron(help_win, COLOR_PAIR(CP_BLUE_ON_DEF));
    box(help_win, 0, 0);
    mvwhline(help_win, 2, 1, ACS_HLINE, width - 2);
    mvwhline(help_win, 7, 1, ACS_HLINE, width - 2);
    mvwhline(help_win, height - 3, 1, ACS_HLINE, width - 2);
    mvwaddch(help_win, 2, 0, ACS_LTEE);
    mvwaddch(help_win, 7, 0, ACS_LTEE);
    mvwaddch(help_win, height - 3, 0, ACS_LTEE);
    mvwaddch(help_win, 2, 64, ACS_RTEE);
    mvwaddch(help_win, 7, 64, ACS_RTEE);
    mvwaddch(help_win, height - 3, 64, ACS_RTEE);

    // Set the window footer (nice blue?)
    mvwprintw(help_win, height - 2, 20, "Press any key to continue");

    // Some brief explanation abotu what window shows
    wattron(help_win, COLOR_PAIR(CP_CYAN_ON_DEF));
    mvwprintw(help_win, 3, 2, "This windows show the list of parsed calls from a pcap file ");
    mvwprintw(help_win, 4, 2, "(Offline) or a live capture with libpcap functions (Online).");
    mvwprintw(help_win, 5, 2, "You can configure the columns shown in this screen and some");
    mvwprintw(help_win, 6, 2, "static filters using sngreprc resource file.");
    wattroff(help_win, COLOR_PAIR(CP_CYAN_ON_DEF));

    // A list of available keys in this window
    mvwprintw(help_win, 8, 2, "Available keys:");
    mvwprintw(help_win, 10, 2, "Esc/Q       Exit sngrep.");
    mvwprintw(help_win, 11, 2, "Enter       Show selected calls message flow");
    mvwprintw(help_win, 12, 2, "Space       Select call");
    mvwprintw(help_win, 13, 2, "F1/h        Show this screen");
    mvwprintw(help_win, 14, 2, "F2/S        Save captured packages to a file");
    mvwprintw(help_win, 15, 2, "F3//        Display filtering (match string case insensitive)");
    mvwprintw(help_win, 16, 2, "F4/X        Show selected call-flow (Extended) if available");
    mvwprintw(help_win, 17, 2, "F5          Clear call list (can not be undone!)");
    mvwprintw(help_win, 18, 2, "F6/R        Show selected call messages in raw mode");
    mvwprintw(help_win, 19, 2, "F7/F        Show filter options");
    mvwprintw(help_win, 20, 2, "F8/c        Turn on/off window colours");
    mvwprintw(help_win, 21, 2, "F9/l        Turn on/off resolved addresses");
    mvwprintw(help_win, 22, 2, "F10/t       Select displayed columns");
    mvwprintw(help_win, 23, 2, "i/I         Set display filter to invite");
    mvwprintw(help_win, 24, 2, "p           Stop/Resume packet capture");

    // Press any key to close
    wgetch(help_win);
    delwin(help_win);

    return 0;
}