Exemplo n.º 1
0
/*
 * Page the other window. Check to make sure it exists, then
 * nextwind, forwpage and restore window pointers.
 */
int
pagenext(int f, int n)
{
	struct mgwin *wp;

	if (wheadp->w_wndp == NULL) {
		ewprintf("No other window");
		return (FALSE);
	}
	wp = curwp;
	(void) nextwind(f, n);
	(void) forwpage(f, n);
	curwp = wp;
	curbp = wp->w_bufp;
	return (TRUE);
}
Exemplo n.º 2
0
int buffermenu(int f, int n)
{
  BUFFER *bp;
  BUFFER *org_bp = curbp;
  int c,k;
  int bufptr;
  int bufcount = 0;

  bufptr = 1;

 start:
  listbuffers(f,n);
  swbuffer(blistp);
  onlywind(0,0);
  bufcount = count_buffers();

  if (bufptr > bufcount)
	bufptr = bufcount;

  if (bufcount > 0)
	forwline(0, bufptr + 1);
  else
	forwline(0, 2);

  for (;;) {
	mlwrite("Buffer Menu: 1,2,s,v,k,q ");
	update();
	c = ttgetc();

	/* if no buffers, only allow exit */
	if (bufcount == 0) {
	  switch (c) {
	  case 'q': case 'Q': case 'x': case 'X':
		break;
	  default:
		(*term.t_beep) ();
		continue;
	  }
	}

	/*
	 * pre process escape sequence to get up/down arrows
	 * convert to CTRL+N, CTRL+P 
	 */
	if (c == ESC) {
	  k = getctl();
	  if (k == '[') {
		k = getctl();
		switch(k) {
		case 'A': c = CTRL_P; break;
		case 'B': c = CTRL_N; break;
		default: 
		  (*term.t_beep)();
		  continue;
		}
	  } else {
		k = getctl();
		(*term.t_beep) ();
		continue;
	  }
	}  /* if ESC */

	switch (c) {
	case 'n':
	case 'N':
	case CTRL_N:
	  if (bufcount == bufptr) {
		(*term.t_beep) ();
		break;
	  }
	  forwline(0,1);
	  bufptr++;
	  break;

	case 'p':
	case 'P':
	case CTRL_P:
	  if (bufptr == 1) {
		(*term.t_beep) ();
		break;
	  }
	  backline(0,1);
	  bufptr--;
	  break;

	case '1':
	  bp = get_buffer(bufptr);
	  swbuffer(bp);
	  onlywind(0,0);
	  mlerase();
	  return TRUE;

	case '2':
	  bp = get_buffer(bufptr);
	  swbuffer(bp);
	  onlywind(0,0);
	  /* need to check or is still valid */
	  if (valid_buf(org_bp) == TRUE && bufcount > 1)
		{
		  splitwind(0,0);
		  swbuffer(org_bp);
		  nextwind(0,0);
		}
	  mlerase();
	  return TRUE;

	  /* save file */
	case 's':
	case 'S':
	  bp = get_buffer(bufptr);
	  if (bp != NULL) {
		curbp = bp;
		(void)filesave(0,0);
		curbp = blistp;
		goto start;
	  }
	  break;

	  /* toggle read only */
	case 'v':
	case 'V':
	case '%':
	  bp = get_buffer(bufptr);
	  if (bp != NULL)  /* be defensive */
		bp->b_flag ^= BFRO;
	  goto start;
	  break;

	  /* kill buffer */
	case 'k':
	case 'K':
	  bp = get_buffer(bufptr);
	  if (bp != NULL)
		zotbuf(bp);
	  goto start;
	  break;

	  /* exit buffer menu */
	case 'q':
	case 'Q':
	case 'x':
	case 'X':
	  if (bufcount == 0) {
		bp = get_scratch();
		swbuffer(bp);
		onlywind(0,0);
		mlerase();
		return TRUE;
	  }

	  if (valid_buf(org_bp) == TRUE)
		swbuffer(org_bp);
	  else
		swbuffer(bheadp);
	  onlywind(0,0);
	  mlerase();
	  return TRUE;

	  /* any other key */
	default:
	  (*term.t_beep) ();
	  break;
	}
  }

  mlerase();
  return TRUE;
}