Namespace

Class/Module Index [+]

Quicksearch

Termios

Description

Termios module is simple wrapper of termios(3). It can be included into IO-family classes and can extend IO-family objects. In addition, the methods can use as module function.

You can call termios(3) function as module methods. Or you can use these methods as instance method by including Termios module to the target IO object.

Constants

Many constants which are derived from "termios.h" are defined on Termios module. You can use these constants as the same name in "termios.h" basically.

IFLAGS, OFLAGS, CFLAGS and LFLAGS are Hash object. They contains Symbols of constants for c_iflag, c_oflag, c_cflag and c_lflag. CCINDEX and BAUDS are Hash object too. They contains Symbols of constats for c_cc or ispeed and ospeed.

See also

termios(3)

Constants

BAUDS

List of baud rates

BAUD_NAMES

List of baud rate names

CCINDEX

Hash of control character index and control character names

CCINDEX_NAMES

List of control character names

CFLAGS

Hash of control mode names and values

CFLAG_CHOICES
CFLAG_NAMES

List of control mode names

FLOW_ACTIONS

List of tcflow actions

FLUSH_QSELECTORS

List of tcflush qselectors

IFLAGS

Hash of input mode names and values

IFLAG_NAMES

List of input mode names

IOCTL_COMMANDS
IOCTL_COMMAND_NAMES
LFLAGS

Hash of local mode names and values

LFLAG_NAMES

List of local mode names

LINE_DISCIPLINES
LINE_DISCIPLINE_NAMES
MODEM_SIGNALS
MODEM_SIGNAL_NAMES
NCCS

number of control characters

OFLAGS

Hash of output mode names and values

OFLAG_CHOICES
OFLAG_NAMES

List of output mode names

POSIX_VDISABLE
PTY_PACKET_OPTIONS
PTY_PACKET_OPTION_NAMES
SETATTR_OPTS

List of tcsetattr options

VISIBLE_CHAR

Public Class Methods

drain(p1) click to toggle source
static VALUE
termios_s_tcdrain(obj, io)
    VALUE obj, io;
{
    return termios_tcdrain(io);
}
flow(p1, p2) click to toggle source
static VALUE
termios_s_tcflow(obj, io, act)
    VALUE obj, io, act;
{
    return termios_tcflow(io, act);
}
flush(p1, p2) click to toggle source
static VALUE
termios_s_tcflush(obj, io, qs)
    VALUE obj, io, qs;
{
    return termios_tcflush(io, qs);
}
getattr(p1) click to toggle source
static VALUE
termios_s_tcgetattr(obj, io)
    VALUE obj, io;
{
    return termios_tcgetattr(io);
}
getpgrp(p1) click to toggle source
static VALUE
termios_s_tcgetpgrp(obj, io)
    VALUE obj, io;
{
    return termios_tcgetpgrp(io);
}
new_termios click to toggle source

Returns new Termios::Termios object.

