Ejemplo n.º 1
0
// XXX no control for max length here?!?!
R_API int r_cons_fgets(char *buf, int len, int argc, const char **argv) {
#define RETURN(x) { ret=x; goto beach; }
	RCons *cons = r_cons_singleton ();
	int ret = 0, color = cons->pal.input && *cons->pal.input;
	if (cons->echo) {
		r_cons_set_raw (0);
		r_cons_show_cursor (1);
	}
#if 0
	int mouse = r_cons_enable_mouse (false);
	r_cons_enable_mouse (false);
	r_cons_flush ();
#endif
	if (cons->user_fgets) {
		RETURN (cons->user_fgets (buf, len));
	}
	printf ("%s", cons->line->prompt);
	fflush (stdout);
	*buf = '\0';
	fflush (cons->fdin);
	if (color) {
		const char *p = cons->pal.input;
		int len = p? strlen (p): 0;
		if (len>0)
			fwrite (p, len, 1, stdout);
		fflush (stdout);
	}
	if (!fgets (buf, len, cons->fdin)) {
		if (color) {
			printf (Color_RESET);
			fflush (stdout);
		}
		RETURN (-1);
	}
	if (feof (cons->fdin)) {
		if (color) {
			printf (Color_RESET);
		}
		RETURN (-2);
	}
	buf[strlen (buf)-1] = '\0';
	if (color) printf (Color_RESET);
	ret = strlen (buf);
beach:
#if __UNIX__
	if (errno == EINTR) {
		ret = 0;
	}
#endif
	//r_cons_enable_mouse (mouse);
	return ret;
}
Ejemplo n.º 2
0
// XXX no control for max length here?!?!
R_API int r_cons_fgets(char *buf, int len, int argc, const char **argv) {
	RCons *cons = r_cons_singleton ();
	if (cons->user_fgets)
		return cons->user_fgets (buf, len);
	*buf = '\0';
	fflush (cons->fdin);
	if (fgets (buf, len, cons->fdin) == NULL)
		return -1;
	if (feof (cons->fdin))
		return -2;
	buf[strlen (buf)-1] = '\0';
	return strlen (buf);
}
Ejemplo n.º 3
0
static int parseMouseEvent() {
	int ch = r_cons_readchar ();
	/* Skip the x/y coordinates */
#if USE_CLICK
	int x = r_cons_readchar() - 33;
	int y = r_cons_readchar() - 33;
#else
	(void) r_cons_readchar ();
	(void) r_cons_readchar ();
#endif
#if USE_CLICK
	if (ch == 35) {
		/* handle click  */
#define CLICK_DEBUG 1
#if CLICK_DEBUG
		r_cons_gotoxy (0, 0);
		r_cons_printf ("Click at %d %d\n", x, y);
		r_cons_flush ();
#endif
		RCons *cons = r_cons_singleton ();
		if (cons->onclick) {
			cons->onclick (cons->data, x, y);
		}
		r_cons_enable_mouse (false);
		(void)r_cons_readchar ();
		return 0;
	}
#endif
	if (ch != 0x20 && ch >= 64 + 32) {
		/* Grab wheel events only */
		I->mouse_event = 1;
		return "kj"[(ch - (64 + 32))&1];
	}

	// temporary disable the mouse wheel to allow select
	r_cons_enable_mouse (false);
	(void)r_cons_readchar ();
	return 0;
}
Ejemplo n.º 4
0
// XXX no control for max length here?!?!
R_API int r_cons_fgets(char *buf, int len, int argc, const char **argv) {
#define RETURN(x) { ret=x; goto beach; }
    RCons *cons = r_cons_singleton ();
    int ret = 0, color = cons->pal.input && *cons->pal.input;
#if 0
    int mouse = r_cons_enable_mouse (R_FALSE);
    r_cons_enable_mouse (R_FALSE);
    r_cons_flush ();
#endif
    if (cons->user_fgets) {
        RETURN (cons->user_fgets (buf, len));
    }
    *buf = '\0';
    fflush (cons->fdin);
    if (color) {
        const char *p = cons->pal.input;
        int len = p? strlen (p): 0;
        if (len>0)
            fwrite (p, len, 1, stdout);
        fflush (stdout);
    }
    if (fgets (buf, len, cons->fdin) == NULL) {
        if (color) {
            printf (Color_RESET);
            fflush (stdout);
        }
        RETURN (-1);
    }
    if (feof (cons->fdin)) {
        if (color) printf (Color_RESET);
        RETURN (-2);
    }
    buf[strlen (buf)-1] = '\0';
    if (color) printf (Color_RESET);
    ret = strlen (buf);
beach:
    //r_cons_enable_mouse (mouse);
    return ret;
}