Beispiel #1
0
/* find_moves():
 * Find possible moves
 */
static const char *
find_moves(void)
{
        int x, y;
        COORD test;
        const char *m;
        char *a;
        static const char moves[] = ".hjklyubn";
        static char ans[sizeof moves];
        a = ans;

        for (m = moves; *m; m++) {
                test.x = My_pos.x + xinc(*m);
                test.y = My_pos.y + yinc(*m);
                move(test.y, test.x);
                switch(winch(stdscr)) {
                case ' ':
                case PLAYER:
                        for (x = test.x - 1; x <= test.x + 1; x++) {
                                for (y = test.y - 1; y <= test.y + 1; y++) {
                                        move(y, x);
                                        if (winch(stdscr) == ROBOT)
						goto bad;
                                }
                        }
                        *a++ = *m;
                }
        bad:;
        }
        *a = 0;
        if (ans[0])
                return ans;
        else
                return "t";
}
Beispiel #2
0
erase_all()
{
	PLANE	*pp;

	for (pp = air.head; pp != NULL; pp = pp->next) {
		wmove(cleanradar, pp->ypos, pp->xpos * 2);
		wmove(radar, pp->ypos, pp->xpos * 2);
		waddch(radar, winch(cleanradar));
		wmove(cleanradar, pp->ypos, pp->xpos * 2 + 1);
		wmove(radar, pp->ypos, pp->xpos * 2 + 1);
		waddch(radar, winch(cleanradar));
	}
}
task main()
{
	servo[sCubes] = 126;
	waitForStart();

	while(true)
	{
		getJoystickSettings(joystick);  // Update Buttons and Joysticks
		if(!bDisconnected)//makes  sure robot is still connected to Samantha
		{
			sniperCheck();
			drive();
			flag();
			lift();
			liftLimit();
			winch();
			dispenser();
			//all of the above code runs the methods that control all the motorized parts of our robot.
			wait1Msec(10); //a wait to ensure that multiple signals do not stack and to prevent lag.
		}
		else
		{
			motor[Left] = 0;
			motor[Right] = 0;
			motor[mLift] = 0;
			motor[mFlag] = 0;
			motor[mWinch1] = motor[mWinch2] = 0;
			servo[sCubes] = 126;
		}
	}
}
Beispiel #4
0
static void
drawmove(chtype tchar, int oldy, int oldx, int row, int column)
/* place the stars, update board & currents */
{
    if (movecount <= 1) {
	int i, j;

	for (i = 0; i < BDEPTH; i++) {
	    for (j = 0; j < BWIDTH; j++) {
		if (movecount == 0) {
		    unmarkcell(i, j);
		} else {
		    cellmove(i, j);
		    if (winch(boardwin) == minus)
			waddch(boardwin, movecount ? ' ' : minus);
		}
	    }
	}
    } else {
	markcell(tchar, oldy, oldx);
	mark_possibles(oldy, oldx, ' ');
    }

    if (row >= 0 && column >= 0) {
	markcell(trail, row, column);
	mark_possibles(row, column, minus);
	board[row][column] = TRUE;
    }

    wprintw(msgwin, "\nMove %d", movecount);
    if (trialcount != movecount)
	wprintw(msgwin, " (%d tries)", trialcount);
    wclrtoeol(msgwin);
}
Beispiel #5
0
chtype mvinch(int y, int x)
{
    if (move(y, x) == ERR)
        return (chtype)ERR;

    return( winch( stdscr));
}
Beispiel #6
0
chtype mvwinch(WINDOW *win, int y, int x)
{
    if (wmove(win, y, x) == ERR)
        return (chtype)ERR;

    return( winch( win));
}
Beispiel #7
0
/*
 * Draw shadows along the right and bottom edge to give a more 3D look
 * to the boxes
 */
