Module Eio_unix.Pty

Creating and controlling pseudoterminals.

Pseudoterminal (PTY) support.

A pseudoterminal is a pair of connected file descriptors emulating a terminal. The pseudoterminal device is used by a controlling program such as a terminal emulator, while the terminal device is used by a child process as its controlling terminal.

type t

A connected pseudoterminal pair.

val open_pty : sw:Eio.Std.Switch.t -> unit -> t

open_pty ~sw () allocates a new pseudoterminal pair.

Both file descriptors are closed when sw finishes. The pty end is non-blocking; the tty end is blocking and so suitable as the child's controlling terminal.

Not a multi-domain-safe function on some platforms without reentrant ptsname support.

  • raises Unix.Unix_error

    if the pseudoterminal cannot be created.

val pty : t -> Fd.t

pty t is the pseudoterminal-device end.

val tty : t -> Fd.t

tty t is the terminal-device end.

val name : t -> string

name t is the path of the terminal device.

val source : t -> [ `Unix_fd | Eio.Resource.close_ty | Eio.Flow.source_ty ] Eio.Std.r

source t reads the output the child writes to terminal.

val sink : t -> [ `Unix_fd | Eio.Resource.close_ty | Eio.Flow.sink_ty ] Eio.Std.r

sink t writes input for the child to read from its terminal.

type winsize = {
  1. rows : int;
    (*

    Height of the terminal in character rows.

    *)
  2. cols : int;
    (*

    Width of the terminal in character columns.

    *)
  3. xpixel : int;
    (*

    Width in pixels (0 if unknown).

    *)
  4. ypixel : int;
    (*

    Height in pixels (0 if unknown).

    *)
}

Terminal window dimensions.

val get_window_size : Fd.t -> winsize

get_window_size fd returns the window size of terminal fd.

  • raises Unix.Unix_error

    if fd is not a terminal.

val set_window_size : Fd.t -> winsize -> unit

set_window_size fd ws sets the window size of terminal fd.

Setting it on the pty end updates the terminal and delivers SIGWINCH to the foreground process group attached to the terminal.

  • raises Unix.Unix_error

    if fd is not a terminal.

module Tc : sig ... end

Terminal attributes control. These raise Unix.Unix_error if fd is not a terminal.