[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

9.20 gauche.termios - Termios

Module: gauche.termios
This module defines POSIX termios interface, which controls terminal attributes. This module also provides pseudo tty interface, if the system provides it.

Builtin Class: <sys-termios>
POSIX termios(7) structure.

Instance Variable: <sys-termios> iflag
Instance Variable: <sys-termios> oflag
Instance Variable: <sys-termios> cflag
Instance Variable: <sys-termios> lflag

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 signalled. (You can check if port has an associated terminal by sys-isatty?. See section 6.21.3.5 Other file operations).

Function: sys-tcgetattr port-or-fd
Returns terminal parameters in a <sys-termios> object, associated to port-or-fd.

Function: sys-tcsetattr port-or-fd when 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:

TCSANOW
The change is reflected immediately.
TCSADRAIN
The change is reflected after all pending output is flushed.
TCSAFLUSH
The change is reflected after all pending output is flushed, and all pending input is discarded.

Function: sys-tcsendbreak port-or-fd duration
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.

Function: sys-tcdrain port-or-fd
Waits until all output written to port-or-fd is transmitted.

Function: sys-tcflush port-or-fd queue
Discards data in the buffer of port-or-fd, specified by queue, which may be one of the following values.
TCIFLUSH
Discards data received but not read.
TCOFLUSH
Discards data written but not transmitted.
TCIOFLUSH
Do both TCIFLUSH and TCOFLUSH action.

Function: sys-tcflow port-or-fd action
Controls data flow of port-or-fd by action, which may be one of the following values:
TCOOFF
Suspends output transmission.
TCOON
Restarts output transmission.
TCIOFF
Transmits a STOP character to make the terminal device stop transmitting data to the system.
TCION
Transmits a START character to make the terminal device resume transmitting data to the system.

Function: sys-tcgetpgrp port-or-fd
Returns process group ID of the terminal associated to port-or-fd.

Function: sys-tcsetpgrp port-or-fd pgrp
Sets process group ID of the terminal associated to port-or-fd to pgrp.

Function: sys-cfgetispeed termios
Function: sys-cfsetispeed termios speed
Function: sys-cfgetospeed termios
Function: sys-cfsetospeed termios speed
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.

Function: sys-openpty &optional term
Openes 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 section 6.18.3 File ports). To obtain pseudo tty's name, use sys-ttyname (See section 6.21.3.5 Other file operations).

This function is available only if the system supports openpty(3).

Function: sys-forkpty &optional term
Openes 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).

The following example shows how to get a password from the user without echoing:

 
(use gauche.termios)

(define (get-password prompt)
  (let* ((port (current-input-port))
         (attr (sys-tcgetattr port))
         (lflag (slot-ref attr 'lflag)))
    ;; Show prompt
    (display prompt)
    (flush)
    ;; Turn off echo during reading.
    (dynamic-wind
     (lambda ()
       (slot-set! attr 'lflag (logand lflag (lognot ECHO)))
       (sys-tcsetattr port TCSAFLUSH attr))
     (lambda ()
       (read-line port))
     (lambda ()
       (slot-set! attr 'lflag lflag)
       (sys-tcsetattr port TCSANOW attr)))))


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

This document was generated by Ken Dickey on November, 28 2002 using texi2html