Module: Termios

Defined in:
ext/termios.c,
lib/termios.rb,
lib/termios/version.rb,
ext/termios.c

Overview

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)

Defined Under Namespace

Classes: Termios

Constant Summary collapse

VISIBLE_CHAR =
{}
VERSION =
'1.1.0'
NCCS =

number of control characters

INT2FIX(NCCS)
POSIX_VDISABLE =
INT2FIX(_POSIX_VDISABLE)
CCINDEX =

Hash of control character index and control character names

ccindex
CCINDEX_NAMES =

List of control character names

ccindex_names
IFLAGS =

Hash of input mode names and values

iflags
IFLAG_NAMES =

List of input mode names

iflags_names
OFLAGS =

Hash of output mode names and values

oflags
OFLAG_NAMES =

List of output mode names

oflags_names
OFLAG_CHOICES =
oflags_choices
CFLAGS =

Hash of control mode names and values

cflags
CFLAG_NAMES =

List of control mode names

cflags_names
CFLAG_CHOICES =
cflags_choices
LFLAGS =

Hash of local mode names and values

lflags
LFLAG_NAMES =

List of local mode names

lflags_names
BAUDS =

List of baud rates

bauds
BAUD_NAMES =

List of baud rate names

bauds_names
SETATTR_OPTS =

List of tcsetattr options

tcsetattr_opt
FLUSH_QSELECTORS =

List of tcflush qselectors

tcflush_qs
FLOW_ACTIONS =

List of tcflow actions

tcflow_act
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_names

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.drainObject



460
461
462
# File 'ext/termios.c', line 460

static VALUE
termios_s_tcdrain(obj, io)
VALUE obj, io;

.flowObject



539
540
541
# File 'ext/termios.c', line 539

static VALUE
termios_s_tcflow(obj, io, act)
VALUE obj, io, act;

.flushObject



500
501
502
# File 'ext/termios.c', line 500

static VALUE
termios_s_tcflush(obj, io, qs)
VALUE obj, io, qs;

.getattrObject



322
323
324
# File 'ext/termios.c', line 322

static VALUE
termios_s_tcgetattr(obj, io)
VALUE obj, io;

.getpgrpObject



572
573
574
# File 'ext/termios.c', line 572

static VALUE
termios_s_tcgetpgrp(obj, io)
VALUE obj, io;

.new_termiosObject

Returns new Termios::Termios object.



620
621
622
# File 'ext/termios.c', line 620

static VALUE
termios_s_newtermios(argc, argv, klass)
int argc;

.sendbreakObject



428
429
430
# File 'ext/termios.c', line 428

static VALUE
termios_s_tcsendbreak(obj, io, duration)
VALUE obj, io, duration;

.setattrObject



395
396
397
# File 'ext/termios.c', line 395

static VALUE
termios_s_tcsetattr(obj, io, opt, param)
VALUE obj, io, opt, param;

.setpgrpObject



607
608
609
# File 'ext/termios.c', line 607

static VALUE
termios_s_tcsetpgrp(obj, io, pgrpid)
VALUE obj, io, pgrpid;

.tcdrainObject



460
461
462
# File 'ext/termios.c', line 460

static VALUE
termios_s_tcdrain(obj, io)
VALUE obj, io;

.tcflowObject



539
540
541
# File 'ext/termios.c', line 539

static VALUE
termios_s_tcflow(obj, io, act)
VALUE obj, io, act;

.tcflushObject



500
501
502
# File 'ext/termios.c', line 500

static VALUE
termios_s_tcflush(obj, io, qs)
VALUE obj, io, qs;

.tcgetattrObject



322
323
324
# File 'ext/termios.c', line 322

static VALUE
termios_s_tcgetattr(obj, io)
VALUE obj, io;

.tcgetpgrpObject



572
573
574
# File 'ext/termios.c', line 572

static VALUE
termios_s_tcgetpgrp(obj, io)
VALUE obj, io;

.tcsendbreakObject



428
429
430
# File 'ext/termios.c', line 428

static VALUE
termios_s_tcsendbreak(obj, io, duration)
VALUE obj, io, duration;

.tcsetattrObject



395
396
397
# File 'ext/termios.c', line 395

static VALUE
termios_s_tcsetattr(obj, io, opt, param)
VALUE obj, io, opt, param;

.tcsetpgrpObject



607
608
609
# File 'ext/termios.c', line 607

static VALUE
termios_s_tcsetpgrp(obj, io, pgrpid)
VALUE obj, io, pgrpid;

Instance Method Details

#tcdrain(io) ⇒ Object #tcdrainObject

Waits until all output to the object has been sent.

See also: tcdrain(3)



444
445
446
# File 'ext/termios.c', line 444

static VALUE
termios_tcdrain(io)
VALUE io;

#tcflow(io, action) ⇒ Object #tcflow(action) ⇒ Object

Suspends write or read of data on the object.

See also: tcflow(3)



516
517
518
# File 'ext/termios.c', line 516

static VALUE
termios_tcflow(io, act)
VALUE io, act;

#tcflush(io, qs) ⇒ Object #tcflush(qs) ⇒ Object

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

See also: tcflush(3)



477
478
479
# File 'ext/termios.c', line 477

static VALUE
termios_tcflush(io, qs)
VALUE io, qs;

#tcgetattr(io) ⇒ Object #tcgetattrObject

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)



306
307
308
# File 'ext/termios.c', line 306

static VALUE
termios_tcgetattr(io)
VALUE io;

#tcgetpgrp(io) ⇒ Object #tcgetpgrpObject

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

See also: tcgetpgrp(3)



556
557
558
# File 'ext/termios.c', line 556

static VALUE
termios_tcgetpgrp(io)
VALUE io;

#tcsendbreak(io, duration) ⇒ Object #tcsendbreak(duration) ⇒ Object

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

See also: tcsendbreak(3)



411
412
413
# File 'ext/termios.c', line 411

static VALUE
termios_tcsendbreak(io, duration)
VALUE io, duration;

#tcsetattr(io, option, termios) ⇒ Object #tcsetattr(option, termios) ⇒ Object

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)



361
362
363
# File 'ext/termios.c', line 361

static VALUE
termios_tcsetattr(io, opt, param)
VALUE io, opt, param;

#tcsetpgrp(io, pgrpid) ⇒ Object #tcsetpgrp(pgrpid) ⇒ Object

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

See also: tcsetpgrp(3)



589
590
591
# File 'ext/termios.c', line 589

static VALUE
termios_tcsetpgrp(io, pgrpid)
VALUE io, pgrpid;