示例#1
0
/*
 * ip_addstr --
 *	Add len bytes from the string at the cursor, advancing the cursor.
 *
 * PUBLIC: int ip_addstr __P((SCR *, const char *, size_t));
 */
int
ip_addstr(SCR *sp, const char *str, size_t len)
{
	IP_BUF ipb;
	IP_PRIVATE *ipp;
	int iv, rval;

	ipp = IPP(sp);

	/*
	 * If ex isn't in control, it's the last line of the screen and
	 * it's a split screen, use inverse video.
	 */
	iv = 0;
	if (!F_ISSET(sp, SC_SCR_EXWROTE) &&
	    ipp->row == LASTLINE(sp) && IS_SPLIT(sp)) {
		iv = 1;
		ip_attr(sp, SA_INVERSE, 1);
	}
	ipb.code = SI_ADDSTR;
	ipb.len1 = len;
	ipb.str1 = str;
	rval = vi_send(ipp->o_fd, "a", &ipb);
	/* XXXX */
	ipp->col += len;

	if (iv)
		ip_attr(sp, SA_INVERSE, 0);
	return (rval);
}
示例#2
0
文件: cl_funcs.c 项目: Hooman3/minix
static int 
addstr4(SCR *sp, const void *str, size_t len, int wide)
{
	WINDOW *win;
	size_t y, x;
	int iv;

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

	/*
	 * If ex isn't in control, it's the last line of the screen and
	 * it's a split screen, use inverse video.
	 */
	iv = 0;
	getyx(win, y, x);
	__USE(x);
	if (!F_ISSET(sp, SC_SCR_EXWROTE) &&
	    y == RLNO(sp, LASTLINE(sp)) && IS_SPLIT(sp)) {
		iv = 1;
		(void)wstandout(win);
	}

#ifdef USE_WIDECHAR
	if (wide) {
	    if (waddnwstr(win, str, len) == ERR)
		return (1);
	} else 
#endif
	    if (waddnstr(win, str, len) == ERR)
		    return (1);

	if (iv)
		(void)wstandend(win);
	return (0);
}
示例#3
0
/*
 * ip_deleteln --
 *	Delete the current line, scrolling all lines below it.
 *
 * PUBLIC: int ip_deleteln __P((SCR *));
 */
int
ip_deleteln(SCR *sp)
{
	IP_BUF ipb;
	IP_PRIVATE *ipp = IPP(sp);

	/*
	 * 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.
	 */
	if (!F_ISSET(sp, SC_SCR_EXWROTE) && IS_SPLIT(sp)) {
		ipb.code = SI_REWRITE;
		ipb.val1 = RLNO(sp, LASTLINE(sp));
		if (vi_send(ipp->o_fd, "1", &ipb))
			return (1);
	}

	/*
	 * The bottom line is expected to be blank after this operation,
	 * and other screens must support that semantic.
	 */
	ipb.code = SI_DELETELN;
	return (vi_send(ipp->o_fd, NULL, &ipb));
}
示例#4
0
文件: v_scroll.c 项目: lichray/nvi2
/*
 * v_pagedown -- [count]^F
 *	Page down full screens.
 * !!!
 * Historic vi did not move to the EOF if the screen couldn't move, i.e.
 * if EOF was already displayed on the screen.  This implementation does
 * move to EOF in that case, making ^F more like the historic ^D.
 *
 * PUBLIC: int v_pagedown(SCR *, VICMD *);
 */