static VALUE
termios_s_newtermios(argc, argv, klass)
    int argc;
    VALUE *argv;
    VALUE klass;
{
    return rb_funcall2(cTermios, rb_intern("new"), argc, argv);
}
sendbreak(p1, p2) click to toggle source
static VALUE
termios_s_tcsendbreak(obj, io, duration)
    VALUE obj, io, duration;
{
    return termios_tcsendbreak(io, duration);
}
setattr(p1, p2, p3) click to toggle source
static VALUE
termios_s_tcsetattr(obj, io, opt, param)
    VALUE obj, io, opt, param;
{
    return termios_tcsetattr(io, opt, param);
}
setpgrp(p1, p2) click to toggle source
static VALUE
termios_s_tcsetpgrp(obj, io, pgrpid)
    VALUE obj, io, pgrpid;
{
    return termios_tcsetpgrp(io, pgrpid);
}
tcdrain(p1) click to toggle source
static VALUE
termios_s_tcdrain(obj, io)
    VALUE obj, io;
{
    return termios_tcdrain(io);
}
tcflow(p1, p2) click to toggle source
static VALUE
termios_s_tcflow(obj, io, act)
    VALUE obj, io, act;
{
    return termios_tcflow(io, act);
}
tcflush(p1, p2) click to toggle source
static VALUE
termios_s_tcflush(obj, io, qs)
    VALUE obj, io, qs;
{
    return termios_tcflush(io, qs);
}
tcgetattr(p1) click to toggle source
static VALUE
termios_s_tcgetattr(obj, io)
    VALUE obj, io;
{
    return termios_tcgetattr(io);
}
tcgetpgrp(p1) click to toggle source
static VALUE
termios_s_tcgetpgrp(obj, io)
    VALUE obj, io;
{
    return termios_tcgetpgrp(io);
}
tcsendbreak(p1, p2) click to toggle source
static VALUE
termios_s_tcsendbreak(obj, io, duration)
    VALUE obj, io, duration;
{
    return termios_tcsendbreak(io, duration);
}
tcsetattr(p1, p2, p3) click to toggle source
static VALUE
termios_s_tcsetattr(obj, io, opt, param)
    VALUE obj, io, opt, param;
{
    return termios_tcsetattr(io, opt, param);
}
tcsetpgrp(p1, p2) click to toggle source
static VALUE
termios_s_tcsetpgrp(obj, io, pgrpid)
    VALUE obj, io, pgrpid;
{
    return termios_tcsetpgrp(io, pgrpid);
}

Public Instance Methods

tcdrain(io) click to toggle source
tcdrain

Waits until all output to the object has been sent.

See also: tcdrain(3)

static VALUE
termios_tcdrain(io)
    VALUE io;
{
    OpenFile *fptr;

    Check_Type(io, T_FILE);

    GetOpenFile(io, fptr);
    if (tcdrain(FILENO(fptr)) < 0) {
        rb_sys_fail("tcdrain");
    }

    return Qtrue;
}
tcflow(io, action) click to toggle source
tcflow(action)

Suspends write or read of data on the object.

See also: tcflow(3)

static VALUE
termios_tcflow(io, act)
    VALUE io, act;
{
    OpenFile *fptr;
    int action;

    Check_Type(io,  T_FILE);
    Check_Type(act, T_FIXNUM);
    action = FIX2INT(act);
    if (rb_ary_includes(tcflow_act, act) != Qtrue) {
        rb_raise(rb_eArgError, 
                 "wrong action value %d", action);
    }

    GetOpenFile(io, fptr);
    if (tcflow(FILENO(fptr), action) < 0) {
        rb_sys_fail("tcflow");
    }

    return Qtrue;
}
tcflush(io, qs) click to toggle source
tcflush(qs)

Cancels data written to the object but not send or data received but not read.

See also: tcflush(3)

static VALUE
termios_tcflush(io, qs)
    VALUE io, qs;
{
    OpenFile *fptr;
    int queue_selector;

    Check_Type(io, T_FILE);
    Check_Type(qs, T_FIXNUM);
    queue_selector = FIX2INT(qs);
    if (rb_ary_includes(tcflush_qs, qs) != Qtrue) {
        rb_raise(rb_eArgError, 
                 "wrong queue-selector value %d", queue_selector);
    }

    GetOpenFile(io, fptr);
    if (tcflush(FILENO(fptr), queue_selector) < 0) {
        rb_sys_fail("tcflush");
    }

    return Qtrue;
}
tcgetattr(io) click to toggle source
tcgetattr

Returns new Termios::Termios object which stores termios parameters associated with the io.

require 'termios'

Termios.tcgetattr($stdin)
  #=> #<Termios::Termios speed 38400 baud; intr=^C ... >

$stdout.extend(Termios)
$stdout.tcgetattr
  #=> #<Termios::Termios speed 38400 baud; intr=^C ... >

See also: tcgetattr(3)

