class IO

Public Instance Methods

unget(str, ...) → nil click to toggle source

Feed str into the TTY's input queue.

$stdin.unget "hello\n"    #=> nil
VALUE
rb_io_unget( int argc, VALUE *argv, VALUE io)
{
#ifndef RUBY_VM
    OpenFile *fptr;
#else
    rb_io_t *fptr;
#endif
    int fd;
    struct termios oldtio, newtio;
    void *v[5];

    GetOpenFile( io, fptr);
#ifndef RUBY_VM
    fd = fileno( fptr->f);
#else
    fd = fptr->fd;
#endif

    if (tcgetattr( fd, &oldtio) < 0)
        RB_SYS_FAIL( fptr);
    newtio = oldtio;
    newtio.c_iflag &= ~ICRNL;
    if (tcsetattr( fd, TCSANOW, &newtio) < 0)
        RB_SYS_FAIL( fptr);

    v[0] = &fd, v[1] = fptr, v[2] = &oldtio,
        v[3] = &argc, v[4] = (void *) argv;
    return rb_ensure( io_unget, (VALUE) v, io_reset, (VALUE) v);
}
winsize() → ary click to toggle source

Get the available window space.

cols, rows, xpixel, ypixel = $stdout.winsize
VALUE
rb_io_winsize( VALUE self)
{
#ifndef RUBY_VM
    OpenFile *fptr;
#else
    rb_io_t *fptr;
#endif
    int fd;
    struct winsize w;
    VALUE r;

    GetOpenFile( self, fptr);
#ifndef RUBY_VM
    fd = fileno( fptr->f);
#else
    fd = fptr->fd;
#endif

    if (ioctl( fd, TIOCGWINSZ, &w) < 0)
        RB_SYS_FAIL( fptr);
    r = rb_ary_new2( 4);
    rb_ary_store( r, 0, INT2NUM( w.ws_col));
    rb_ary_store( r, 1, INT2NUM( w.ws_row));
    rb_ary_store( r, 2, INT2NUM( w.ws_xpixel));
    rb_ary_store( r, 3, INT2NUM( w.ws_ypixel));
    return r;
}