4.5. TermIOS Class

Note: This class is not available with the PO_NO_TERMINAL_IO parse option.

On platforms without TermIOS support (such as Windows), none of the methods in this class are available; to write a portable program, check the HAVE_TERMIOS constant at runtime before using this functionality.

This class contains the data structure used to read and set terminal attributes on terminal I/O constants.

This class is used with File::getTerminalAttributes(), File::setTerminalAttributes(), and the terminal I/O constants to manipulate terminal attributes.

For example, here is some code to set terminal attributes, read in a character from standard input with a timeout, and reset the terminal attributes:

my TermIOS $t();
stdin.getTerminalAttributes($t);
my TermIOS $orig = $t.copy();
on_exit
    stdin.setTerminalAttributes(TCSADRAIN, $orig);

my $lflag = $t.getLFlag();
$lflag &= ~ICANON;
$lflag &= ~ECHO;
$lflag &= ~ISIG;
$t.setLFlag($lflag);
$t.setCC(VMIN, 1);
$t.setCC(VTIME, 0);
stdin.setTerminalAttributes(TCSADRAIN, $t);

stdout.printf("Press any key: ");
while (!stdin.isDataAvailable(20ms)) {
    stdout.printf(".");
    stdout.sync();
    usleep(1ms);
}
my $c = stdin.read(1);
stdout.printf(" GOT ASCII 0x%02x (%d) '%s'\n", ord($c), ord($c), $c);

For more information on terminal attributes, see your system's manual pages for "termios".

Table 4.191. TermIOS Method Overview

Method

Except?

Description

TermIOS::constructor()

Y

Creates the TermIOS object.

TermIOS::destructor()

N

Destroys the TermIOS object.

TermIOS::copy()

N

Returns a copy of the object.

int TermIOS::getLFlag()

N

Gets the local mode value of the object.

int TermIOS::getCFlag()

N

Gets the control mode value of the object.

int TermIOS::getOFlag()

N

Gets the output mode value of the object.

int TermIOS::getIFlag()

N

Gets the input mode value of the object.

nothing TermIOS::setLFlag(softint $val = 0)

N

Sets the local mode of the object.

nothing TermIOS::setCFlag(softint $val = 0)

N

Sets the control mode of the object.

nothing TermIOS::setOFlag(softint $val = 0)

N

Sets the output mode of the object.

nothing TermIOS::setIFlag(softint $val = 0)

N

Sets the input mode of the object.

int TermIOS::getCC(softint $offset = 0)

Y

Gets the value of a control character for the object.

nothing TermIOS::setCC(softint $offset = 0, softint $value = 0)

Y

Sets the value of a control character for the object.

bool TermIOS::isEqual(TermIOS $other)

Y

Returns true if the object passed is equal to the current object, false if not.

static TermIOS::getWindowSize()

Y

Returns a hash giving the current terminal window size in hash keys rows and columns.


4.5.1. TermIOS::constructor()

Synopsis

Creates the TermIOS object with random contents. Use File::getTerminalAttributes() with a terminal I/O constant to initialize the object with terminal settings.

Prototype

TermIOS::constructor()

Example
my TermIOS $termios();
stdin.getTerminalAttributes($termios);
Platform Availability

HAVE_TERMIOS

Table 4.192. Exceptions Thrown by TermIOS::constructor()

err

desc

MISSING-FEATURE-ERROR

This exception is thrown when the method is not available on the runtime platform; for maximum portability, check the constant HAVE_TERMIOS before calling this function.


4.5.2. TermIOS::destructor()

Synopsis

Destroys the TermIOS object.

Example
delete $termios;

This method does not throw any exceptions.

4.5.3. TermIOS::copy()

Synopsis

Returns a copy of the object.

Example
my TermIOS $t2 = $t.copy();

This method does not throw any exceptions.

4.5.4. TermIOS::getLFlag()

Synopsis

Returns the local mode flag for the object

Prototype

int TermIOS::getLFlag()

Platform Availability

HAVE_TERMIOS

Table 4.193. Return Values for TermIOS::getLFlag()

Return Type

Description

int

The local mode flag for the object


Table 4.194. Exceptions Thrown by TermIOS::getLFlag()

err

desc

MISSING-FEATURE-ERROR

This exception is thrown when the method is not available on the runtime platform; for maximum portability, check the constant HAVE_TERMIOS before calling this function.


4.5.5. TermIOS::getCFlag()

Synopsis

Returns the control mode flag for the object

Prototype

int TermIOS::getCFlag()

Platform Availability

HAVE_TERMIOS

Table 4.195. Return Values for TermIOS::getCFlag()

Return Type

Description

int

The control mode flag for the object


Table 4.196. Exceptions Thrown by TermIOS::getCFlag()

err

desc

MISSING-FEATURE-ERROR

This exception is thrown when the method is not available on the runtime platform; for maximum portability, check the constant HAVE_TERMIOS before calling this function.


4.5.6. TermIOS::getIFlag()

Synopsis

Returns the input mode flag for the object

Prototype

int TermIOS::getIFlag()

Platform Availability

HAVE_TERMIOS

Table 4.197. Return Values for TermIOS::getIFlag()

Return Type

Description

int

The input mode flag for the object


Table 4.198. Exceptions Thrown by TermIOS::getIFlag()

err

desc

MISSING-FEATURE-ERROR

This exception is thrown when the method is not available on the runtime platform; for maximum portability, check the constant HAVE_TERMIOS before calling this function.


4.5.7. TermIOS::getOFlag()

Synopsis

Returns the output mode flag for the object

Prototype

int TermIOS::getOFlag()

Platform Availability

HAVE_TERMIOS

Table 4.199. Return Values for TermIOS::getOFlag()

