Module | Termios |
In: |
lib/termios.rb
termios.c lib/termios.rb |
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.
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.
termios(3)
VISIBLE_CHAR | = | {} | ||
NCCS | = | INT2FIX(NCCS) | number of control characters | |
POSIX_VDISABLE | = | INT2FIX(_POSIX_VDISABLE) | ||
CCINDEX | = | ccindex | Hash of control character index and control character names | |
CCINDEX_NAMES | = | ccindex_names | List of control character names | |
IFLAGS | = | iflags | Hash of input mode names and values | |
IFLAG_NAMES | = | iflags_names | List of input mode names | |
OFLAGS | = | oflags | Hash of output mode names and values | |
OFLAG_NAMES | = | oflags_names | List of output mode names | |
OFLAG_CHOICES | = | oflags_choices | ||
CFLAGS | = | cflags | Hash of control mode names and values | |
CFLAG_NAMES | = | cflags_names | List of control mode names | |
CFLAG_CHOICES | = | cflags_choices | ||
LFLAGS | = | lflags | Hash of local mode names and values | |
LFLAG_NAMES | = | lflags_names | List of local mode names | |
BAUDS | = | bauds | List of baud rates | |
BAUD_NAMES | = | bauds_names | List of baud rate names | |
SETATTR_OPTS | = | tcsetattr_opt | List of tcsetattr options | |
FLUSH_QSELECTORS | = | tcflush_qs | List of tcflush qselectors | |
FLOW_ACTIONS | = | tcflow_act | List of tcflow actions | |
IOCTL_COMMANDS | = | ioctl_commands | ||
IOCTL_COMMAND_NAMES | = | ioctl_commands_names | ||
MODEM_SIGNALS | = | modem_signals | ||
MODEM_SIGNAL_NAMES | = | modem_signals_names | ||
PTY_PACKET_OPTIONS | = | pty_pkt_options | ||
PTY_PACKET_OPTION_NAMES | = | pty_pkt_options_names | ||
LINE_DISCIPLINES | = | line_disciplines | ||
LINE_DISCIPLINE_NAMES | = | line_disciplines | ||
VISIBLE_CHAR | = | {} |
Returns new Termios::Termios object.
/* * call-seq: * Termios.new_termios * * 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); }
Waits until all output to the object has been sent.
See also: tcdrain(3)
/* * call-seq: * Termios.tcdrain(io) * io.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; }
Suspends write or read of data on the object.
See also: tcflow(3)
/* * call-seq: * Termios.tcflow(io, action) * io.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; }
Cancels data written to the object but not send or data received but not read.
See also: tcflush(3)
/* * call-seq: * Termios.tcflush(io, qs) * io.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; }
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)
/* * call-seq: * Termios.tcgetattr(io) * io.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); }
Returns the process group ID of the foreground process group the terminal associated to the object.
See also: tcgetpgrp(3)
/* * call-seq: * Termios.tcgetpgrp(io) * io.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); }
Sends a continuous stream of 0-bits for a specific duration.
See also: tcsendbreak(3)
/* * call-seq: * Termios.tcsendbreak(io, duration) * io.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; }
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)
/* * call-seq: * Termios.tcsetattr(io, option, termios) * io.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; }
Makes the process group with pgrpid the foreground process group on the terminal associated to the object.
See also: tcsetpgrp(3)
/* * call-seq: * Termios.tcsetpgrp(io, pgrpid) * io.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; }