void draw_shadow(WINDOW * win, int y, int x, int height, int width)
{
	int i;

	if (has_colors()) {	/* Whether terminal supports color? */
		wattrset(win, dlg.shadow.atr);
		wmove(win, y + height, x + 2);
		for (i = 0; i < width; i++)
			waddch(win, winch(win) & A_CHARTEXT);
		for (i = y + 1; i < y + height + 1; i++) {
			wmove(win, i, x + width);
			waddch(win, winch(win) & A_CHARTEXT);
			waddch(win, winch(win) & A_CHARTEXT);
		}
		wnoutrefresh(win);
	}
}
Beispiel #8
0
/*
 * cl_deleteln --
 *	Delete the current line, scrolling all lines below it.
 *
 * PUBLIC: int cl_deleteln __P((SCR *));
 */
int
cl_deleteln(SCR *sp)
{
	CHAR_T ch;
	CL_PRIVATE *clp;
	WINDOW *win;
	size_t col, lno, spcnt, y, x;

	clp = CLP(sp);
	win = CLSP(sp) ? CLSP(sp) : stdscr;

	/*
	 * This clause is required because the curses screen uses reverse
	 * video to delimit split screens.  If the screen does not do this,
	 * this code won't be necessary.
	 *
	 * If the bottom line was in reverse video, rewrite it in normal
	 * video before it's scrolled.
	 *
	 * Check for the existence of a chgat function; XSI requires it, but
	 * historic implementations of System V curses don't.   If it's not
	 * a #define, we'll fall back to doing it by hand, which is slow but
	 * acceptable.
	 *
	 * By hand means walking through the line, retrieving and rewriting
	 * each character.  Curses has no EOL marker, so track strings of
	 * spaces, and copy the trailing spaces only if there's a non-space
	 * character following.
	 */
	if (!F_ISSET(sp, SC_SCR_EXWROTE) && IS_SPLIT(sp)) {
		getyx(win, y, x);
#ifdef mvchgat
		mvwchgat(win, RLNO(sp, LASTLINE(sp)), 0, -1, A_NORMAL, 0, NULL);
#else
		for (lno = RLNO(sp, LASTLINE(sp)), col = spcnt = 0;;) {
			(void)wmove(win, lno, col);
			ch = winch(win);
			if (isblank(ch))
				++spcnt;
			else {
				(void)wmove(win, lno, col - spcnt);
				for (; spcnt > 0; --spcnt)
					(void)waddch(win, ' ');
				(void)waddch(win, ch);
			}
			if (++col >= sp->cols)
				break;
		}
#endif
		(void)wmove(win, y, x);
	}

	/*
	 * The bottom line is expected to be blank after this operation,
	 * and other screens must support that semantic.
	 */
	return (wdeleteln(win) == ERR);
}
Beispiel #9
0
    void BoardView::draw_border(Square &sq, int x, int y)
    {
        if (!border_enabled)
            return;

		int global_x = x + cursor.offset_x;
		int global_y = y + cursor.offset_y;

        bool needs_l_border = global_x % NM_CHUNK_SIZE == 0;
        bool needs_r_border = (global_x + 1) % NM_CHUNK_SIZE == 0;
        bool needs_t_border = false;//global_y % NM_CHUNK_SIZE == 0;
        bool needs_b_border = (global_y + 1) % NM_CHUNK_SIZE == 0 && !needs_r_border && !needs_l_border;

        if (needs_l_border)
        {
            main << Move({3 * x, y}) << AttrOn(COLOR_PAIR(BORDER_COLOR))
                 << " " << AttrOff(COLOR_PAIR(BORDER_COLOR));
        }

        if (needs_r_border)
        {
            main << Move({3 * x + 2, y}) << AttrOn(COLOR_PAIR(BORDER_COLOR))
                 << " " << AttrOff(COLOR_PAIR(BORDER_COLOR));
        }

        if (needs_t_border)
        {
            main << Move({3 * x + 1, y});
            char data = winch(main) & A_CHARTEXT;
            data = isdigit(data) ? data : ' ';
            main << data << "\u035e";
        }

        if (needs_b_border)
        {
            main << Move({3 * x + 1, y});
            char data = winch(main) & A_CHARTEXT;
            main << Move({3 * x, y});
            int color = (sq.state == SquareState::CLOSED) ? 12 : 6;
            main << AttrOn(A_UNDERLINE) << AttrOn(COLOR_PAIR(color))
                 << " " << data << " " << AttrOff(COLOR_PAIR(color)) << AttrOff(A_UNDERLINE);
        }
    }