int
v_pagedown(SCR *sp, VICMD *vp)
{
	recno_t offset;

	/*
	 * !!!
	 * The calculation in IEEE Std 1003.2-1992 (POSIX) is:
	 *
	 *	top_line = top_line + count * (window - 2);
	 *
	 * which was historically wrong.  The correct one is:
	 *
	 *	top_line = top_line + count * window - 2;
	 *
	 * i.e. the two line "overlap" was only subtracted once.  Which
	 * makes no sense, but then again, an overlap makes no sense for
	 * any screen but the "next" one anyway.  We do it the historical
	 * way as there's no good reason to change it.
	 *
	 * If the screen has been split horizontally, use the smaller of
	 * the current window size and the window option value.
	 *
	 * It possible for this calculation to be less than 1; move at
	 * least one line.
	 */
	offset = (F_ISSET(vp, VC_C1SET) ? vp->count : 1) * (IS_SPLIT(sp) ?
	    MIN(sp->t_maxrows, O_VAL(sp, O_WINDOW)) : O_VAL(sp, O_WINDOW));
	offset = offset <= 2 ? 1 : offset - 2;
	if (vs_sm_scroll(sp, &vp->m_stop, offset, CNTRL_F))
		return (1);
	vp->m_final = vp->m_stop;
	return (0);
}
示例#5
0
文件: cl_funcs.c 项目: fishman/nvi
/*
 * 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);
}
示例#6
0
文件: input.c 项目: LokiChaos/tintin
void process_input(void)
{
	if (HAS_BIT(gtd->ses->telopts, TELOPT_FLAG_SGA) && !HAS_BIT(gtd->ses->telopts, TELOPT_FLAG_ECHO))
	{
		read_key();
	}
	else
	{
		read_line();
	}

	if (!HAS_BIT(gtd->flags, TINTIN_FLAG_PROCESSINPUT))
	{
		return;
	}

	DEL_BIT(gtd->flags, TINTIN_FLAG_PROCESSINPUT);

	if (gtd->chat && gtd->chat->paste_time)
	{
		chat_paste(gtd->input_buf, NULL);

		return;
	}

	if (HAS_BIT(gtd->ses->telopts, TELOPT_FLAG_ECHO))
	{
		add_line_history(gtd->ses, gtd->input_buf);
	}

	if (HAS_BIT(gtd->ses->telopts, TELOPT_FLAG_ECHO))
	{
		echo_command(gtd->ses, gtd->input_buf);
	}
	else
	{
		echo_command(gtd->ses, "");
	}

	if (gtd->ses->scroll_line != -1)
	{
		buffer_end(gtd->ses, "");
	}

	check_all_events(gtd->ses, SUB_ARG|SUB_SEC, 0, 1, "RECEIVED INPUT", gtd->input_buf);

	gtd->ses = script_driver(gtd->ses, LIST_COMMAND, gtd->input_buf);

	if (IS_SPLIT(gtd->ses))
	{
		erase_toeol();
	}

	gtd->input_buf[0] = 0;
}
示例#7
0
文件: player.c 项目: thekyz/network
int main(int argc, char *argv[])
{
    void *ctx = zmq_ctx_new();
    char *player_name = argv[1];

    PP("Connecting to server ...\n");
    void *lobby = zmq_socket(ctx, ZMQ_PUSH);
    zmq_connect(lobby, "tcp://localhost:" DEALER_LOBBY_PORT);

    char msg[MAX_MSG_LEN] = "";
    sprintf(msg, A_CONNECTED "%s", player_name);
    zmq_send(lobby, msg, strlen(msg) + 1, 0);

    sleep(1);
    sprintf(msg, A_READY "%s", player_name);
    zmq_send(lobby, msg, strlen(msg) + 1, 0);

    void *table = zmq_socket(ctx, ZMQ_SUB);
    zmq_connect(table, "tcp://localhost:" DEALER_TABLE_PORT);

    const char *msg_filter = F_MSG;
    zmq_setsockopt(table, ZMQ_SUBSCRIBE, F_MSG, strlen(F_MSG));
    zmq_setsockopt(table, ZMQ_SUBSCRIBE, F_GAME, strlen(F_GAME));

    for (;;) {
        memset(msg, 0, sizeof(msg));
        zmq_recv(table, msg, MAX_MSG_LEN, 0);
        msg[MAX_MSG_LEN - 1] = '\0';

      #define IS_MSG(__m) strncmp(msg, __m, strlen(__m)) == 0
        if (IS_MSG(F_MSG)) {
            PP("[D] %s\n", &msg[strlen(F_MSG)]);
        } else if (IS_MSG(F_GAME)) {
            char *split = &msg[strlen(F_GAME)];
            PP("game << %s\n", split);

          #define IS_SPLIT(__m) strncmp(split, __m, strlen(__m)) == 0
            if (IS_SPLIT(G_BET)) {
                char bet[MAX_MSG_LEN] = "";
                sprintf(bet, A_PLAY "%s %s %s", player_name, G_BET, "10");
                /*printf("[C] bet >> %s\n", bet);*/
                zmq_send(lobby, bet, strlen(bet) + 1, 0);
            }
        } else {
            PPE("Error: unknown message filter on table socket !\n");
        }
    }

    return 0;
}
示例#8
0
文件: v_scroll.c 项目: lichray/nvi2
/*
 * v_pageup -- [count]^B
 *	Page up full screens.
 *
 * !!!
 * Historic vi did not move to the SOF if the screen couldn't move, i.e.
 * if SOF was already displayed on the screen.  This implementation does
 * move to SOF in that case, making ^B more like the historic ^U.
 *
 * PUBLIC: int v_pageup(SCR *, VICMD *);
 */
