Ejemplo n.º 1
0
R_API int r_cons_readchar() {
	char buf[2];
	buf[0] = -1;
#if __WINDOWS__ && !__CYGWIN__ //&& !MINGW32
	#if 1   // if something goes wrong set this to 0. skuater.....
	return readchar_win(0);
	#endif
	BOOL ret;
	DWORD out;
	DWORD mode;
	HANDLE h = GetStdHandle (STD_INPUT_HANDLE);
	GetConsoleMode (h, &mode);
	SetConsoleMode (h, 0); // RAW
	ret = ReadConsole (h, buf, 1, &out, NULL);
	FlushConsoleInputBuffer (h);
	if (!ret) {
		return -1;
	}
	SetConsoleMode (h, mode);
#else
	r_cons_set_raw (1);
	if (read (0, buf, 1) == -1) {
		return -1;
	}
	r_cons_set_raw (0);
#endif
	return r_cons_controlz (buf[0]);
}
Ejemplo n.º 2
0
R_API int r_cons_readchar() {
	void *bed;
	char buf[2];
	buf[0] = -1;
	if (readbuffer_length > 0) {
		int ch = *readbuffer;
		readbuffer_length--;
		memmove (readbuffer, readbuffer + 1, readbuffer_length);
		return ch;
	}
#if __WINDOWS__ && !__CYGWIN__ //&& !MINGW32
	#if 1   // if something goes wrong set this to 0. skuater.....
	return readchar_win(0);
	#endif
	BOOL ret;
	DWORD out;
	DWORD mode;
	HANDLE h = GetStdHandle (STD_INPUT_HANDLE);
	GetConsoleMode (h, &mode);
	SetConsoleMode (h, 0); // RAW
	bed = r_cons_sleep_begin ();
	ret = ReadConsole (h, buf, 1, &out, NULL);
	r_cons_sleep_end (bed);
	FlushConsoleInputBuffer (h);
	if (!ret) {
		return -1;
	}
	SetConsoleMode (h, mode);
#else
	r_cons_set_raw (1);
	bed = r_cons_sleep_begin ();

	// Blocks until either stdin has something to read or a signal happens.
	// This serves to check if the terminal window was resized. It avoids the race
	// condition that could happen if we did not use pselect or select in case SIGWINCH
	// was handled immediately before the blocking call (select or read). The race is
	// prevented from happening by having SIGWINCH blocked process-wide except for in
	// pselect (that is what pselect is for).
	fd_set readfds;
	sigset_t sigmask;
	FD_ZERO (&readfds);
	FD_SET (STDIN_FILENO, &readfds);
	r_signal_sigmask (0, NULL, &sigmask);
	sigdelset (&sigmask, SIGWINCH);
	pselect (STDIN_FILENO + 1, &readfds, NULL, NULL, NULL, &sigmask);
	if (sigwinchFlag != 0) {
		resizeWin ();
	}

	ssize_t ret = read (STDIN_FILENO, buf, 1);
	r_cons_sleep_end (bed);
	if (ret != 1) {
		return -1;
	}
	if (bufactive) {
		r_cons_set_raw (0);
	}
#endif
	return r_cons_controlz (buf[0]);
}
Ejemplo n.º 3
0
R_API int r_cons_readchar() {
	char buf[2];
	buf[0] = -1;
#if __WINDOWS__
	BOOL ret;
	DWORD out;
	DWORD mode;
	HANDLE h = GetStdHandle (STD_INPUT_HANDLE);
	GetConsoleMode (h, &mode);
	SetConsoleMode (h, 0); // RAW
	ret = ReadConsole (h, buf, 1, &out, NULL);
	if (!ret)
		return -1;
	SetConsoleMode (h, mode);
#else
	r_cons_set_raw (1);
	if (read (0, buf, 1)==-1)
		return -1;
	r_cons_set_raw (0);
#endif
	return r_cons_controlz (buf[0]);
}
Ejemplo n.º 4
0
R_API int r_cons_readchar() {
    char buf[2];
    buf[0] = -1;
#if __WINDOWS__ && !__CYGWIN__ && !MINGW32
    BOOL ret;
    DWORD out;
    DWORD mode;
    char b;
    HANDLE h = GetStdHandle (STD_INPUT_HANDLE);
    GetConsoleMode (h, &mode);
    SetConsoleMode (h, 0); // RAW
ignore:
    if (!I->is_wine) {
        while (!_kbhit ());
        b = getwinkey ();
        if (b=='2')
            goto ignore;
        else if (b=='1')
            ret = ReadConsole (h, buf, 1, &out, NULL);
        else {
            buf[0]=b;
            ret=1;
        }
    } else {
        ret = ReadConsole (h, buf, 1, &out, NULL);
    }
    FlushConsoleInputBuffer(h);
    if (!ret)
        return -1;
    SetConsoleMode (h, mode);
#else
    r_cons_set_raw (1);
    if (read (0, buf, 1)==-1)
        return -1;
    r_cons_set_raw (0);
#endif
    return r_cons_controlz (buf[0]);
}