Return Type

Description

int

The output mode flag for the object


Table 4.200. Exceptions Thrown by TermIOS::getOFlag()

err

desc

MISSING-FEATURE-ERROR

This exception is thrown when the method is not available on the runtime platform; for maximum portability, check the constant HAVE_TERMIOS before calling this function.


4.5.8. TermIOS::setLFlag()

Synopsis

Sets the local mode flag for the object

Prototype

nothing TermIOS::setLFlag(softint $val = 0)

Platform Availability

HAVE_TERMIOS

Table 4.201. Arguments for TermIOS::setLFlag()

Argument

Description

softint $val = 0

The local mode to set for the object.


Table 4.202. Exceptions Thrown by TermIOS::setLFlag()

err

desc

MISSING-FEATURE-ERROR

This exception is thrown when the method is not available on the runtime platform; for maximum portability, check the constant HAVE_TERMIOS before calling this function.


4.5.9. TermIOS::setCFlag()

Synopsis

Sets the control mode flag for the object

Prototype

nothing TermIOS::setCFlag(softint $val = 0)

Platform Availability

HAVE_TERMIOS

Table 4.203. Arguments for TermIOS::setCFlag()

Argument

Description

softint $val = 0

The control mode to set for the object.


Table 4.204. Exceptions Thrown by TermIOS::setCFlag()

err

desc

MISSING-FEATURE-ERROR

This exception is thrown when the method is not available on the runtime platform; for maximum portability, check the constant HAVE_TERMIOS before calling this function.


4.5.10. TermIOS::setIFlag()

Synopsis

Sets the input mode flag for the object

Prototype

nothing TermIOS::setIFlag(softint $val = 0)

Platform Availability

HAVE_TERMIOS

Table 4.205. Arguments for TermIOS::setIFlag()

Argument

Description

softint $val = 0

The input mode to set for the object.


Table 4.206. Exceptions Thrown by TermIOS::setIFlag()

err

desc

MISSING-FEATURE-ERROR

This exception is thrown when the method is not available on the runtime platform; for maximum portability, check the constant HAVE_TERMIOS before calling this function.


4.5.11. TermIOS::setOFlag()

Synopsis

Sets the output mode flag for the object

Prototype

nothing TermIOS::setOFlag(softint $val = 0)

Platform Availability

HAVE_TERMIOS

Table 4.207. Arguments for TermIOS::setOFlag()

Argument

Description

softint $val = 0

The output mode to set for the object.


Table 4.208. Exceptions Thrown by TermIOS::setOFlag()

err

desc

MISSING-FEATURE-ERROR

This exception is thrown when the method is not available on the runtime platform; for maximum portability, check the constant HAVE_TERMIOS before calling this function.


4.5.12. TermIOS::getCC()

Synopsis

Returns the value of the control character corresponding to the argument passed.

Prototype

int TermIOS::getCC(softint $offset = 0)

Platform Availability

HAVE_TERMIOS

Table 4.209. Arguments for TermIOS::getCC()

Argument

Description

softint $offset = 0

The control character to get from th object.


Table 4.210. Return Values for TermIOS::getCC()

Return Type

Description

int

The value of the given control character.


Table 4.211. Exceptions Thrown by TermIOS::getCC()

err

desc

MISSING-FEATURE-ERROR

This exception is thrown when the method is not available on the runtime platform; for maximum portability, check the constant HAVE_TERMIOS before calling this function.


4.5.13. TermIOS::setCC()

Synopsis

Sets the control character corresponding to the first argument to the value of the second argument.

Prototype

nothing TermIOS::setCC(softint $offset = 0, softint $value = 0)

Platform Availability

HAVE_TERMIOS

Table 4.212. Arguments for TermIOS::setCC()

Argument

Description

softint $offset = 0

The control character to set.

softint value = 0

The value to set


Table 4.213. Exceptions Thrown by TermIOS::setCC()

err

desc

MISSING-FEATURE-ERROR

This exception is thrown when the method is not available on the runtime platform; for maximum portability, check the constant HAVE_TERMIOS before calling this function.


4.5.14. TermIOS::isEqual()

Synopsis

Returns True if the TermIOS object passed as an argument is equal to the current object; false if not. If the argument passed to this method is not a TermIOS object, an exception is raised

Prototype

bool TermIOS::isEqual(TermIOS $other)

Platform Availability

HAVE_TERMIOS

Table 4.214. Arguments for TermIOS::isEqual()

Argument

Description

TermIOS $other

The object to compare to the current object.


Table 4.215. Return Values for TermIOS::isEqual()

Return Type

Description

bool

The result of comparing the current object to the argument


Table 4.216. Exceptions thrown by TermIOS::isEqual()

err

desc

TERMIOS-ISEQUAL-ERROR

argument passed is not a TermIOS object

MISSING-FEATURE-ERROR

This exception is thrown when the method is not available on the runtime platform; for maximum portability, check the constant HAVE_TERMIOS before calling this function.


4.5.15. static TermIOS::getWindowSize()

Synopsis

Returns a hash giving the current terminal window size in hash keys rows and columns.

Prototype

static hash TermIOS::getWindowSize()

Example
$hash = TermIOS::getWindowSize()
Platform Availability

HAVE_TERMIOS

Restrictions

Not available with PO_NO_FILESYSTEM

Table 4.217. Return Values for TermIOS::getWindowSize()

Return Type

Description

hash

Returns a hash giving the current terminal window size in hash keys rows and columns.


Table 4.218. Exceptions Thrown by TermIOS::getWindowSize()

err

desc

MISSING-FEATURE-ERROR

This exception is thrown when the method is not available on the runtime platform; for maximum portability, check the constant HAVE_TERMIOS before calling this function.