Пример #1
0
int main() {
  //struct timeval lastTime;

  WINDOW *win = initscr();
  keypad(win, true);
  curs_set(0);
  raw();
  noecho();
  timeout(gSpeed);
  
  start_color();
  //
  
  gGame.width = getmaxx(win);
  gGame.height = getmaxy(win);
  
  level_load(0);
  //gettimeofday(&gGame.lastTime, NULL);
  while ((gGame.input = getch()) != 'q') {
    level_draw();
    /*gettimeofday(&lastTime, NULL);
    gGame.elapsedTime = 1000 * (gGame.lastTime.tv_sec - lastTime.tv_sec) + (gGame.lastTime.tv_usec - lastTime.tv_usec);
    gGame.lastTime = lastTime;*/
  }
  level_unload(true);
  
  keypad(win, false);
  curs_set(1);
  echo();
  noraw();
  delwin(win);
  endwin();

  return 0;
}
Пример #2
0
int
_meta(int bf)
{
	/*
	 * Do the appropriate fiddling with the tty driver to make it send
	 * all 8 bits through.  On SYSV this means clearing ISTRIP, on
	 * V7 you have to resort to RAW mode.
	 */
#ifdef	SYSV
	if (bf)
		PROGTTYS.c_iflag &= ~ISTRIP;
	else
		PROGTTYS.c_iflag |= ISTRIP;
	(void) reset_prog_mode();
#else	/* SYSV */
	if (bf)
		raw();
	else
		noraw();
#endif	/* SYSV */

	/* Do whatever is needed to put the terminal into meta-mode. */

	if ((SP->fl_meta = bf) != 0)
		(void) tputs(meta_on, 1, _outch);
	else
		(void) tputs(meta_off, 1, _outch);
	(void) fflush(SP->term_file);
	return (OK);
}
Пример #3
0
int
main()
{
    CELL file_cpy = {0};
    WINDOW *mainwin;

    mainwin = initscr();
    start_color();
    setup_colors();
    cbreak();
    noecho();
    keypad(mainwin, TRUE);
    meta(mainwin, TRUE);
    raw();

    leaveok(mainwin, TRUE);
    wbkgd(mainwin, COLOR_PAIR(COLOR_MAIN));
    wattron(mainwin, COLOR_PAIR(COLOR_MAIN));
    werase(mainwin);
    refresh();

    file_cpy.window = mainwin;

    main_dir(&file_cpy);

    wbkgd(mainwin, A_NORMAL);
    werase(mainwin);
    echo();
    nocbreak();
    noraw();
    refresh();
    endwin();
    return TRUE;
}
Пример #4
0
/***
Put the terminal into raw mode.
@function raw
@bool[opt] on
@treturn bool `true`, if successful
@see noraw(3x)
@see raw(3x)
*/
static int
Praw(lua_State *L)
{
	if (lua_isnoneornil(L, 1) || lua_toboolean(L, 1))
		return pushokresult(raw());
	return pushokresult(noraw());
}
Пример #5
0
static void tty_cleanup(void)
{
    move(nlines - 1, 0);
    refresh();
    noraw();
    echo();
    endwin();
}
Пример #6
0
void finish2()
{
  fclose(fdebug);
  delwin(topwin); delwin(editwin); delwin(bottomwin); 
  echo(); noraw();  
  endwin();
  exit(0);
}
Пример #7
0
restartterm(NCURSES_CONST char *termp, int filenum, int *errret)
{
    int result;

    T((T_CALLED("restartterm(%s,%d,%p)"), termp, filenum, errret));

    if (setupterm(termp, filenum, errret) != OK) {
	result = ERR;
    } else if (SP != 0) {
	int saveecho = SP->_echo;
	int savecbreak = SP->_cbreak;
	int saveraw = SP->_raw;
	int savenl = SP->_nl;

	if (saveecho)
	    echo();
	else
	    noecho();

	if (savecbreak) {
	    cbreak();
	    noraw();
	} else if (saveraw) {
	    nocbreak();
	    raw();
	} else {
	    nocbreak();
	    noraw();
	}
	if (savenl)
	    nl();
	else
	    nonl();

	reset_prog_mode();

#if USE_SIZECHANGE
	_nc_update_screensize(SP);
#endif

	result = OK;
    } else {
	result = ERR;
    }
    returnCode(result);
}
Пример #8
0
int Curses_allow_interrupts(int ok)
{
    refresh();
    if (ok)
	noraw();
    else
	raw();
    return 0;
}
Пример #9
0
void backspace()
{
  noraw();
  move(cursor_row,cursor_col-1);
  delch();
  raw();
  refresh();
  getsyx(cursor_row,cursor_col);
}
Пример #10
0
nCurse::~nCurse() {
    if (running) {
        noraw();
        echo();
        endwin();
        delscreen(s);
        keypad(stdscr, FALSE);
        running = false;
    }
}
Пример #11
0
// lnc.raw(on: boolean)
static int lnc_raw(lua_State *L)
{
	luaL_checktype(L, -1, LUA_TBOOLEAN);
	int on = lua_toboolean(L, -1);
	if (on) {
		raw();
	} else {
		noraw();
	}
	return 0;
}
Пример #12
0
int		NCurseGui::guiQuit()
{
  wborder(_win, ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ');
  wrefresh(_win);
  delwin(_win);
  curs_set(1);
  noraw();
  echo();
  endwin();
  return 0;
}
Пример #13
0
int main (int argc, char* argv[])
{
    char password[LEN+1];
    int  pigs_can_fly = 1;

    /* Catch what we can, pretend that SIGKILL is catchable */
    if (DEBUG != 1)
    {
        signal(SIGHUP,  SIG_IGN);
        signal(SIGINT,  SIG_IGN);
        signal(SIGQUIT, SIG_IGN);
        signal(SIGKILL, SIG_IGN);
        signal(SIGTERM, SIG_IGN);
        signal(SIGTSTP, SIG_IGN);
    }

    /* Initialise Curses */
    initscr();

    /* Let me process everything, and turn off auto echo */
    raw(); 
    if (DEBUG != 1)
    {
        noecho();
    }

    while (pigs_can_fly) {

        /* printf won't work due to noecho() */
        printw("Password:"******"Without the password, you're going nowhere :-)\n");
        }
    }

    /* Turn echo'ing back on, and leave raw mode */
    if (DEBUG != 1)
    {
        echo();
    }
    noraw();

    /* Cleanup from curses */
    endwin();

    return 0;
}
Пример #14
0
int restartterm(const char *term, int filenum, int *errret)
{
int saveecho = SP->_echo;
int savecbreak = SP->_cbreak;
int saveraw = SP->_raw;
int savenl = SP->_nl;

	T((T_CALLED("restartterm(%s,%d,%p)"), term, filenum, errret));

	setupterm(term, filenum, errret);

	if (saveecho)
		echo();
	else
		noecho();

	if (savecbreak) {
		cbreak();
		noraw();
	} else if (saveraw) {
		nocbreak();
		raw();
	} else {
		nocbreak();
		noraw();
	}
	if (savenl)
		nl();
	else
		nonl();

	reset_prog_mode();

#if USE_SIZECHANGE
	_nc_update_screensize();
#endif

	returnCode(OK);
}
Пример #15
0
static int ncurses_end_graphics(caca_display_t *dp)
{
    _caca_set_term_title("");
    mousemask(dp->drv.p->oldmask, NULL);
    curs_set(1);
    noraw();
    endwin();

#if defined HAVE_GETENV && defined HAVE_PUTENV
    ncurses_uninstall_terminal(dp);
#endif

    free(dp->drv.p);

    return 0;
}
Пример #16
0
void t_unset_flags(int flags)
{
	if (flags & TUI_KEYPAD)
		keypad(stdscr, FALSE);

	if (flags & TUI_NO_DELAY)
		nodelay(stdscr, FALSE);

	if (flags & TUI_ECHO)
		noecho();

	if (flags & TUI_RAW)
		noraw();

	if (flags & TUI_COOKED)
		cbreak();
}
Пример #17
0
static void stop_catcher(int signo UNUSED)
{
    sigset_t sigset, osigset;

    stoptime();
    noraw();
    echo();
    move(nlines - 1, 0);
    refresh();

    signal(SIGTSTP, SIG_DFL);
    sigemptyset(&sigset);
    sigaddset(&sigset, SIGTSTP);
    sigprocmask(SIG_UNBLOCK, &sigset, &osigset);
    kill(0, SIGTSTP);
    sigprocmask(SIG_SETMASK, &osigset, (sigset_t *) 0);
    signal(SIGTSTP, stop_catcher);
}
Пример #18
0
int
/* The next line causes a lint warning because errret is not used */
restartterm(char *term, int filenum, int *errret)
/* int	filenum - This is a UNIX file descriptor, not a stdio ptr. */
{
	int	saveecho = SP->fl_echoit;
	int	savecbreak = cur_term->_fl_rawmode;
	int	savenl;

#ifdef	SYSV
	savenl = PROGTTYS.c_iflag & ONLCR;
#else	/* SYSV */
	savenl = PROGTTY.sg_flags & CRMOD;
#endif	/* SYSV */

	_called_before = 0;
	(void) setupterm(term, filenum, (int *) 0);

	/* Restore curses settable flags, leaving other stuff alone. */
	SP->fl_echoit = saveecho;

	(void) nocbreak();
	(void) noraw();
	if (savecbreak == 1)
		(void) cbreak();
	else
		if (savecbreak == 2)
			(void) raw();

	if (savenl)
		(void) nl();
	else
		(void) nonl();

	(void) reset_prog_mode();

	LINES = SP->lsize;
	COLS = columns;
	return (OK);
}
Пример #19
0
char *input_name(void)
{
	char *name = malloc(sizeof(char) * 36);
	int height = 3;
	int width = 40;
	int startx = (COLS - width) / 2;
	int starty = (LINES - height) / 2;

	WINDOW *win = newwin(height, width, starty, startx);
	clear();
	box(win, 0, 0);
	mvwprintw(win, 0, 1, "Enter your name");
	wrefresh(win);
	wmove(win, 1, 1);
	noraw();
	echo();
	wscanw(win, "%[a-zA-z_0-9]", name);
	raw();
	noecho();


	return name;
}
Пример #20
0
EIF_INTEGER c_ecurses_noraw ()
{
    return noraw ();
};
Пример #21
0
void
tty_noraw_mode (void)
{
    nocbreak ();                /* FIXME: unneeded? */
    noraw ();
}
Пример #22
0
wgetn_wstr(WINDOW *win, wint_t *str, int maxlen)
{
    SCREEN *sp = _nc_screen_of(win);
    TTY buf;
    bool oldnl, oldecho, oldraw, oldcbreak;
    wint_t erasec;
    wint_t killc;
    wint_t *oldstr = str;
    wint_t *tmpstr = str;
    wint_t ch;
    int y, x, code;

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

    if (!win)
	returnCode(ERR);

    _nc_get_tty_mode(&buf);

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

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

    getyx(win, y, x);

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

    while ((code = wget_wch(win, &ch)) != ERR) {
	/*
	 * Map special characters into key-codes.
	 */
	if (ch == '\r')
	    ch = '\n';
	if (ch == '\n') {
	    code = KEY_CODE_YES;
	    ch = KEY_ENTER;
	}
	if (ch < KEY_MIN) {
	    if (ch == erasec) {
		ch = KEY_BACKSPACE;
		code = KEY_CODE_YES;
	    }
	    if (ch == killc) {
		ch = KEY_EOL;
		code = KEY_CODE_YES;
	    }
	}
	if (code == KEY_CODE_YES) {
	    /*
	     * Some terminals (the Wyse-50 is the most common) generate a \n
	     * from the down-arrow key.  With this logic, it's the user's
	     * choice whether to set kcud=\n for wget_wch(); terminating
	     * *getn_wstr() with \n should work either way.
	     */
	    if (ch == KEY_DOWN || ch == KEY_ENTER) {
		if (oldecho == TRUE
		    && win->_cury == win->_maxy
		    && win->_scroll)
		    wechochar(win, (chtype) '\n');
		break;
	    }
	    if (ch == KEY_LEFT || ch == KEY_BACKSPACE) {
		if (tmpstr > oldstr) {
		    tmpstr = WipeOut(win, y, x, oldstr, tmpstr, oldecho);
		}
	    } else if (ch == KEY_EOL) {
		while (tmpstr > oldstr) {
		    tmpstr = WipeOut(win, y, x, oldstr, tmpstr, oldecho);
		}
	    } else {
		beep();
	    }
	} else if (maxlen >= 0 && tmpstr - oldstr >= maxlen) {
	    beep();
	} else {
	    *tmpstr++ = ch;
	    *tmpstr = 0;
	    if (oldecho == TRUE) {
		int oldy = win->_cury;

		if (wadd_wint(win, tmpstr - 1) == ERR) {
		    /*
		     * We can't really use the lower-right corner for input,
		     * since it'll mess up bookkeeping for erases.
		     */
		    win->_flags &= ~_WRAPPED;
		    waddch(win, (chtype) ' ');
		    tmpstr = WipeOut(win, y, x, oldstr, tmpstr, oldecho);
		    continue;
		} else if (win->_flags & _WRAPPED) {
		    /*
		     * If the last waddch forced a wrap & scroll, adjust our
		     * reference point for erasures.
		     */
		    if (win->_scroll
			&& oldy == win->_maxy
			&& win->_cury == win->_maxy) {
			if (--y <= 0) {
			    y = 0;
			}
		    }
		    win->_flags &= ~_WRAPPED;
		}
		wrefresh(win);
	    }
	}
    }

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

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

    (void) _nc_set_tty_mode(&buf);

    *tmpstr = 0;
    if (code == ERR) {
	if (tmpstr == oldstr) {
	    *tmpstr++ = WEOF;
	    *tmpstr = 0;
	}
	returnCode(ERR);
    }

    T(("wgetn_wstr returns %s", _nc_viswibuf(oldstr)));

    returnCode(OK);
}
Пример #23
0
void get_current()
{
  int c,lc,i=0;

  raw();
  noecho();
  keypad(stdscr, TRUE);

  while ((c=getch()))
  {
    if (c == '\t')                                // Tab
    {
      if (showing)  tab_hits_down();
      else {
        clrtobot();
        if (current_length > 1) {
          hunt_current();
          show_hits();
          tab_hits_down();
        }
      }
    }
    else if (c == '\n' && lc == '\n') break;      // two-returns to quit
    else if (c == 27) { exiting=1;break;break; }            // ESC quit
    else if (c == 'J' || c == 258)                // J | d-arrow down hit list
      tab_hits_down();
    else if (c == 'K' || c == 353 || c == 259)    // K | <shift-TAB> | u-arrow up hit list
      tab_hits_up(); 
    else if (c == 32)                             // SPACE to reset search
    {
      memset(current,'\0',MAX_LINE);
      current_length = 0;
      clear_matches();
      setup_screen();
      mvprintw(LINES - 2, 0, "!: %s", items);
      move(cursor_row,cursor_col+3);
      refresh();
      i=0;
    }
    else if (c == 127 || c == 8)                  // DELETE or BACKSPACE
    {
      if (current_length > 0 )
      {
        i--;
        current_length--;
        current[i] = '\0';
        clrtobot();
        mvprintw(LINES - 2, 0, "!: %s", items);
        backspace();
        move(cursor_row,cursor_col);
        getsyx(cursor_row,cursor_col);
        if (showing && current_length > 1) {
          hunt_current();
          show_hits();
          tab_hits_down();
        }
      }
    }
    else if (c=='\n')                             // SELECT hightlighted hit or typed word
    {
      if (showing && sel_match>-1) strcat(items,tags[matches[sel_match].index]);
      else strcat(items,current);
      memset(current,'\0',MAX_LINE);
      current_length=i=0;
      setup_screen();
      showing=FALSE;
      strcat(items," ");
      mvprintw(LINES - 2, 0, "!: %s", items);
      move(cursor_row,cursor_col+3);
      refresh();
    }
    else                                          // regular key-typed
    {
      addch(c);
      current[i]=c;
      ++i;
      ++current_length;
      refresh();
      getsyx(cursor_row,cursor_col);
      if (showing && (current_length > 1)) {
        noraw();
        delch();
        raw();
        refresh();
        hunt_current();
        show_hits();
        tab_hits_down();
      }
      else showing=FALSE;
    }
    lc = c;
    if (diags) diag(c);
  }
  current[i] = '\0';
}
Пример #24
0
static void
demo_forms(void)
{
    WINDOW *w;
    FORM *form;
    FIELD *f[100];		/* FIXME memset to zero */
    int finished = 0, c;
    unsigned n = 0;
    int pg;
    WINDOW *also;

#ifdef NCURSES_MOUSE_VERSION
    mousemask(ALL_MOUSE_EVENTS, (mmask_t *) 0);
#endif

    help_edit_field();

    MvAddStr(4, 57, "Forms Entry Test");
    show_insert_mode(TRUE);

    refresh();

    /* describe the form */
    memset(f, 0, sizeof(f));
    for (pg = 0; pg < 4; ++pg) {
	char label[80];
	sprintf(label, "Sample Form Page %d", pg + 1);
	f[n++] = make_label(0, 15, label);
	set_new_page(f[n - 1], TRUE);

	switch (pg) {
	default:
	    f[n++] = make_label(2, 0, "Last Name");
	    f[n++] = make_field(3, 0, 1, 18);
	    set_field_type(f[n - 1], TYPE_ALPHA, 1);

	    f[n++] = make_label(2, 20, "First Name");
	    f[n++] = make_field(3, 20, 1, 12);
	    set_field_type(f[n - 1], TYPE_ALPHA, 1);

	    f[n++] = make_label(2, 34, "Middle Name");
	    f[n++] = make_field(3, 34, 1, 12);
	    set_field_type(f[n - 1], TYPE_ALPHA, 1);
	    break;
	case 1:
	    f[n++] = make_label(2, 0, "Last Name");
	    f[n++] = make_field(3, 0, 1, 18);
	    set_field_type(f[n - 1], TYPE_ALPHA, 1);

	    f[n++] = make_label(2, 20, "First Name");
	    f[n++] = make_field(3, 20, 1, 12);
	    set_field_type(f[n - 1], TYPE_ALPHA, 1);

	    f[n++] = make_label(2, 34, "MI");
	    f[n++] = make_field(3, 34, 1, 1);
	    set_field_pad(f[n - 1], '?');
	    set_field_type(f[n - 1], TYPE_ALPHA, 1);
	    break;
	case 2:
	    f[n++] = make_label(2, 0, "Host Name");
	    f[n++] = make_field(3, 0, 1, 18);
	    set_field_type(f[n - 1], TYPE_ALNUM, 1);

#ifdef NCURSES_VERSION
	    f[n++] = make_label(2, 20, "IP Address");
	    f[n++] = make_field(3, 20, 1, 12);
	    set_field_type(f[n - 1], TYPE_IPV4, 1);
#endif

	    break;

	case 3:
	    f[n++] = make_label(2, 0, "Four digits");
	    f[n++] = make_field(3, 0, 1, 18);
	    set_field_type(f[n - 1], TYPE_INTEGER, 4, 0, 0);

	    f[n++] = make_label(2, 20, "Numeric");
	    f[n++] = make_field(3, 20, 1, 12);
	    set_field_type(f[n - 1], TYPE_NUMERIC, 3, -10000.0, 100000000.0);

	    break;
	}

	f[n++] = make_label(5, 0, "Comments");
	f[n++] = make_field(6, 0, 4, 46);
	set_field_buffer(f[n - 1], 0, "HELLO\nWORLD!");
	set_field_buffer(f[n - 1], 1, "Hello\nWorld!");
    }

    f[n] = (FIELD *) 0;

    if ((form = new_form(f)) != 0) {

	display_form(form);

	w = form_win(form);
	also = newwin(getmaxy(stdscr) - getmaxy(w), COLS, getmaxy(w), 0);
	show_current_field(also, form);

	while (!finished) {
	    switch (edit_field(form, &c)) {
	    case E_OK:
		break;
	    case E_UNKNOWN_COMMAND:
		finished = my_form_driver(form, c);
		break;
	    default:
		beep();
		break;
	    }
	    show_current_field(also, form);
	}

	erase_form(form);

	free_form(form);
    }
    for (c = 0; f[c] != 0; c++) {
	void *ptr = field_userptr(f[c]);
	free(ptr);
	free_field(f[c]);
    }
    noraw();
    nl();

#ifdef NCURSES_MOUSE_VERSION
    mousemask(0, (mmask_t *) 0);
#endif
}
Пример #25
0
void xendwin()
{
    keypad(stdscr, FALSE);
    noraw();
    endwin();
}
Пример #26
0
void initialise_curses(void)
{
#ifdef BUILDWIDE
      setlocale(LC_CTYPE, "");
#endif
      /* maybe this will fix the resize problem */
      unsetenv("LINES");
      unsetenv("COLUMNS");

      initscr();

#ifdef LEAVE_SCROLLBACK
#define isprivate(s) ((s) != 0 && strstr(s, "\033[?") != 0)
    if (isprivate(enter_ca_mode) && isprivate(exit_ca_mode)) {
	    (void) putp(exit_ca_mode);
	    (void) putp(clear_screen);
	    enter_ca_mode = 0;
	    exit_ca_mode = 0;
    }
#endif

      if(has_colors() == TRUE)
      {
         if(start_color() != ERR)
         {
            use_default_colors();
         }
         else
         {
            debug(DEBUGLEVEL_WARN, "CmdStartup start_color failed\n");
         }
      }
      else
      {
         debug(DEBUGLEVEL_WARN, "CmdStartup has_colors false\n");
      }

      noraw();
      cbreak();
      noecho();
      scrollok(stdscr, TRUE);
      idlok(stdscr, TRUE);
      keypad(stdscr, TRUE);

      intrflush(stdscr, FALSE);
      // nodelay(stdscr, TRUE);
      // halfdelay(10);
      timeout(50);

      def_prog_mode();

      // debug("CmdStartup color (%ld %ld)\n", stdscr->_attrs, stdscr->_bkgd);

      /* for(iColourNum = 0; iColourNum <= 9; iColourNum++)
      {
         iF = -1;
         iB = -1;
         pair_content(iColourNum, &iF, &iB);
         debug("CmdStartup colour %d: %d %d\n", iColourNum, iF, iB);
      } */

      // pair_content(1, &iForeground, &iBackground);
      CmdBackground(0);
}
Пример #27
0
cell pp_curs_noraw(cell x) {
	if (!Running) return UNSPECIFIC;
	noraw();
	return UNSPECIFIC;
}
Пример #28
0
wgetnstr_events(WINDOW *win,
		char *str,
		int maxlen,
		EVENTLIST_1st(_nc_eventlist * evl))
{
    SCREEN *sp = _nc_screen_of(win);
    TTY buf;
    bool oldnl, oldecho, oldraw, oldcbreak;
    char erasec;
    char killc;
    char *oldstr;
    int ch;
    int y, x;

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

    if (!win)
	returnCode(ERR);

    _nc_get_tty_mode(&buf);

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

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

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

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

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

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

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

    _nc_set_tty_mode(&buf);

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

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

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

    returnCode(OK);
}
Пример #29
0
static void
inputTest(WINDOW *win)
{
    int answered;
    int repeat;
    int w, h, bx, by, sw, sh, i, c, num;
    char buffer[80];
    WINDOW *subWin;
    wclear(win);

    getmaxyx(win, h, w);
    getbegyx(win, by, bx);
    sw = w / 3;
    sh = h / 3;
    if ((subWin = subwin(win, sh, sw, by + h - sh - 2, bx + w - sw - 2)) == NULL)
	return;

#ifdef A_COLOR
    if (has_colors()) {
	init_pair(2, COLOR_WHITE, COLOR_RED);
	wbkgd(subWin, (chtype) COLOR_PAIR(2) | A_BOLD);
    } else
	wbkgd(subWin, A_BOLD);
#else
    wbkgd(subWin, A_BOLD);
#endif
    box(subWin, ACS_VLINE, ACS_HLINE);
    wrefresh(win);

    nocbreak();
    MvWAddStr(win, 2, 1, "Press some keys for 5 seconds");
    MvWAddStr(win, 1, 1, "Pressing ^C should do nothing");
    wrefresh(win);

    werase(subWin);
    box(subWin, ACS_VLINE, ACS_HLINE);
    for (i = 0; i < 5; i++) {
	MvWPrintw(subWin, 1, 1, "Time = %d", i);
	wrefresh(subWin);
	napms(1000);
	flushinp();
    }

    delwin(subWin);
    werase(win);
    flash();
    wrefresh(win);
    napms(500);

    MvWAddStr(win, 2, 1, "Press a key, followed by ENTER");
    wmove(win, 9, 10);
    wrefresh(win);
    echo();
    noraw();
    wgetch(win);
    flushinp();

    wmove(win, 9, 10);
    wdelch(win);
    MvWAddStr(win, 4, 1, "The character should now have been deleted");
    Continue(win);

    wclear(win);
    MvWAddStr(win, 1, 1, "Press keys (or mouse buttons) to show their names");
    MvWAddStr(win, 2, 1, "Press spacebar to finish");
    wrefresh(win);

    keypad(win, TRUE);
    raw();
    noecho();

#if HAVE_TYPEAHEAD
    typeahead(-1);
#endif

#ifdef NCURSES_MOUSE_VERSION
    mousemask(ALL_MOUSE_EVENTS, (mmask_t *) 0);
#endif
#if defined(PDCURSES)
    mouse_set(ALL_MOUSE_EVENTS);
#endif

    for (;;) {
	wmove(win, 3, 5);
	c = wgetch(win);
	wclrtobot(win);
	if (c >= KEY_MIN)
	    wprintw(win, "Key Pressed: %s", keyname(c));
	else if (isprint(c))
	    wprintw(win, "Key Pressed: %c", c);
	else
	    wprintw(win, "Key Pressed: %s", unctrl(UChar(c)));
#ifdef KEY_MOUSE
	if (c == KEY_MOUSE) {
#if defined(NCURSES_MOUSE_VERSION)
#define ButtonChanged(n) ((event.bstate) & NCURSES_MOUSE_MASK(1, 037))
#define ButtonPressed(n) ((event.bstate) & NCURSES_MOUSE_MASK(1, NCURSES_BUTTON_PRESSED))
#define ButtonDouble(n)  ((event.bstate) & NCURSES_MOUSE_MASK(1, NCURSES_DOUBLE_CLICKED))
#define ButtonTriple(n)  ((event.bstate) & NCURSES_MOUSE_MASK(1, NCURSES_TRIPLE_CLICKED))
#define ButtonRelease(n) ((event.bstate) & NCURSES_MOUSE_MASK(1, NCURSES_BUTTON_RELEASED))
	    MEVENT event;
	    int button = 0;

	    getmouse(&event);
	    if (ButtonChanged(1))
		button = 1;
	    else if (ButtonChanged(2))
		button = 2;
	    else if (ButtonChanged(3))
		button = 3;
	    else
		button = 0;
	    wmove(win, 4, 18);
	    wprintw(win, "Button %d: ", button);
	    if (ButtonPressed(button))
		wprintw(win, "pressed: ");
	    else if (ButtonDouble(button))
		wprintw(win, "double: ");
	    else if (ButtonTriple(button))
		wprintw(win, "triple: ");
	    else
		wprintw(win, "released: ");
	    wprintw(win, " Position: Y: %d X: %d", event.y, event.x);
#elif defined(PDCURSES)
	    int button = 0;
	    request_mouse_pos();
	    if (BUTTON_CHANGED(1))
		button = 1;
	    else if (BUTTON_CHANGED(2))
		button = 2;
	    else if (BUTTON_CHANGED(3))
		button = 3;
	    else
		button = 0;
	    wmove(win, 4, 18);
	    wprintw(win, "Button %d: ", button);
	    if (MOUSE_MOVED)
		wprintw(win, "moved: ");
	    else if ((BUTTON_STATUS(button) & BUTTON_ACTION_MASK) == BUTTON_PRESSED)
		wprintw(win, "pressed: ");
	    else if ((BUTTON_STATUS(button) & BUTTON_ACTION_MASK) == BUTTON_DOUBLE_CLICKED)
		wprintw(win, "double: ");
	    else
		wprintw(win, "released: ");
	    wprintw(win, " Position: Y: %d X: %d", MOUSE_Y_POS, MOUSE_X_POS);
#endif /* NCURSES_VERSION vs PDCURSES */
	}
#endif /* KEY_MOUSE */
	wrefresh(win);
	if (c == ' ')
	    break;
    }
#if 0
    nodelay(win, TRUE);
    wgetch(win);
    nodelay(win, FALSE);
#endif
#if defined(PDCURSES)
    mouse_set(0L);
#endif
    refresh();

    repeat = 0;
    do {
	static const char *fmt[] =
	{
	    "%d %10s",
	    "%d %[a-zA-Z]s",
	    "%d %[][a-zA-Z]s",
	    "%d %[^0-9]"
	};
	char *format = strdup(fmt[(unsigned) repeat % SIZEOF(fmt)]);

	wclear(win);
	MvWAddStr(win, 3, 2, "The window should have moved");
	MvWAddStr(win, 4, 2,
		  "This text should have appeared without you pressing a key");
	MvWPrintw(win, 6, 2,
		  "Scanning with format \"%s\"", format);
	mvwin(win, 2 + 2 * (repeat % 4), 1 + 2 * (repeat % 4));
	erase();
	refresh();
	wrefresh(win);
	echo();
	noraw();
	num = 0;
	*buffer = 0;
	answered = mvwscanw(win, 7, 6, format, &num, buffer);
	MvWPrintw(win, 8, 6,
		  "String: %s Number: %d (%d values read)",
		  buffer, num, answered);
	Continue(win);
	++repeat;
	free(format);
    } while (answered > 0);
}
Пример #30
0
static void
outputTest(WINDOW *win)
{
    WINDOW *win1;
    char Buffer[80];
    chtype ch;
    int by, bx;

#if !HAVE_TIGETSTR
#if HAVE_TGETENT
    char tc_buffer[4096];
    char tc_parsed[4096];
    char *area_pointer = tc_parsed;
    tgetent(tc_buffer, getenv("TERM"));
#else
#define tgetstr(a,b) 0
#endif
#endif /* !HAVE_TIGETSTR */

    nl();
    wclear(win);
    MvWAddStr(win, 1, 1,
	      "You should now have a screen in the upper left corner, and this text should have wrapped");
    mvwin(win, 2, 1);
    waddstr(win, "\nThis text should be down\n");
    waddstr(win, "and broken into two here ^");
    Continue(win);

    wclear(win);
    wattron(win, A_BOLD);
    MvWAddStr(win, 1, 1, "A new window will appear with this text in it");
    MvWAddStr(win, 8, 1, "Press any key to continue");
    wrefresh(win);
    wgetch(win);

    getbegyx(win, by, bx);

    if (LINES < 24 || COLS < 75) {
	MvWAddStr(win, 5, 1,
		  "Some tests have been skipped as they require a");
	MvWAddStr(win, 6, 1, "display of at least 24 LINES by 75 COLUMNS");
	Continue(win);
    } else {
	win1 = newwin(10, 50, 14, 25);
	if (win1 == NULL) {
	    endwin();
	    return;
	}
#ifdef A_COLOR
	if (has_colors()) {
	    init_pair(3, COLOR_BLUE, COLOR_WHITE);
	    wbkgd(win1, (chtype) COLOR_PAIR(3));
	} else
	    wbkgd(win1, A_NORMAL);
#else
	wbkgd(win1, A_NORMAL);
#endif
	wclear(win1);
	MvWAddStr(win1, 5, 1,
		  "This text should appear; using overlay option");
	copywin(win, win1, 0, 0, 0, 0, 9, 49, TRUE);

#if defined(PDCURSES) && !defined(XCURSES)
	box(win1, 0xb3, 0xc4);
#else
	box(win1, ACS_VLINE, ACS_HLINE);
#endif
	wmove(win1, 8, 26);
	wrefresh(win1);
	wgetch(win1);

	wclear(win1);
	wattron(win1, A_BLINK);
	MvWAddStr(win1, 4, 1,
		  "This blinking text should appear in only the second window");
	wattroff(win1, A_BLINK);
	mvwin(win1, by, bx);
	overlay(win, win1);
	mvwin(win1, 14, 25);
	wmove(win1, 8, 26);
	wrefresh(win1);
	wgetch(win1);
	delwin(win1);
    }

    clear();
    wclear(win);
    wrefresh(win);
    MvWAddStr(win, 6, 2, "This line shouldn't appear");
    MvWAddStr(win, 4, 2, "Only half of the next line is visible");
    MvWAddStr(win, 5, 2, "Only half of the next line is visible");
    wmove(win, 6, 1);
    wclrtobot(win);
    wmove(win, 5, 20);
    wclrtoeol(win);
    MvWAddStr(win, 8, 2, "This line also shouldn't appear");
    wmove(win, 8, 1);
    wdeleteln(win);
    Continue(win);

    wmove(win, 5, 9);
    ch = winch(win);

    wclear(win);
    wmove(win, 6, 2);
    waddstr(win, "The next char should be l:  ");
    winsch(win, ch);
    Continue(win);

#if HAVE_WINSSTR
    (void) mvwinsstr(win, 6, 2, "A1B2C3D4E5");
    Continue(win);
#endif

    wmove(win, 5, 1);
    winsertln(win);
    MvWAddStr(win, 5, 2, "The lines below should have moved down");
    Continue(win);

    wclear(win);
    wmove(win, 2, 2);
    wprintw(win, "This is a formatted string in a window: %d %s\n", 42,
	    "is it");
    MvWAddStr(win, 10, 1, "Enter a string: ");
    wrefresh(win);
    noraw();
    echo();
    *Buffer = 0;
    wscanw(win, "%s", Buffer);

    printw("This is a formatted string in stdscr: %d %s\n", 42, "is it");
    MvAddStr(10, 1, "Enter a string: ");
    *Buffer = 0;
    scanw("%s", Buffer);

    if (TIGETSTR("cvvis", "vs") != 0) {
	wclear(win);
	curs_set(2);
	MvWAddStr(win, 1, 1, "The cursor should appear as a block (visible)");
	Continue(win);
    }

    if (TIGETSTR("civis", "vi") != 0) {
	wclear(win);
	curs_set(0);
	MvWAddStr(win, 1, 1,
		  "The cursor should have disappeared (invisible)");
	Continue(win);
    }

    if (TIGETSTR("cnorm", "ve") != 0) {
	wclear(win);
	curs_set(1);
	MvWAddStr(win, 1, 1, "The cursor should be an underline (normal)");
	Continue(win);
    }
#ifdef A_COLOR
    if (has_colors()) {
	wclear(win);
	MvWAddStr(win, 1, 1, "Colors should change after you press a key");
	Continue(win);
	init_pair(1, COLOR_RED, COLOR_WHITE);
	wrefresh(win);
    }
#endif

    werase(win);

#if HAVE_TERMNAME
    MvWAddStr(win, 1, 1, "Information About Your Terminal");
    MvWAddStr(win, 3, 1, termname());
    MvWAddStr(win, 4, 1, longname());
    if (termattrs() & A_BLINK)
	MvWAddStr(win, 5, 1, "This terminal supports blinking.");
    else
	MvWAddStr(win, 5, 1, "This terminal does NOT support blinking.");
#endif

    (void) mvwaddnstr(win, 7, 5, "Have a nice day!ok", 16);
    wrefresh(win);

    (void) mvwinnstr(win, 7, 5, Buffer, 18);
    MvAddStr(LINES - 2, 10, Buffer);
    refresh();
    Continue(win);
}