Beispiel #10
0
/*
 * Check if the cursor is on a valid edit-position.  This must be one of
 * the non-blank cells in the field.
 */
static int validEditPosition(CDKUSCALE *widget, int newPosition)
{
    chtype ch;
    if (newPosition <= 0 || newPosition >= widget->fieldWidth)
        return FALSE;
    if (moveToEditPosition(widget, newPosition) == ERR)
        return FALSE;
    ch = winch(widget->fieldWin);
    if (CharOf(ch) != ' ')
        return TRUE;
    if (newPosition > 1)
    {
        /* don't use recursion - only one level is wanted */
        if (moveToEditPosition(widget, newPosition - 1) == ERR)
            return FALSE;
        ch = winch(widget->fieldWin);
        return CharOf(ch) != ' ';
    }
    return FALSE;
}
Beispiel #11
0
/*
 * Read the character at the indicated position in win
 */
int
readwin(WINDOW *win, int line, int col)
{
	int oldline, oldcol;
	int c;

	getyx(win, oldline, oldcol);
	wmove(win, line, col);
	c = winch(win);
	wmove(win, oldline, oldcol);
	return (c);
}
Beispiel #12
0
void
newpos(struct body *bp)
{
	if (visible_len == (LINES-3) * (COLS-3) - 1) {
		endwin();
		printf("\nYou won!\nYour final score was %d\n\n", score);
		exit(0);
	}
	do {
		bp->y = rnd(LINES-3)+ 1;
		bp->x = rnd(COLS-3) + 1;
		wmove(tv, bp->y, bp->x);
	} while(winch(tv) != ' ');
}
Beispiel #13
0
void
init(int argc, gtm_char_t *name)
{
	struct sigaction action;

	if (argc != 1)
		return;

	strncpy(env, name, 31);
	env[31] = '\0';

	winch(SIGWINCH);

	sigemptyset(&action.sa_mask);
	action.sa_flags = 0;
	action.sa_handler = winch;
	sigaction(SIGWINCH, &action, &prev);
}
Beispiel #14
0
/*---------------------------------------------------------------------------
|   Facility      :  libnform  
|   Function      :  static char * Only_Padding(
|                                    WINDOW *w,
|                                    int len,
|                                    int pad)
|   
|   Description   :  Test if 'length' cells starting at the current position
|                    contain a padding character.
|
|   Return Values :  true if only padding cells are found
+--------------------------------------------------------------------------*/
NCURSES_INLINE static bool
Only_Padding(WINDOW *w, int len, int pad)
{
  bool result = TRUE;
  int y, x, j;
  FIELD_CELL cell;

  getyx(w, y, x);
  for (j = 0; j < len; ++j)
    {
      if (wmove(w, y, x + j) != ERR)
	{
#if USE_WIDEC_SUPPORT
	  if (win_wch(w, &cell) != ERR)
	    {
	      if ((chtype)CharOf(cell) != ChCharOf(pad)
		  || cell.chars[1] != 0)
		{
		  result = FALSE;
		  break;
		}
	    }
#else
	  cell = winch(w);
	  if (ChCharOf(cell) != ChCharOf(pad))
	    {
	      result = FALSE;
	      break;
	    }
#endif
	}
      else
	{
	  /* if an error, return true: no non-padding text found */
	  break;
	}
    }
  /* no need to reset the cursor position; caller does this */
  return result;
}
Beispiel #15
0
NCURSES_EXPORT(chtype) (mvwinch) (WINDOW * a1, int a2, int z)
{
	T((T_CALLED("mvwinch(%p,%d,%d)"), (const void *)a1, a2, z)); returnChtype((wmove(a1,a2,z) == (-1) ? (chtype)((-1)) : winch(a1)));
}
Beispiel #16
0
NCURSES_EXPORT(chtype) (inch) (void)
{
	T((T_CALLED("inch()"))); returnChtype(winch(stdscr));
}
EIF_INTEGER c_ecurses_winch (EIF_POINTER w)
{
    return  winch((WINDOW *) w);
};
Beispiel #18
0
chtype
mvwinch(WINDOW *win, int y, int x)
{
	return (wmove(win, y, x) == ERR ? (chtype) ERR : winch(win));
}
Beispiel #19
0
//------------------------------------------------------------------------------
chtype inch( void )
{
    __QCS_FCONTEXT( "inch" );

    return winch( stdscr );
}
Beispiel #20
0
void outputTest(WINDOW *win)
{
    WINDOW *win1;
    char Buffer[80];
    chtype ch;
    int by, bx;

    nl();
    wclear(win);
    mvwaddstr(win, 1, 1, "You should now have a screen in the upper "
                         "left corner, and this text should have wrapped");
    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, COLOR_PAIR(3));
        }
        else
