unix::tty+x86_64 +linux

unix::tty provides an interface for interacting with and manipulating a terminal environment, based on the termios interface defined by POSIX.

https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/termios.h.html

Index

Types

type ttysize = struct {
	rows: u16,
	columns: u16,
};

// Undocumented types:
type termios = struct {
	file: io::file,
	saved: rt::termios,
	current: rt::termios,
};

Errors

type error = !(errors::invalid | errors::unsupported | errors::noentry);

Functions

fn isatty(fd: io::file) bool;
fn makeraw(termios: *termios) (void | errors::error);
fn noecho(termios: *termios) (void | errors::error);
fn noncanonical(termios: *termios) (void | errors::error);
fn open() (io::file | error);
fn openpty() ((io::file, io::file) | fs::error);
fn ptsname(master: io::file) (str | error);
fn set_winsize(pty: io::file, sz: ttysize) (void | error);
fn strerror(err: error) str;
fn tcsetpgrp(fd: io::file, pg: exec::process) (void | errors::error);
fn termios_query(file: io::file) (termios | errors::error);
fn termios_restore(termios: *const termios) void;
fn termios_set(termios: *const termios) (void | errors::error);
fn winsize(fd: io::file) (ttysize | error);

Types

type ttysize[link]

type ttysize = struct {
	rows: u16,
	columns: u16,
};

Structure representing dimensions of a terminal.

type termios[link]

Show undocumented member
type termios = struct {
	file: io::file,
	saved: rt::termios,
	current: rt::termios,
};

Errors

type error[link]

type error = !(errors::invalid | errors::unsupported | errors::noentry);

Any error that may occur during TTY-related tasks.

Functions

fn isatty[link]

fn isatty(fd: io::file) bool;

Returns whether the given stream is connected to a terminal.

fn makeraw[link]

fn makeraw(termios: *termios) (void | errors::error);

Enables "raw" mode for this terminal, disabling echoing, line editing, and signal handling. Users should call termios_query prior to this to save the previous terminal settings, and termios_restore to restore them before exiting.

fn noecho[link]

fn noecho(termios: *termios) (void | errors::error);

Disables "echo" on this terminal. Users should call termios_restore to restore settings.

fn noncanonical[link]

fn noncanonical(termios: *termios) (void | errors::error);

Enables "noncanonical" mode for this terminal, disabling line buffering and line editing. Users should call termios_restore to restore settings.

fn open[link]

fn open() (io::file | error);

Returns a stream connected to the TTY of the current process. The caller must close it using io::close.

fn openpty[link]

fn openpty() ((io::file, io::file) | fs::error);

Opens an available pseudoterminal and returns the file descriptors of the master and slave.

fn ptsname[link]

fn ptsname(master: io::file) (str | error);

Returns the filename of the pseudoterminal slave.

fn set_winsize[link]

fn set_winsize(pty: io::file, sz: ttysize) (void | error);

Sets the dimensions of the underlying pseudoterminal for an io::file.

fn strerror[link]

fn strerror(err: error) str;

Converts an error to a human-friendly string.

fn tcsetpgrp[link]

fn tcsetpgrp(fd: io::file, pg: exec::process) (void | errors::error);

Sets the process group on the foreground of this terminal.

fn termios_query[link]

fn termios_query(file: io::file) (termios | errors::error);

Retrieves serial port settings of the given terminal.

fn termios_restore[link]

fn termios_restore(termios: *const termios) void;

Restores original serial port settings.

fn termios_set[link]

fn termios_set(termios: *const termios) (void | errors::error);

Sets serial port settings.

fn winsize[link]

fn winsize(fd: io::file) (ttysize | error);

Returns the dimensions of underlying terminal for an io::file.