int
v_pageup(SCR *sp, VICMD *vp)
{
	recno_t offset;

	/*
	 * !!!
	 * The calculation in IEEE Std 1003.2-1992 (POSIX) is:
	 *
	 *	top_line = top_line - count * (window - 2);
	 *
	 * which was historically wrong.  The correct one is:
	 *
	 *	top_line = (top_line - count * window) + 2;
	 *
	 * A simpler expression is that, as with ^F, we scroll exactly:
	 *
	 *	count * window - 2
	 *
	 * lines.
	 *
	 * Bizarre.  As with ^F, an overlap makes no sense for anything
	 * but the first screen.  We do it the historical way as there's
	 * no good reason to change it.
	 *
	 * If the screen has been split horizontally, use the smaller of
	 * the current window size and the window option value.
	 *
	 * It possible for this calculation to be less than 1; move at
	 * least one line.
	 */
	offset = (F_ISSET(vp, VC_C1SET) ? vp->count : 1) * (IS_SPLIT(sp) ?
	    MIN(sp->t_maxrows, O_VAL(sp, O_WINDOW)) : O_VAL(sp, O_WINDOW));
	offset = offset <= 2 ? 1 : offset - 2;
	if (vs_sm_scroll(sp, &vp->m_stop, offset, CNTRL_B))
		return (1);
	vp->m_final = vp->m_stop;
	return (0);
}
示例#9
0
int show_buffer(struct session *ses) {
  char temp[STRING_SIZE];
  int scroll_size, scroll_cnt, scroll_tmp, scroll_add, scroll_cut;

  if (ses != gtd->ses) {
    return TRUE;
  }

  scroll_size = get_scroll_size(ses);
  scroll_add = 0 - ses->scroll_base;
  scroll_tmp = 0;
  scroll_cnt = ses->scroll_line;
  scroll_cut = 0;
  /*
     Find the upper limit of the buffer shown
   */

  while (TRUE) {
    if (ses->buffer[scroll_cnt] == NULL) {
      break;
    }

    scroll_tmp = str_hash_lines(ses->buffer[scroll_cnt]);

    if (scroll_add + scroll_tmp > scroll_size) {
      if (scroll_add == scroll_size) {
        scroll_cut = 0;
      } else {
        scroll_cut = scroll_tmp - (scroll_size - scroll_add);
      }
      break;
    }

    scroll_add += scroll_tmp;

    if (scroll_cnt == ses->scroll_max - 1) {
      scroll_cnt = 0;
    } else {
      scroll_cnt++;
    }
  }

  if (ses->buffer[scroll_cnt] == NULL) {
    erase_screen(ses);
  }

  if (IS_SPLIT(ses)) {
    save_pos(ses);
    goto_rowcol(ses, ses->bot_row, 1);
    SET_BIT(ses->flags, SES_FLAG_READMUD);
  }

  /*
     If the top line exists of multiple lines split it in the middle.
   */

  if (ses->buffer[scroll_cnt] && scroll_cut) {
    if (scroll_add >= 0) {
      word_wrap_split(ses, ses->buffer[scroll_cnt], temp, scroll_tmp - scroll_cut, scroll_cut);

      printf("%s\n", temp);
    } else {
      word_wrap_split(ses, ses->buffer[scroll_cnt], temp, ses->scroll_base, scroll_size);

      goto eof;
    }
  }

  /*
     Print away
   */

  while (TRUE) {
    if (scroll_cnt == 0) {
      scroll_cnt = ses->scroll_max - 1;
    } else {
      scroll_cnt--;
    }

    if (ses->buffer[scroll_cnt] == NULL) {
      break;
    }

    scroll_tmp = word_wrap(ses, ses->buffer[scroll_cnt], temp, FALSE);

    if (scroll_add - scroll_tmp < 0) {
      scroll_cut = scroll_add;
      break;
    }

    scroll_add -= scroll_tmp;

    printf("%s\n", temp);
  }

  /*
     If the bottom line exists of multiple lines split it in the middle
   */

  if (scroll_tmp && ses->buffer[scroll_cnt]) {
    word_wrap_split(ses, ses->buffer[scroll_cnt], temp, 0, scroll_cut);
  }

 eof:

  if (IS_SPLIT(ses)) {
    restore_pos(ses);
    DEL_BIT(ses->flags, SES_FLAG_READMUD);
  }
  return TRUE;
}
示例#10
0
文件: prompt.c 项目: SlySven/tintin
void do_one_prompt(struct session *ses, char *prompt, int row)
{
	char temp[BUFFER_SIZE];
	int original_row, len;

	if (ses != gtd->ses)
	{
		return;
	}

	original_row = row;

	if (row < 0)
	{
		row = -1 * row;
	}
	else
	{
		row = ses->rows - row;
	}

	if (row < 1 || row > ses->rows)
	{
		show_message(ses, LIST_PROMPT, "#ERROR: PROMPT ROW IS OUTSIDE THE SCREEN: {%s} {%d}.", prompt, original_row);

		return;
	}

	if (row > ses->top_row && row < ses->bot_row)
	{
		show_message(ses, LIST_PROMPT, "#ERROR: PROMPT ROW IS INSIDE THE SCROLLING REGION: {%s} {%d}.", prompt, original_row);

		return;
	}

	len = strip_vt102_strlen(ses, prompt);

	if (len == 0)
	{
		sprintf(temp, "%.*s", ses->cols + 4, "\033[0m----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------");
	}
	else if (len <= ses->cols)
	{
		sprintf(temp, "%s", prompt);
	}
	else
	{
		show_debug(ses, LIST_PROMPT, "#DEBUG PROMPT {%s}", prompt);

		sprintf(temp, "#PROMPT SIZE (%d) LONGER THAN ROW SIZE (%d)", len, ses->cols);
	}

	if (!HAS_BIT(ses->flags, SES_FLAG_READMUD) && IS_SPLIT(ses))
	{
		save_pos(ses);
	}

	if (row == ses->rows)
	{
		gtd->input_off = len + 1;

		printf("\033[%d;1H\033[%d;1H\033[K%s%s\033[%d;%dH\0337\033[%d;1H", row, row, temp, gtd->input_buf, row, gtd->input_off + gtd->input_cur, ses->bot_row);
	}
	else
	{
		// goto row, erase to eol, print prompt, goto bot_row

		printf("\033[%d;1H\033[%d;1H\033[K%s\033[%d;1H", row, row, temp, ses->bot_row);
	}

	if (!HAS_BIT(ses->flags, SES_FLAG_READMUD) && IS_SPLIT(ses))
	{
		restore_pos(ses);
	}
}