static VALUE
termios_tcgetattr(io)
    VALUE io;
{
    struct termios t;
    OpenFile *fptr;

    Check_Type(io, T_FILE);
    GetOpenFile(io, fptr);
    if (tcgetattr(FILENO(fptr), &t) < 0) {
        rb_sys_fail("tcgetattr");
    }

    return termios_to_Termios(&t);
}
tcgetpgrp(io) click to toggle source
tcgetpgrp

Returns the process group ID of the foreground process group the terminal associated to the object.

See also: tcgetpgrp(3)

static VALUE
termios_tcgetpgrp(io)
    VALUE io;
{
    OpenFile *fptr;
    pid_t pid;

    Check_Type(io,  T_FILE);
    GetOpenFile(io, fptr);
    if ((pid = tcgetpgrp(FILENO(fptr))) < 0) {
        rb_sys_fail("tcgetpgrp");
    }

    return LONG2NUM(pid);
}
tcsendbreak(io, duration) click to toggle source
tcsendbreak(duration)

Sends a continuous stream of 0-bits for a specific duration.

See also: tcsendbreak(3)

static VALUE
termios_tcsendbreak(io, duration)
    VALUE io, duration;
{
    OpenFile *fptr;

    Check_Type(io,       T_FILE);
    Check_Type(duration, T_FIXNUM);

    GetOpenFile(io, fptr);
    if (tcsendbreak(FILENO(fptr), FIX2INT(duration)) < 0) {
        rb_sys_fail("tcsendbreak");
    }

    return Qtrue;
}
tcsetattr(io, option, termios) click to toggle source
tcsetattr(option, termios)

Sets the Termios::Termios object as the termios paramter to the io and returns the old termios parameter.

Option are specifies when the parameter is changed. What option are available is plathome dependent, but usually Termios::TCSANOW, Termios::TCSADRAIN and Termios::TCSAFLUSH are provided.

require 'termios'

oldt = Termios.tcgetattr($stdin)
newt = oldt.dup
newt.lflag &= ~Termios::ECHO

secret = nil
begin
  Termios.tcsetattr($stdin, Termios::TCSANOW, newt)
  print "noecho> "
  secret = $stdin.gets
  print "\n"
ensure
  Termios.tcsetattr($stdin, Termios::TCSANOW, oldt)
end

puts secret

See also: tcsetattr(3)

static VALUE
termios_tcsetattr(io, opt, param)
    VALUE io, opt, param;
{
    VALUE old;
    OpenFile *fptr;
    struct termios t;
    int tcsetattr_option;

    Check_Type(io,  T_FILE);
    Check_Type(opt, T_FIXNUM);
    if (CLASS_OF(param) != cTermios) {
        const char *type = rb_class2name(CLASS_OF(param));
        rb_raise(rb_eTypeError, 
                 "wrong argument type %s (expected Termios::Termios)", 
                 type);
    }

    tcsetattr_option = FIX2INT(opt);
    if (rb_ary_includes(tcsetattr_opt, opt) != Qtrue) {
        rb_raise(rb_eArgError, 
                 "wrong option value %d", tcsetattr_option);
    }

    old = termios_tcgetattr(io);
    GetOpenFile(io, fptr);
    Termios_to_termios(param, &t);
    if (tcsetattr(FILENO(fptr), tcsetattr_option, &t) < 0) {
        rb_sys_fail("tcsetattr");
    }

    return old;
}
tcsetpgrp(io, pgrpid) click to toggle source
tcsetpgrp(pgrpid)

Makes the process group with pgrpid the foreground process group on the terminal associated to the object.

See also: tcsetpgrp(3)

static VALUE
termios_tcsetpgrp(io, pgrpid)
    VALUE io, pgrpid;
{
    OpenFile *fptr;
    pid_t pgrp;

    Check_Type(io,     T_FILE);
    pgrp = NUM2LONG(pgrpid);

    GetOpenFile(io, fptr);
    if (tcsetpgrp(FILENO(fptr), pgrp) < 0) {
        rb_sys_fail("tcsetpgrp");
    }

    return Qtrue;
}

[Validate]

Generated with the Darkfish Rdoc Generator 2.