Esempio n. 1
0
void close_ncurses() {
#ifdef HAVE_LIBNCURSESW
	sleep(3);
	attroff(COLOR_PAIR(3));
	delwin(log_win);
	delwin(p_win);
	delwin(bar_win);
	delwin(box_win);
	touchwin(ptclscr_win);
	endwin();
	delscreen (ptclscr);
#endif
}
Esempio n. 2
0
void
cleanup(void)
{
    if (ttyclock->ttyscr)
        delscreen(ttyclock->ttyscr);

    if (ttyclock && ttyclock->tty)
        free(ttyclock->tty);
    if (ttyclock && ttyclock->option.format)
        free(ttyclock->option.format);
    if (ttyclock)
        free(ttyclock);
}
Esempio n. 3
0
_nc_freeall(void)
{
    WINDOWLIST *p, *q;
    static va_list empty_va;

    T((T_CALLED("_nc_freeall()")));
#if NO_LEAKS
    if (SP != 0) {
	if (SP->_oldnum_list != 0) {
	    FreeAndNull(SP->_oldnum_list);
	}
	if (SP->_panelHook.destroy != 0) {
	    SP->_panelHook.destroy(SP->_panelHook.stdscr_pseudo_panel);
	}
    }
#endif
    if (SP != 0) {
	_nc_lock_global(curses);

	while (_nc_windows != 0) {
	    bool deleted = FALSE;

	    /* Delete only windows that're not a parent */
	    for (each_window(p)) {
		bool found = FALSE;

		for (each_window(q)) {
		    if ((p != q)
			&& (q->win._flags & _SUBWIN)
			&& (&(p->win) == q->win._parent)) {
			found = TRUE;
			break;
		    }
		}

		if (!found) {
		    if (delwin(&(p->win)) != ERR)
			deleted = TRUE;
		    break;
		}
	    }

	    /*
	     * Don't continue to loop if the list is trashed.
	     */
	    if (!deleted)
		break;
	}
	delscreen(SP);
	_nc_unlock_global(curses);
    }
Esempio n. 4
0
/*
 * Cleans up resources and calls pg_free on s
 */
void
ScreenDestroy(Screen *s)
{
	/* resets the tty to original state */
	endwin();

	/* ncurses resource cleanup */
	delscreen(s->nterm);

	fclose(s->term_in);
	RowCleanup(&s->key);

	memset(s, 0, sizeof(Screen));
	pg_free(s);
}
Esempio n. 5
0
int end_ncurses(void)
{
  wclear(stdscr);
  wrefresh(stdscr);
  nl();
  endwin();
#if defined(DJGPP) || defined(__MINGW32__)
#else
#ifdef HAVE_DELSCREEN
  if(screenp!=NULL)
    delscreen(screenp);
#endif
#endif
  return 0;
}
Esempio n. 6
0
int main(void)
{
	SCREEN *s;

	s = newterm(NULL, stdout, stdin);
	set_term(s);

	addstr("Hello!");

	refresh();
	getch();

	endwin();
	delscreen(s);
	return 0;
}
Esempio n. 7
0
/*
 * cl_vi_end --
 *	Shutdown the vi screen.
 */
static int
cl_vi_end(GS *gp)
{
	CL_PRIVATE *clp;

	clp = GCLP(gp);

	/* Restore the cursor keys to normal mode. */
	(void)keypad(stdscr, FALSE);

	/*
	 * If we were running vi when we quit, scroll the screen up a single
	 * line so we don't lose any information.
	 *
	 * Move to the bottom of the window (some endwin implementations don't
	 * do this for you).
	 */
	if (!F_ISSET(clp, CL_IN_EX) && !F_ISSET(gp, G_SRESTART)) {
		(void)move(0, 0);
		(void)deleteln();
		(void)move(LINES - 1, 0);
		(void)refresh();
	}

	cl_freecap(clp);

	/* End curses window. */
	(void)endwin();

	/* Delete curses screen. */
	delscreen(clp->screen);

	/*
	 * XXX
	 * The screen TE sequence just got sent.  See the comment in
	 * cl_funcs.c:cl_attr().
	 */
	clp->ti_te = TE_SENT;

	return (0);
}
Esempio n. 8
0
static int
_vdk_screen_dtor(vdk_object_t *object)
{
    vdk_raster_t    *raster;
    int             raster_type;
    int             retval;

    if(object == NULL) return -1;

    raster_type = vdk_object_get_raster_type(VDK_OBJECT(object));
    if(raster_type != VDK_RASTER_SCR) return -1;

    raster = VDK_RASTER(object);

    // in order to tear down the screen it must first be activated
    set_term(raster->primitive.screen);
    endwin();
    delscreen(raster->primitive.screen);

    // call the parent klass destructor
    retval = VDK_OBJECT(VDK_CONTEXT_KLASS)->dtor(object);

    return retval;
}
Esempio n. 9
0
/*f
 * Initialize XCurses for use with a single terminal.  stdin and stdout
 * are used.  If a program needs an indication of error conditions,
 * so that it can continue to run in a line-oriented mode, use newterm()
 * instead.
 */
WINDOW *
initscr()
{
	WINDOW *w;
	SCREEN *sp;
	int i, n, begy;
	char *term, *err;

#ifdef M_CURSES_TRACE
	__m_trace("initscr(void)");
#endif

	errno = 0;
 	sp = newterm((char *) 0, stdout, stdin);

	if (sp == (SCREEN *) 0) {
		err = errno == ENOMEM ? nomem_msg : noterm_msg;
		goto error_1;
	}

	(void) set_term(sp);

	/* We require some form of cursor positioning and the ability to
	 * clear the end of a line.  These abilities should be sufficient
	 * to provide minimum full screen support. 
	 */
	if (1 < lines
	&& cursor_address == (char *) 0 
	&& row_address == (char *) 0
	&& (cursor_up == (char *) 0 || cursor_down == (char *) 0)
	&& (parm_up_cursor == (char *) 0 || parm_down_cursor == (char *) 0)) {
		err = dumb_msg;
		goto error_3;
	}
	
	if ((1 < lines && cursor_address == (char *) 0)
	&& column_address == (char *) 0
	&& (cursor_left == (char *) 0 || cursor_right == (char *) 0)
	&& (parm_left_cursor == (char *) 0 || parm_right_cursor == (char *)0)) {
		err = dumb_msg;
		goto error_3;
	}

	if (clr_eol == (char *) 0) {
		err = dumb_msg;
		goto error_3;
	}

	return __m_return_pointer("initscr", stdscr);
error_3:
	(void) delwin(stdscr);
error_2:
	(void) endwin();
	(void) delscreen(sp);
error_1:
	/* newterm()/setupterm() attempts to load $TERM, else if
	 * $TERM is not defined, the vendor's default terminal type.
	 */
	if ((term = getenv("TERM")) == (char *) 0)
		term = M_TERM_NAME;

	(void) fprintf(stderr, m_strmsg(err), term);
error_0:
	exit(1);
	return (0);	/* keep gcc happy */
}
Esempio n. 10
0
_nc_freeall(void)
{
    WINDOWLIST *p, *q;
    char *s;

    T((T_CALLED("_nc_freeall()")));
#if NO_LEAKS
    _nc_free_tparm();
    if (_nc_oldnums != 0) {
	FreeAndNull(_nc_oldnums);
    }
#endif
    if (SP != 0) {
	while (_nc_windows != 0) {
	    /* Delete only windows that're not a parent */
	    for (p = _nc_windows; p != 0; p = p->next) {
		bool found = FALSE;

		for (q = _nc_windows; q != 0; q = q->next) {
		    if ((p != q)
			&& (q->win._flags & _SUBWIN)
			&& (&(p->win) == q->win._parent)) {
			found = TRUE;
			break;
		    }
		}

		if (!found) {
		    delwin(&(p->win));
		    break;
		}
	    }
	}
	delscreen(SP);
    }

    del_curterm(cur_term);
    _nc_free_entries(_nc_head);
    _nc_get_type(0);
    _nc_first_name(0);
#if USE_WIDEC_SUPPORT
    FreeIfNeeded(_nc_wacs);
#endif
#if NO_LEAKS
    _nc_alloc_entry_leaks();
    _nc_captoinfo_leaks();
    _nc_comp_scan_leaks();
#endif

    if ((s = _nc_home_terminfo()) != 0)
	free(s);

    (void) _nc_printf_string(0, 0);
#ifdef TRACE
    (void) _nc_trace_buf(-1, 0);
#endif

#if HAVE_LIBDBMALLOC
    malloc_dump(malloc_errfd);
#elif HAVE_LIBDMALLOC
#elif HAVE_LIBMPATROL
    __mp_summary();
#elif HAVE_PURIFY
    purify_all_inuse();
#endif
    returnVoid;
}
Esempio n. 11
0
static int
dialog_run (pinentry_t pinentry, const char *tty_name, const char *tty_type)
{
  struct dialog diag;
  FILE *ttyfi = NULL;
  FILE *ttyfo = NULL;
  SCREEN *screen = 0;
  int done = 0;
  char *pin_utf8;
  int alt = 0;
#ifndef HAVE_DOSISH_SYSTEM
  int no_input = 1;
#endif
#ifdef HAVE_NCURSESW
  char *old_ctype = NULL;

  if (pinentry->lc_ctype)
    {
      old_ctype = strdup (setlocale (LC_CTYPE, NULL));
      setlocale (LC_CTYPE, pinentry->lc_ctype);
    }
  else
    setlocale (LC_CTYPE, "");
#endif

  /* Open the desired terminal if necessary.  */
  if (tty_name)
    {
      ttyfi = fopen (tty_name, "r");
      if (!ttyfi)
        {
          pinentry->specific_err = ASSUAN_ENOENT;
          return -1;
        }
      ttyfo = fopen (tty_name, "w");
      if (!ttyfo)
	{
	  int err = errno;
	  fclose (ttyfi);
	  errno = err;
          pinentry->specific_err = ASSUAN_ENOENT;
	  return -1;
	}
      screen = newterm (tty_type, ttyfo, ttyfi);
      set_term (screen);
    }
  else
    {
      if (!init_screen)
	{
          if (!(isatty(fileno(stdin)) && isatty(fileno(stdout))))
            {
              errno = ENOTTY;
              pinentry->specific_err = ASSUAN_ENOTTY;
              return -1;
            }
	  init_screen = 1;
	  initscr ();
	}
      else
	clear ();
    }

  keypad (stdscr, TRUE); /* Enable keyboard mapping.  */
  nonl ();		/* Tell curses not to do NL->CR/NL on output.  */
  cbreak ();		/* Take input chars one at a time, no wait for \n.  */
  noecho ();		/* Don't echo input - in color.  */

  if (has_colors ())
    {
      start_color ();
#ifdef NCURSES_VERSION
      use_default_colors ();
#endif

      if (pinentry->color_so == PINENTRY_COLOR_DEFAULT)
	{
	  pinentry->color_so = PINENTRY_COLOR_RED;
	  pinentry->color_so_bright = 1;
	}
      if (COLOR_PAIRS >= 2)
	{
	  init_pair (1, pinentry_color[pinentry->color_fg],
		     pinentry_color[pinentry->color_bg]);
	  init_pair (2, pinentry_color[pinentry->color_so],
		     pinentry_color[pinentry->color_bg]);

	  bkgd (COLOR_PAIR (1));
	  attron (COLOR_PAIR (1) | (pinentry->color_fg_bright ? A_BOLD : 0));
	}
    }
  refresh ();

  /* Create the dialog.  */
  if (dialog_create (pinentry, &diag))
    {
      /* Note: pinentry->specific_err has already been set.  */
      endwin ();
      if (screen)
        delscreen (screen);

#ifdef HAVE_NCURSESW
      if (old_ctype)
        {
          setlocale (LC_CTYPE, old_ctype);
          free (old_ctype);
        }
#endif
      if (ttyfi)
        fclose (ttyfi);
      if (ttyfo)
        fclose (ttyfo);
      return -2;
    }
  dialog_switch_pos (&diag,
		     diag.pinentry->pin ? DIALOG_POS_PIN : DIALOG_POS_OK);

#ifndef HAVE_DOSISH_SYSTEM
  wtimeout (stdscr, 70);
#endif

  do
    {
      int c;

      c = wgetch (stdscr);     /* Refresh, accept single keystroke of input.  */
#ifndef HAVE_DOSISH_SYSTEM
      if (timed_out && no_input)
	{
	  done = -2;
	  break;
	}
#endif

      switch (c)
	{
	case ERR:
#ifndef HAVE_DOSISH_SYSTEM
	  continue;
#else
          done = -2;
          break;
#endif

	case 27: /* Alt was pressed.  */
	  alt = 1;
	  /* Get the next key press.  */
	  continue;

	case KEY_LEFT:
	case KEY_UP:
	  switch (diag.pos)
	    {
	    case DIALOG_POS_OK:
	      if (diag.pinentry->pin)
		dialog_switch_pos (&diag, DIALOG_POS_PIN);
	      break;
	    case DIALOG_POS_NOTOK:
	      dialog_switch_pos (&diag, DIALOG_POS_OK);
	      break;
	    case DIALOG_POS_CANCEL:
	      if (diag.notok)
		dialog_switch_pos (&diag, DIALOG_POS_NOTOK);
	      else
		dialog_switch_pos (&diag, DIALOG_POS_OK);
	      break;
	    default:
	      break;
	    }
	  break;

	case KEY_RIGHT:
	case KEY_DOWN:
	  switch (diag.pos)
	    {
	    case DIALOG_POS_PIN:
	      dialog_switch_pos (&diag, DIALOG_POS_OK);
	      break;
	    case DIALOG_POS_OK:
	      if (diag.notok)
		dialog_switch_pos (&diag, DIALOG_POS_NOTOK);
	      else
		dialog_switch_pos (&diag, DIALOG_POS_CANCEL);
	      break;
	    case DIALOG_POS_NOTOK:
	      dialog_switch_pos (&diag, DIALOG_POS_CANCEL);
	      break;
	    default:
	      break;
	    }
	  break;

	case '\t':
	  switch (diag.pos)
	    {
	    case DIALOG_POS_PIN:
	      dialog_switch_pos (&diag, DIALOG_POS_OK);
	      break;
	    case DIALOG_POS_OK:
	      if (diag.notok)
		dialog_switch_pos (&diag, DIALOG_POS_NOTOK);
	      else
		dialog_switch_pos (&diag, DIALOG_POS_CANCEL);
	      break;
	    case DIALOG_POS_NOTOK:
	      dialog_switch_pos (&diag, DIALOG_POS_CANCEL);
	      break;
	    case DIALOG_POS_CANCEL:
	      if (diag.pinentry->pin)
		dialog_switch_pos (&diag, DIALOG_POS_PIN);
	      else
		dialog_switch_pos (&diag, DIALOG_POS_OK);
	      break;
	    default:
	      break;
	    }
	  break;

	case '\005':
	  done = -2;
	  break;

	case '\r':
	  switch (diag.pos)
	    {
	    case DIALOG_POS_PIN:
	    case DIALOG_POS_OK:
	      done = 1;
	      break;
	    case DIALOG_POS_NOTOK:
	      done = -1;
	      break;
	    case DIALOG_POS_CANCEL:
	      done = -2;
	      break;
            case DIALOG_POS_NONE:
              break;
	    }
	  break;

	default:
	  if (diag.pos == DIALOG_POS_PIN)
	    dialog_input (&diag, alt, c);
	}
#ifndef HAVE_DOSISH_SYSTEM
      no_input = 0;
#endif
      if (c != -1)
	alt = 0;
    }
  while (!done);

  if (diag.pinentry->pin)
    /* NUL terminate the passphrase.  dialog_run makes sure there is
       enough space for the terminating NUL byte.  */
    diag.pinentry->pin[diag.pin_len] = 0;

  set_cursor_state (1);
  endwin ();
  if (screen)
    delscreen (screen);

#ifdef HAVE_NCURSESW
  if (old_ctype)
    {
      setlocale (LC_CTYPE, old_ctype);
      free (old_ctype);
    }
#endif
  if (ttyfi)
    fclose (ttyfi);
  if (ttyfo)
    fclose (ttyfo);
  /* XXX Factor out into dialog_release or something.  */
  free (diag.ok);
  if (diag.cancel)
    free (diag.cancel);
  if (diag.notok)
    free (diag.notok);

  if (pinentry->pin)
    {
      pinentry->locale_err = 1;
      pin_utf8 = pinentry_local_to_utf8 (pinentry->lc_ctype, pinentry->pin, 1);
      if (pin_utf8)
	{
	  pinentry_setbufferlen (pinentry, strlen (pin_utf8) + 1);
	  if (pinentry->pin)
	    strcpy (pinentry->pin, pin_utf8);
	  secmem_free (pin_utf8);
	  pinentry->locale_err = 0;
	}
    }

  if (done == -2)
    pinentry->canceled = 1;

  if (diag.pinentry->pin)
    return done < 0 ? -1 : diag.pin_len;
  else
    return done < 0 ? 0 : 1;
}
Esempio n. 12
0
static int
dialog_run (pinentry_t pinentry, const char *tty_name, const char *tty_type)
{
  struct dialog diag;
  FILE *ttyfi = NULL;
  FILE *ttyfo = NULL;
  SCREEN *screen = 0;
  int done = 0;
  char *pin_utf8;

  /* Open the desired terminal if necessary.  */
  if (tty_name)
    {
      ttyfi = fopen (tty_name, "r");
      if (!ttyfi)
	return -1;
      ttyfo = fopen (tty_name, "w");
      if (!ttyfo)
	{
	  int err = errno;
	  fclose (ttyfi);
	  errno = err;
	  return -1;
	}
      screen = newterm ((char *)tty_type, ttyfo, ttyfi);
      set_term (screen);
    }
  else
    {
      if (!init_screen)
	{
	  init_screen = 1;
	  initscr ();
	}
      else
	clear ();
    }
  
  keypad (stdscr, TRUE); /* Enable keyboard mapping.  */
  nonl ();		/* Tell curses not to do NL->CR/NL on output.  */
  cbreak ();		/* Take input chars one at a time, no wait for \n.  */
  noecho ();		/* Don't echo input - in color.  */

  if (has_colors ())
    {
      start_color ();
      use_default_colors ();

      if (pinentry->color_so == PINENTRY_COLOR_DEFAULT)
	{
	  pinentry->color_so = PINENTRY_COLOR_RED;
	  pinentry->color_so_bright = 1;
	}
      if (COLOR_PAIRS >= 2)
	{
	  init_pair (1, pinentry_color[pinentry->color_fg],
		     pinentry_color[pinentry->color_bg]);
	  init_pair (2, pinentry_color[pinentry->color_so],
		     pinentry_color[pinentry->color_bg]);

	  bkgd (COLOR_PAIR (1));
	  attron (COLOR_PAIR (1) | (pinentry->color_fg_bright ? A_BOLD : 0));
	}
    }
  refresh ();

  /* XXX */
  if (dialog_create (pinentry, &diag))
    return -2;
  dialog_switch_pos (&diag, diag.pin ? DIALOG_POS_PIN : DIALOG_POS_OK);

  do
    {
      int c;

      c = getch ();     /* Refresh, accept single keystroke of input.  */

      switch (c)
	{
	case KEY_LEFT:
	case KEY_UP:
	  switch (diag.pos)
	    {
	    case DIALOG_POS_OK:
	      if (diag.pin)
		dialog_switch_pos (&diag, DIALOG_POS_PIN);
	      break;
	    case DIALOG_POS_NOTOK:
	      dialog_switch_pos (&diag, DIALOG_POS_OK);
	      break;
	    case DIALOG_POS_CANCEL:
	      if (diag.notok)
		dialog_switch_pos (&diag, DIALOG_POS_NOTOK);
	      else
		dialog_switch_pos (&diag, DIALOG_POS_OK);
	      break;
	    default:
	      break;
	    }
	  break;

	case KEY_RIGHT:
	case KEY_DOWN:
	  switch (diag.pos)
	    {
	    case DIALOG_POS_PIN:
	      dialog_switch_pos (&diag, DIALOG_POS_OK);
	      break;
	    case DIALOG_POS_OK:
	      if (diag.notok)
		dialog_switch_pos (&diag, DIALOG_POS_NOTOK);
	      else
		dialog_switch_pos (&diag, DIALOG_POS_CANCEL);
	      break;
	    case DIALOG_POS_NOTOK:
	      dialog_switch_pos (&diag, DIALOG_POS_CANCEL);
	      break;
	    default:
	      break;
	    }
	  break;

	case '\t':
	  switch (diag.pos)
	    {
	    case DIALOG_POS_PIN:
	      dialog_switch_pos (&diag, DIALOG_POS_OK);
	      break;
	    case DIALOG_POS_OK:
	      if (diag.notok)
		dialog_switch_pos (&diag, DIALOG_POS_NOTOK);
	      else
		dialog_switch_pos (&diag, DIALOG_POS_CANCEL);	      
	      break;
	    case DIALOG_POS_NOTOK:
	      dialog_switch_pos (&diag, DIALOG_POS_CANCEL);
	      break;
	    case DIALOG_POS_CANCEL:
	      if (diag.pin)
		dialog_switch_pos (&diag, DIALOG_POS_PIN);
	      else
		dialog_switch_pos (&diag, DIALOG_POS_OK);
	      break;
	    default:
	      break;
	    }
	  break;
  
	case '\005':
	  done = -2;
	  break;

	case '\r':
	  switch (diag.pos)
	    {
	    case DIALOG_POS_PIN:
	    case DIALOG_POS_OK:
	      done = 1;
	      break;
	    case DIALOG_POS_NOTOK:
	      done = -1;
	      break;
	    case DIALOG_POS_CANCEL:
	      done = -2;
	      break;
            case DIALOG_POS_NONE:
              break;
	    }
	  break;

	default:
	  if (diag.pos == DIALOG_POS_PIN)
	    dialog_input (&diag, c);
	}
    }
  while (!done);

  set_cursor_state (1);
  endwin ();
  if (screen)
    delscreen (screen);

  if (ttyfi)
    fclose (ttyfi);
  if (ttyfo)
    fclose (ttyfo);
  /* XXX Factor out into dialog_release or something.  */
  free (diag.ok);
  if (diag.cancel)
    free (diag.cancel);
  if (diag.notok)
    free (diag.notok);

  if (pinentry->pin)
    {
      pinentry->locale_err = 1;
      pin_utf8 = pinentry_local_to_utf8 (pinentry->lc_ctype, pinentry->pin, 1);
      if (pin_utf8)
	{
	  pinentry_setbufferlen (pinentry, strlen (pin_utf8) + 1);
	  if (pinentry->pin)
	    strcpy (pinentry->pin, pin_utf8);
	  secmem_free (pin_utf8);
	  pinentry->locale_err = 0;
	}
    }

  if (done == -2)
    pinentry->canceled = 1;

  return diag.pin ? (done < 0 ? -1 : diag.pin_len) : (done < 0 ? 0 : 1);
}
Esempio n. 13
0
/* Shut down curses and put our terminal back to normal
*/
void exitcurses(void) {
    if (using_curses) {
        endwin();
        delscreen(term);
    }
}
Esempio n. 14
0
/*
 * Create a new terminal screen.  Used if a program is going to be sending
 * output to more than one terminal.  It returns a SCREEN* for the terminal.
 * The parameters are a terminal name, output FILE*, and input FILE*.  If
 * the terminal name is null then $TERM is used.  The program must also
 * call endwin() for each terminal being used before exiting from curses.
 * If newterm() is called more than once for the same terminal, the first
 * terminal referred to must be the last one for which endwin() is called.
 */
SCREEN *
newterm(char *term, FILE *out_fp, FILE *in_fp)
{
	WINDOW	*w;
	t_wide_io	*wio;
	SCREEN	*sp, *osp;
	int	i, n, y, errret;

	/*
	 * Input stream should be unbuffered so that m_tfgetc() works
	 * correctly on BSD and SUN systems.
	 */
	(void) setvbuf(in_fp, (char *) 0, _IONBF, BUFSIZ);
#if 0
/*
 * Not sure whether we really want to concern ourselves with the output
 * buffer scheme.  Might be best to leave it upto the application to
 * deal with buffer schemes and when to perform flushes.
 *
 * MKS Vi uses MKS Curses and so must support the ability to switch in
 * and out of Curses mode when switching from Vi to Ex and back.
 * Problem is that in Vi mode you would prefer full buffered output to
 * give updates a smoother appearance and Ex mode you require line
 * buffered in order to see prompts and messages.
 */
	(void) setvbuf(out_fp, (char *) 0, _IOLBF, BUFSIZ);
#endif
	errno = 0;

	if (__m_setupterm(term, fileno(in_fp), fileno(out_fp), &errret)
		== ERR) {
		switch (errret) {
		case -1:
			errno = ENOMEM;
			break;
		case 2:
			errno = ENAMETOOLONG;
			break;
		case 0:
		default:
			errno = ENOENT;
			break;
		}
		goto error1;
	}

	if (__m_doupdate_init())
		goto error1;

	if ((sp = (SCREEN *) calloc(1, sizeof (*sp))) == NULL)
		goto error1;

	sp->_kfd = -1;
	sp->_if = in_fp;
	sp->_of = out_fp;
	sp->_term = cur_term;

	sp->_unget._size = __m_decode_init((t_decode **) &sp->_decode);

	/*
	 * Maximum length of a multbyte key sequence, including
	 * multibyte characters and terminal function keys.
	 */
	if (sp->_unget._size < (M_TYPEAHEAD_SIZE + MB_LEN_MAX))
		sp->_unget._size = M_TYPEAHEAD_SIZE + MB_LEN_MAX;

	sp->_unget._stack = calloc((size_t) sp->_unget._size,
		sizeof (*sp->_unget._stack));
	if (sp->_unget._stack == NULL)
		goto error2;

	if ((wio = (t_wide_io *) calloc(1, sizeof (*wio))) == NULL)
		goto error2;

	/* Setup wide input for XCurses. */
	wio->get = (int (*)(void *)) wgetch;
	wio->unget = __xc_ungetc;
	wio->reset = __xc_clearerr;
	wio->iserror = __xc_ferror;
	wio->iseof = __xc_feof;
	sp->_in = wio;

	if (assume_one_line) {
		/* Assume only one line. */
		lines = 1;

		/* Disable capabilities that assume more than one line. */
		clear_screen = clr_eos = cursor_up = cursor_down = NULL;
		cursor_home = cursor_to_ll = cursor_address = NULL;
		row_address = parm_up_cursor = parm_down_cursor = NULL;

		/* Re-evaluate the cursor motion costs. */
		__m_mvcur_cost();

		/* Reset flag for subsequent calls to newterm(). */
		assume_one_line = FALSE;
	}

	if ((sp->_curscr = newwin(lines, columns, 0, 0)) == NULL)
		goto error2;

	if ((sp->_newscr = newwin(lines, columns, 0, 0)) == NULL)
		goto error2;

#if defined(_LP64)
	sp->_hash = (unsigned int *) calloc(lines, sizeof (*sp->_hash));
#else
	sp->_hash = (unsigned long *) calloc(lines, sizeof (*sp->_hash));
#endif
	if (sp->_hash == NULL)
		goto error2;

	if (0 <= __m_slk_format && __m_slk_init(sp, __m_slk_format) == ERR) {
		goto error2;
	}

	/*
	 * doupdate() will perform the final screen preparations like
	 * enter_ca_mode, reset_prog_mode() (to assert the termios
	 * changes), etc.
	 */
	sp->_flags |= S_ENDWIN;

#ifdef SIGTSTP
	(void) signal(SIGTSTP, tstp);
#endif
	/* Assert that __m_screen is set to the new terminal. */
	osp = set_term(sp);

	/* Disable echo in tty driver, Curses does software echo. */
	PTERMIOS(_prog)->c_lflag &= ~ECHO;

	/* Enable mappnig of cr -> nl on input and nl -> crlf on output. */
	PTERMIOS(_prog)->c_iflag |= ICRNL;
	PTERMIOS(_prog)->c_oflag |= OPOST;
#ifdef ONLCR
	PTERMIOS(_prog)->c_oflag |= ONLCR;
#endif
	cur_term->_flags |= __TERM_NL_IS_CRLF;

#ifdef TAB0
	/* Use real tabs. */
	PTERMIOS(_prog)->c_oflag &= ~(TAB1|TAB2|TAB3);
#endif

	/*
	 * Default to 'cbreak' mode as per
	 * test /tset/CAPIxcurses/fcbreak/fcbreak1{4}
	 */
	cur_term->_flags &= ~__TERM_HALF_DELAY;

	/*
	 * Default to 'idcok' mode as per
	 * test /tset/CAPIxcurses/fidcok/fidcok1{3}
	 */
	__m_screen->_flags |= S_INS_DEL_CHAR;

	PTERMIOS(_prog)->c_cc[VMIN] = 1;
	PTERMIOS(_prog)->c_cc[VTIME] = 0;
	PTERMIOS(_prog)->c_lflag &= ~ICANON;

	(void) __m_tty_set_prog_mode();
	(void) __m_set_echo(1);
	(void) typeahead(fileno(in_fp));

	(void) __m_slk_clear(1);

	n = rip.top - rip.bottom;
	if (stdscr == NULL) {
		stdscr = newwin(lines - n, 0, rip.top, 0);
		if (stdscr == NULL)
			goto error3;
	}
	/*
	 * Create and initialise ripped off line windows.
	 * It is the application's responsiblity to free the
	 * windows when the application terminates.
	 */
	for (i = 0; i < n; ++i) {
		if (rip.line[i].created)
			continue;
		y = rip.line[i].dy;
		if (y < 0)
			y += lines;

		w = newwin(1, 0, y, 0);
		if (rip.line[i].init != (int (*)(WINDOW *, int)) 0)
			(void) (*rip.line[i].init)(w, columns);
		rip.line[i].created = 1;
	}
	LINES = stdscr->_maxy = sp->_curscr->_maxy - n;

	return (sp);
error3:
	(void) set_term(osp);
error2:
	delscreen(sp);
error1:
	return (NULL);
}
Esempio n. 15
0
NCURSES_SP_NAME(_nc_freeall) (NCURSES_SP_DCL0)
{
    static va_list empty_va;

    T((T_CALLED("_nc_freeall()")));
#if NO_LEAKS
    _nc_globals.leak_checking = TRUE;
    if (SP_PARM != 0) {
	if (SP_PARM->_oldnum_list != 0) {
	    FreeAndNull(SP_PARM->_oldnum_list);
	}
	if (SP_PARM->_panelHook.destroy != 0) {
	    SP_PARM->_panelHook.destroy(SP_PARM->_panelHook.stdscr_pseudo_panel);
	}
#if USE_NEW_PAIR
	_nc_new_pair_leaks(SP_PARM);
#endif
    }
#endif
    if (SP_PARM != 0) {
	_nc_lock_global(curses);

	while (WindowList(SP_PARM) != 0) {
	    WINDOWLIST *p, *q;
	    bool deleted = FALSE;

	    /* Delete only windows that're not a parent */
	    for (each_window(SP_PARM, p)) {
		WINDOW *p_win = &(p->win);
		bool found = FALSE;

#ifndef USE_SP_WINDOWLIST
		if (p->screen != SP_PARM)
		    continue;
#endif

		for (each_window(SP_PARM, q)) {
		    WINDOW *q_win = &(q->win);

#ifndef USE_SP_WINDOWLIST
		    if (q->screen != SP_PARM)
			continue;
#endif

		    if ((p != q)
			&& (q_win->_flags & _SUBWIN)
			&& (p_win == q_win->_parent)) {
			found = TRUE;
			break;
		    }
		}

		if (!found) {
		    if (delwin(p_win) != ERR)
			deleted = TRUE;
		    break;
		}
	    }

	    /*
	     * Don't continue to loop if the list is trashed.
	     */
	    if (!deleted)
		break;
	}
	delscreen(SP_PARM);
	_nc_unlock_global(curses);
    }
Esempio n. 16
0
/* Shut down curses and put our terminal back to normal
*/
void exitcurses(void) {
    if (interactive.using_curses) {
       endwin();
       delscreen(term);
    }
}
Esempio n. 17
0
Nscreen::~Nscreen(){
   delscreen(scrptr);
}
Esempio n. 18
0
/*
==================
CON_Init

Initialize the console in curses mode, fall back to tty mode on failure
==================
*/
void CON_Init(void)
{
	int col;

#ifndef _WIN32
	// If the process is backgrounded (running non interactively)
	// then SIGTTIN or SIGTOU is emitted, if not caught, turns into a SIGSTP
	signal(SIGTTIN, SIG_IGN);
	signal(SIGTTOU, SIG_IGN);
#endif

	// Make sure we're on a tty
	if (isatty(STDIN_FILENO) != 1 || isatty(STDOUT_FILENO) != 1 || isatty(STDERR_FILENO) != 1) {
		CON_Init_tty();
		return;
	}

	// Initialize curses and set up the root window
	if (!curses_on) {
		SCREEN *test = newterm(NULL, stdout, stdin);
		if (!test) {
			CON_Init_tty();
			CON_Print_tty("Couldn't initialize curses, falling back to tty\n");
			return;
		}
		endwin();
		delscreen(test);
		initscr();
		cbreak();
		noecho();
		nonl();
		intrflush(stdscr, FALSE);
		nodelay(stdscr, TRUE);
		keypad(stdscr, TRUE);
		wnoutrefresh(stdscr);

		// Set up colors
		if (has_colors()) {
			use_default_colors();
			start_color();
			init_pair(1, COLOR_BLACK, -1);
			init_pair(2, COLOR_RED, -1);
			init_pair(3, COLOR_GREEN, -1);
			init_pair(4, COLOR_YELLOW, -1);
			init_pair(5, COLOR_BLUE, -1);
			init_pair(6, COLOR_CYAN, -1);
			init_pair(7, COLOR_MAGENTA, -1);
			init_pair(8, -1, -1);
		}
	}

	// Create the border
	borderwin = newwin(LOG_LINES + 2, LOG_COLS + 2, 1, 0);
	CON_SetColor(borderwin, 2);
	box(borderwin, 0, 0);
	wnoutrefresh(borderwin);

	// Create the log window
	logwin = newpad(MAX_LOG_LINES, LOG_COLS);
	scrollok(logwin, TRUE);
	idlok(logwin, TRUE);
	if (curses_on)
		CON_ColorPrint(logwin, logbuf, qtrue);
	getyx(logwin, lastline, col);
	if (col)
		lastline++;
	scrollline = lastline - LOG_LINES;
	if (scrollline < 0)
		scrollline = 0;
	pnoutrefresh(logwin, scrollline, 0, 2, 1, LOG_LINES + 1, LOG_COLS + 1);

	// Create the scroll bar
	scrollwin = newwin(LOG_LINES, 1, 2, COLS - 1);
	CON_DrawScrollBar();
	CON_SetColor(stdscr, 3);
	mvaddch(1, COLS - 1, SCRLBAR_UP);
	mvaddch(LINES - 2, COLS - 1, SCRLBAR_DOWN);

	// Create the input field
	inputwin = newwin(1, COLS - Q_PrintStrlen(PROMPT) - 8, LINES - 1, Q_PrintStrlen(PROMPT) + 8);
	input_field.widthInChars = COLS - Q_PrintStrlen(PROMPT) - 9;
	if (curses_on) {
		if (input_field.cursor < input_field.scroll)
			input_field.scroll = input_field.cursor;
		else if (input_field.cursor >= input_field.scroll + input_field.widthInChars)
			input_field.scroll = input_field.cursor - input_field.widthInChars + 1;
		CON_ColorPrint(inputwin, input_field.buffer + input_field.scroll, qfalse);
	}
	CON_UpdateCursor();
	wnoutrefresh(inputwin);

	// Create the clock
	clockwin = newwin(1, 8, LINES - 1, 0);
	CON_UpdateClock();

	// Display the title and input prompt
	move(0, (COLS - Q_PrintStrlen(TITLE)) / 2);
	CON_ColorPrint(stdscr, TITLE, qtrue);
	move(LINES - 1, 8);
	CON_ColorPrint(stdscr, PROMPT, qtrue);
	wnoutrefresh(stdscr);
	doupdate();

#ifndef _WIN32
	// Catch window resizes
	signal(SIGWINCH, (void *)CON_Resize);
#endif

	curses_on = qtrue;
}