The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

UniEvent::Tty - stream handle for the console

SYNOPSIS

    my $tty  = UniEvent::Tty->new(\*STDERR);
    my ($w, $h) = $tty->get_winsize();
    say "terminal size: $w x $h";
    $tty->write("hello world");
    $tty->loop->run;

    my $tty_in  = UniEvent::Tty->new(\*STDIN);
    $tty_in->read_callback(sub {
        my ($tty_in, $data, $error) = @_;
        ...
    });
    $tty_in->eof_callback(sub {
      ...
    });
    $tty_in->read_start();    # Important for STDIN
    $tty_in->loop->run;

DESCRIPTION

Tty handle provide streaming interfrace for terminal device.

It is inherited from UniEvent::Stream.

Comparing to other kind of streams, the UniEvent::Tty is not full-duplex stream, i.e. for reading and writing separate handles should be created. As reading operation is not supported for writing handles (i.e. for STDERR or STDOUT), it is user responsibility to invoke read_start() method to receive data from Tty handle.

FUNCTIONS

reset_mode()

To be called when the program exits. Resets TTY settings to default values for the next process to take over.

METHODS

All methods of UniEvent::Stream also apply.

new($fd, [$loop = default])

Constructs new Tty handle in non-blocking mode with the given file descriptor $fd and binds it to the specified event loop.

set_mode($mode)

Set the TTY using the specified terminal mode.

$mode should be on of the following constants (in UE::Tty::*):

MODE_STD

Initial/normal terminal mode

MODE_RAW

Raw input mode (On Windows, ENABLE_WINDOW_INPUT is also enabled)

MODE_IO

Binary-safe I/O mode for IPC (Unix-only)

May return error

get_winsize()

Returns list of size of the terminal window, i.e. ($width, $height).