Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →
instance method
IO#input_pending?
io.input_pending? → true or false
ext/io/console/console.c
View on GitHub ↗
static VALUE
console_input_pending_p(VALUE io)
{
rb_io_t *fptr;
GetOpenFile(io, fptr);
if (rb_io_read_pending(fptr)) return Qtrue;
#ifdef _WIN32
{
DWORD mode;
HANDLE h = (HANDLE)rb_w32_get_osfhandle(GetReadFD(io));
if (GetConsoleMode(h, &mode)) return _kbhit() ? Qtrue : Qfalse;
}
#endif
#if defined HAVE_RB_IO_WAIT
return RTEST(rb_io_wait(io, RB_INT2NUM(RUBY_IO_READABLE), INT2FIX(0))) ? Qtrue : Qfalse;
#else
{
struct timeval timeout = {0, 0};
int result;
result = rb_wait_for_single_fd(fptr->fd, RB_WAITFD_IN, &timeout);
if (result < 0) sys_fail(io);
return (result & RB_WAITFD_IN) ? Qtrue : Qfalse;
}
#endif
}
Returns whether input can be read without blocking.
You must require ‘io/console’ to use this method.