#endif
            wbkgd(win1, A_NORMAL);

        wclear(win1);
        mvwaddstr(win1, 5, 1, "This text should appear; using overlay option");
        copywin(win, win1, 0, 0, 0, 0, 9, 49, TRUE);
        box(win1, ACS_VLINE, ACS_HLINE);
        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);
    winsdelln(win, -1);
    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);

    mvwinsstr(win, 6, 2, "A1B2C3D4E5");
    Continue(win);

    wmove(win, 5, 1);
    winsdelln(win, 1);
    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);
    echo();
    wscanw(win, "%s", Buffer);

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

    wclear(win);
    curs_set(2);
    mvwaddstr(win, 1, 1, "The cursor should be in high-visibility mode");
    Continue(win);

    wclear(win);
    curs_set(0);
    mvwaddstr(win, 1, 1, "The cursor should have disappeared");
    Continue(win);

    wclear(win);
    curs_set(1);
    mvwaddstr(win, 1, 1, "The cursor should be 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);
    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 claims to support blinking.");
    else
        mvwaddstr(win, 5, 1, "This terminal does NOT support blinking.");

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

    mvwinnstr(win, 7, 5, Buffer, 18);
    mvaddstr(LINES - 2, 10, Buffer);
    refresh();
    Continue(win);
}
Beispiel #21
0
chtype inch(void)
{
    return winch(stdscr);
}
Beispiel #22
0
static void
repaint_text(MY_OBJ * obj)
{
    WINDOW *dialog = obj->obj.win;
    int i, x;

    if (dialog != 0 && obj->obj.input != 0) {
	(void) werase(dialog);
	dlg_draw_box2(dialog, 0, 0, obj->height, obj->width, dialog_attr,
		      border_attr, border2_attr);

	dlg_draw_title(dialog, obj->title);

	(void) wattrset(dialog, dialog_attr);
	dlg_draw_helpline(dialog, FALSE);
	dlg_print_autowrap(dialog, obj->prompt, obj->height, obj->width);

	dlg_draw_box2(dialog,
		      obj->height - 4, 2 + MARGIN,
		      2 + MARGIN, obj->width - 2 * (2 + MARGIN),
		      dialog_attr,
		      border_attr,
		      border2_attr);

	/*
	 * Clear the area for the progress bar by filling it with spaces
	 * in the gauge-attribute, and write the percentage with that
	 * attribute.
	 */
	(void) wmove(dialog, obj->height - 3, 4);
	(void) wattrset(dialog, gauge_attr);

	for (i = 0; i < (obj->width - 2 * (3 + MARGIN)); i++)
	    (void) waddch(dialog, ' ');

	(void) wmove(dialog, obj->height - 3, (obj->width / 2) - 2);
	(void) wprintw(dialog, "%3d%%", obj->percent);

	/*
	 * Now draw a bar in reverse, relative to the background.
	 * The window attribute was useful for painting the background,
	 * but requires some tweaks to reverse it.
	 */
	x = (obj->percent * (obj->width - 2 * (3 + MARGIN))) / 100;
	if ((gauge_attr & A_REVERSE) != 0) {
	    wattroff(dialog, A_REVERSE);
	} else {
	    (void) wattrset(dialog, A_REVERSE);
	}
	(void) wmove(dialog, obj->height - 3, 4);
	for (i = 0; i < x; i++) {
	    chtype ch2 = winch(dialog);
	    if (gauge_attr & A_REVERSE) {
		ch2 &= ~A_REVERSE;
	    }
	    (void) waddch(dialog, ch2);
	}

	(void) wrefresh(dialog);
    }
}
Beispiel #23
0
void
process(int ch)
{
	int x,y;
	struct body *nh;

	x = head->x;
	y = head->y;
	switch(ch)
	{
#ifdef KEY_LEFT
		case KEY_LEFT:
#endif
		case 'h':
			x--; break;
#ifdef KEY_DOWN
		case KEY_DOWN:
#endif
		case 'j':
			y++; break;
#ifdef KEY_UP
		case KEY_UP:
#endif
		case 'k':
			y--; break;
#ifdef KEY_RIGHT
		case KEY_RIGHT:
#endif
		case 'l':
			x++; break;
		case 'H': x--; running = RUNLEN; ch = tolower(ch); break;
		case 'J': y++; running = RUNLEN/2; ch = tolower(ch); break;
		case 'K': y--; running = RUNLEN/2; ch = tolower(ch); break;
		case 'L': x++; running = RUNLEN; ch = tolower(ch); break;
		case '\f': setup(); return;
		case CNTRL('Z'): suspend(0); return;
		case CNTRL('C'): crash(); return;
		case CNTRL('D'): crash(); return;
		case ERR: leave(0); return;
		default: return;
	}
	lastch = ch;
	if (growing == 0)
	{
		display(tail, ' ');
		tail->next->prev = NULL;
		nh = tail->next;
		free(tail);
		tail = nh;
		visible_len--;
	}
	else growing--;
	display(head, BODY);
	wmove(tv, y, x);
	if (isdigit(ch = winch(tv)))
	{
		growing += ch-'0';
		prize();
		score += growing;
		running = 0;
		wmove(stw, 0, COLS - 12);
		wprintw(stw, "Score: %3d", score);
		wrefresh(stw);
	}
	else if(ch != ' ') crash();
	nh = newlink();
	nh->next = NULL;
	nh->prev = head;
	head->next = nh;
	nh->y = y;
	nh->x = x;
	display(nh, HEAD);
	head = nh;
	visible_len++;
	if (!(slow && running)) {
		wmove(tv, head->y, head->x);
		wrefresh(tv);
	}
}
Beispiel #24
0
static void
play(void)
/* play the game */
{
    bool keyhelp;		/* TRUE if keystroke help is up */
    int i, j, count;
    int lastcol = 0;		/* last location visited */
    int lastrow = 0;
    int ny = 0, nx = 0;
    int review = 0;		/* review history */
    int rw = 0, col = 0;	/* current row and column */

    do {
	/* clear screen and draw board */
	werase(boardwin);
	werase(helpwin);
	werase(msgwin);
	dosquares();
	help1();
	wnoutrefresh(stdscr);
	wnoutrefresh(helpwin);
	wnoutrefresh(msgwin);
	wnoutrefresh(boardwin);
	doupdate();

	movecount = 0;
	for (i = 0; i < BDEPTH; i++) {
	    for (j = 0; j < BWIDTH; j++) {
		board[i][j] = FALSE;
		unmarkcell(i, j);
	    }
	}
	memset(history, 0, sizeof(history));
	history[0].y = history[0].x = -1;
	history[1].y = history[1].x = -1;
	lastrow = lastcol = -2;
	movecount = 1;
	trialcount = 1;
	keyhelp = FALSE;
	show_help(&keyhelp);

	for (;;) {
	    if (rw != lastrow || col != lastcol) {
		if (lastrow >= 0 && lastcol >= 0) {
		    cellmove(lastrow, lastcol);
		    if (board[lastrow][lastcol])
			waddch(boardwin, trail);
		    else
			waddch(boardwin, oldch);
		}

		cellmove(rw, col);
		oldch = winch(boardwin);

		lastrow = rw;
		lastcol = col;
	    }
	    cellmove(rw, col);
	    waddch(boardwin, plus);
	    cellmove(rw, col);

	    wrefresh(msgwin);

	    switch (wgetch(boardwin)) {
	    case 'k':
	    case '8':
	    case KEY_UP:
		ny = rw + BDEPTH - 1;
		nx = col;
		break;
	    case 'j':
	    case '2':
	    case KEY_DOWN:
		ny = rw + 1;
		nx = col;
		break;
	    case 'h':
	    case '4':
	    case KEY_LEFT:
		ny = rw;
		nx = col + BWIDTH - 1;
		break;
	    case 'l':
	    case '6':
	    case KEY_RIGHT:
		ny = rw;
		nx = col + 1;
		break;
	    case 'y':
	    case '7':
	    case KEY_A1:
		ny = rw + BDEPTH - 1;
		nx = col + BWIDTH - 1;
		break;
	    case 'b':
	    case '1':
	    case KEY_C1:
		ny = rw + 1;
		nx = col + BWIDTH - 1;
		break;
	    case 'u':
	    case '9':
	    case KEY_A3:
		ny = rw + BDEPTH - 1;
		nx = col + 1;
		break;
	    case 'n':
	    case '3':
	    case KEY_C3:
		ny = rw + 1;
		nx = col + 1;
		break;

#ifdef NCURSES_MOUSE_VERSION
	    case KEY_MOUSE:
		{
		    MEVENT myevent;

		    getmouse(&myevent);
		    if (myevent.y >= CY(0) && myevent.y <= CY(BDEPTH)
			&& myevent.x >= CX(0) && myevent.x <= CX(BWIDTH)) {
			nx = CXINV(myevent.x);
			ny = CYINV(myevent.y);
			ungetch('\n');
			break;
		    } else {
			beep();
			continue;
		    }
		}
#endif /* NCURSES_MOUSE_VERSION */

	    case KEY_B2:
	    case '\n':
	    case ' ':
		review = 0;
		if (evalmove(rw, col)) {
		    drawmove(trail,
			     history[movecount - 1].y,
			     history[movecount - 1].x,
			     rw, col);
		    history[movecount].y = (short) rw;
		    history[movecount].x = (short) col;
		    movecount++;
		    trialcount++;

		    if (!chkmoves(rw, col)) {
			if (completed() < 0) {
			    waddstr(msgwin, "\nYou won.");
			} else {
			    waddstr(msgwin,
				    "\nNo further moves are possible.");
			}
		    }
		} else {
		    beep();
		}
		break;

	    case KEY_UNDO:
	    case KEY_BACKSPACE:
	    case '\b':
		review = 0;
		if (movecount <= 0) {
		    no_previous_move();
		} else if (movecount <= 1) {
		    ny = history[movecount].y;
		    nx = history[movecount].x;
		    if (nx < 0 || ny < 0) {
			ny = lastrow;
			nx = lastcol;
		    }
		    movecount = 0;
		    board[ny][nx] = FALSE;
		    oldch = minus;
		    drawmove(' ', ny, nx, -1, -1);
		    movecount = 1;
		    trialcount = 1;
		    no_previous_move();
		} else {
		    int oldy = history[movecount - 1].y;
		    int oldx = history[movecount - 1].x;

		    if (!board[rw][col]) {
			cellmove(rw, col);
			waddch(boardwin, ' ');
		    }

		    board[oldy][oldx] = FALSE;
		    --movecount;
		    ny = history[movecount - 1].y;
		    nx = history[movecount - 1].x;
		    if (nx < 0 || ny < 0) {
			ny = oldy;
			nx = oldx;
		    }
		    drawmove(' ', oldy, oldx, ny, nx);

		    /* avoid problems if we just changed the current cell */
		    cellmove(lastrow, lastcol);
		    oldch = winch(boardwin);
		}
		break;

	    case 'a':
		nx = col;
		ny = rw;
		find_next_move(&ny, &nx);
		break;

	    case 'F':
		if (review > 0) {
		    review--;
		    ny = history[movecount - review - 1].y;
		    nx = history[movecount - review - 1].x;
		} else {
		    beep();
		}
		break;

	    case 'B':
		if (review < movecount - 2) {
		    review++;
		    ny = history[movecount - review - 1].y;
		    nx = history[movecount - review - 1].x;
		} else {
		    beep();
		}
		break;

	    case KEY_REDO:
	    case '\f':
	    case 'r':
		clearok(curscr, TRUE);
		wnoutrefresh(stdscr);
		wnoutrefresh(boardwin);
		wnoutrefresh(msgwin);
		wnoutrefresh(helpwin);
		doupdate();
		break;

	    case 'q':
	    case 'x':
		goto dropout;

	    case '?':
		show_help(&keyhelp);
		break;

	    default:
		beep();
		break;
	    }

	    col = nx % BWIDTH;
	    rw = ny % BDEPTH;
	}

      dropout:
	if ((count = completed()) < 0)
	    wprintw(msgwin, "\nYou won.  Care to try again? ");
	else
	    wprintw(msgwin, "\n%d squares filled.  Try again? ", count);
	wclrtoeol(msgwin);
    } while
	(tolower(wgetch(msgwin)) == 'y');
}
/*
 * Display a gauge, or progress meter.  Starts at percent% and reads stdin.  If
 * stdin is not XXX, then it is interpreted as a percentage, and the display is
 * updated accordingly.  Otherwise the next line is the percentage, and
 * subsequent lines up to another XXX are used for the new prompt.  Note that
 * the size of the window never changes, so the prompt can not get any larger
 * than the height and width specified.
 */
