gauche.termios
- Terminal control ¶This module provides procedures to control terminals. On Unix platforms, the low-level API provides POSIX termios interface as the module name suggests. This module also provides pseudo tty interface, if the system supports it.
On Windows native platforms, POSIX termios interface is not
available. It is too different from Windows console API to
provide a meaningful emulation. The low-level Windows console
API is available in the os.windows
module
(see os.windows
- Windows support). You can still use high-level
terminal control procedures in this module.
• Posix termios interface: | ||
• Common high-level terminal control: |
These procedures are available when the feature identifier
gauche.os.windows
is not defined. See cond-expand
in Feature conditional for how to switch code using
feature identifiers.
{gauche.termios
}
POSIX termios(7) structure.
<sys-termios>
: iflag ¶<sys-termios>
: oflag ¶<sys-termios>
: cflag ¶<sys-termios>
: lflag ¶<sys-termios>
: cc ¶The slots iflag
, oflag
, cflag
and lflag
contains non-negative integers representing bitmasks.
The slot cc
contains a copy of c_cc
array
of struct termios
, as an u8vector (see Uniform vectors
for the details about u8vector).
Since cc
slot is a copy of the internal structure, you have
to set!
an u8vector to the slot explicitly to make
changes to the c_cc
array.
Throughout this section, argument port-or-fd refers to
either a port object or a small integer representing system’s file
descriptor. If port is not associated
to the system terminal, an error is signaled. (You can check if port
has an associated terminal by sys-isatty?
.
see Other file operations).
{gauche.termios
}
Returns terminal parameters in a <sys-termios>
object,
associated to port-or-fd.
{gauche.termios
}
Sets terminal parameters associated to port-or-fd by termios,
which must be an instance of <sys-termios>
.
An integer argument when specifies when the changes take effect. Three variables are pre-defined for the argument:
{gauche.termios
}
Transmits a zero stream for the specified duration
to the terminal associated to port-or-fd.
The unit of duration depends on the system; see man tcsendbreak(3) of
your system for details.
{gauche.termios
}
Waits until all output written to port-or-fd is transmitted.
{gauche.termios
}
Discards data in the buffer of port-or-fd, specified by
queue, which may be one of the following values.
{gauche.termios
}
Controls data flow of port-or-fd by action, which may be
one of the following values:
{gauche.termios
}
Returns process group ID of the terminal associated to port-or-fd.
{gauche.termios
}
Sets process group ID of the terminal associated to port-or-fd
to pgrp.
{gauche.termios
}
Gets/sets input/output speed (baud rate) parameter stored in termios
object. Speed is represented by the following predefined numbers:
B0
, B50
, B75
, B110
, B134
,
B150
, B200
, B300
, B600
, B1200
,
B1800
, B2400
, B4800
, B9600
,
B19200
, B38400
.
Some system may support higher baud rate, such as B57600
,
B115200
or B230400
. You can use symbol-bound?
to check these options are defined. B0
is used to
terminate the connection.
{gauche.termios
}
Opens a pair of pseudo ttys, one for master and the other for slave,
then returns two integers which are their file descriptors.
An optional argument term must be, if passed, a <sys-termios>
object; it sets the slave pty’s parameters.
You can use open-input-fd-port
and/or open-output-fd-port
to create a port around the returned file descriptor (see File ports).
To obtain pseudo tty’s name, use sys-ttyname
(see Other file operations).
This function is available only if the system supports openpty(3)
.
{gauche.termios
}
Opens a pair of pseudo ttys, one for master and the other for slave,
sets the slave pty suitable for login terminal, then fork(2).
Returns two integers; the first value is a child pid for the parent process, and 0 for the child process. The second value is a file descriptor of the master pty.
An optional argument term must be, if passed, a <sys-termios>
object; it sets the slave pty’s parameters.
This function is available only if the system supports forkpty(3)
.
Note: sys-forkpty
has the same MT hazard as sys-fork
(see Process management, for details). If you’re
running multiple threads, use sys-forkpty-and-exec
below.
{gauche.termios
}
Does sys-forkpty
, and lets the child process
immediately exec
s the specified command
with arguments args. This function doesn’t have
the hazard in multi-thread environment.
The meanings of arguments command, args, iomap and
sigmask
are the same as sys-exec
(see Process management).
If the keyword argument term is given, it is used to initialize
the slave pty.
{gauche.termios
}
If iport is an input port connected to a terminal,
sets the terminal mode non-echoing and call proc with
iport as an argument. Before returning from
without-echoing
, or throwing an error,
the terminal mode is reset to the original state when this
procedure is called. The procedure returns whatever value(s)
proc returns.
You can also pass #f
to iport. In that case,
this procedure tries to open a console (/dev/tty
on Unix,
CON
on Windows) and set the console mode, then calls
proc with the opened input port. An error is thrown
if the procedure can not open a console.
If iport is other than above, this procedure simply calls proc with iport. This allows the caller to read password from redirected input, for example.
Note: Because of an implementation issue, on Windows native
platforms this procedure always changes console mode
of the standard input handle when iport
is either
#f
or a terminal input port.
{gauche.termios
}
Returns #t
iff the running Gauche is Windows-native and
the process has attached console. On Unix platforms this
procedure always returns #f
.
The reason that cond-expand
isn’t enough is that on Windows
the program may start without console, but you can attach console
afterwards. See Windows console API, for the details.