int
dialog_gauge(const char *title,
	     const char *prompt,
	     int height,
	     int width,
	     int percent)
{
    int i, x, y;
    char buf[MY_LEN];
    char prompt_buf[MY_LEN];
    WINDOW *dialog;

    auto_size(title, prompt, &height, &width, MIN_HIGH, MIN_WIDE);
    print_size(height, width);
    ctl_size(height, width);

    /* center dialog box on screen */
    x = box_x_ordinate(width);
    y = box_y_ordinate(height);

    dialog = new_window(height, width, y, x);

    curs_set(0);
    do {
	(void) werase(dialog);
	draw_box(dialog, 0, 0, height, width, dialog_attr, border_attr);

	draw_title(dialog, title);

	wattrset(dialog, dialog_attr);
	print_autowrap(dialog, prompt, height, width - (2 * MARGIN));

	draw_box(dialog,
		 height - 4, 2 + MARGIN,
		 2 + MARGIN, width - 2 * (2 + MARGIN),
		 dialog_attr,
		 border_attr);

	(void) wmove(dialog, height - 3, 4);
	wattrset(dialog, title_attr);

	for (i = 0; i < (width - 2 * (3 + MARGIN)); i++)
	    (void) waddch(dialog, ' ');

	wattrset(dialog, title_attr);
	(void) wmove(dialog, height - 3, (width / 2) - 2);
	(void) wprintw(dialog, "%3d%%", percent);

	x = (percent * (width - 2 * (3 + MARGIN))) / 100;
	wattrset(dialog, A_REVERSE);
	(void) wmove(dialog, height - 3, 4);
	for (i = 0; i < x; i++)
	    (void) waddch(dialog, winch(dialog));

	(void) wrefresh(dialog);

	if (read_data(buf, pipe_fp) == 0)
	    break;
	if (isMarker(buf)) {
	    /*
	     * Historically, next line should be percentage, but one of the
	     * worse-written clones of 'dialog' assumes the number is missing.
	     * (Gresham's Law applied to software).
	     */
	    if (read_data(buf, pipe_fp) == 0)
		break;
	    prompt_buf[0] = '\0';
	    if (decode_percent(buf))
		percent = atoi(buf);
	    else
		strcpy(prompt_buf, buf);

	    /* Rest is message text */
	    while (read_data(buf, pipe_fp) != 0
		   && !isMarker(buf)) {
		if (strlen(prompt_buf) + strlen(buf) < sizeof(prompt_buf) - 1) {
		    strcat(prompt_buf, buf);
		}
	    }
	    prompt = prompt_buf;
	} else if (decode_percent(buf)) {
	    percent = atoi(buf);
	}
    } while (1);

    curs_set(1);
    del_window(dialog);
    return (DLG_EXIT_OK);
}
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);
}
Beispiel #27
0
NCURSES_EXPORT(chtype) (mvinch) (int a1, int z)
{
	T((T_CALLED("mvinch(%d,%d)"), a1, z)); returnChtype((wmove(stdscr,a1,z) == (-1) ? (chtype)((-1)) : winch(stdscr)));
}