4.5. TermIOS Class

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

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 stanrdard input with a timeout, and reset the terminal attributes:

my $t = new TermIOS();
stdin.getTerminalAttributes($t);
my $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.199. 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.

TermIOS::getLFlag()

N

Gets the local mode value of the object.

TermIOS::getCFlag()

N

Gets the control mode value of the object.

TermIOS::getOFlag()

N

Gets the output mode value of the object.

TermIOS::getIFlag()

N

Gets the input mode value of the object.

TermIOS::setLFlag()

N

Sets the local mode of the object.

TermIOS::setCFlag()

N

Sets the control mode of the object.

TermIOS::setOFlag()

N

Sets the output mode of the object.

TermIOS::setIFlag()

N

Sets the input mode of the object.

TermIOS::getCC()

N

Gets the value of a control character for the object.

TermIOS::setCC()

N

Sets the value of a control character for the object.

TermIOS::isEqual()

Y

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


Table 4.200. TermIOS Static Method Overview

Method

Except?

Description

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.

Usage
new TermIOS()
Example
my $termios = new TermIOS();
stdin.getTerminalAttributes($termios);

Table 4.201. Arguments for TermIOS::constructor()

Argument

Type

Description

n/a

n/a

The constructor takes no arguments.


Table 4.202. Return Values for TermIOS::constructor()

Return Type

Description

TermIOS Object

The new TermIOS object.


4.5.2. TermIOS::destructor()

Synopsis

Destroys the TermIOS object.

Usage
delete lvalue
Example
delete $termios;

This method does not throw any exceptions.

4.5.3. TermIOS::copy()

Synopsis

Returns a copy of the object.

This method does not throw any exceptions.

4.5.4. TermIOS::getLFlag()

Synopsis

Returns the local mode flag for the object

Usage
TermIOS::getLFlag()

Table 4.203. Arguments for TermIOS::getLFlag()

Argument

Type

Description

n/a

n/a

This method takes no arguments.


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

Return Type

Description

Integer

The local mode flag for the object


4.5.5. TermIOS::getCFlag()

Synopsis

Returns the control mode flag for the object

Usage
TermIOS::getCFlag()

Table 4.205. Arguments for TermIOS::getCFlag()

Argument

Type

Description

n/a

n/a

This method takes no arguments.


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

Return Type

Description

Integer

The control mode flag for the object


4.5.6. TermIOS::getIFlag()

Synopsis

Returns the input mode flag for the object

Usage
TermIOS::getIFlag()

Table 4.207. Arguments for TermIOS::getIFlag()

Argument

Type

Description

n/a

n/a

This method takes no arguments.


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

Return Type

Description

Integer

The input mode flag for the object


4.5.7. TermIOS::getOFlag()

Synopsis

Returns the output mode flag for the object

Usage
TermIOS::getOFlag()

Table 4.209. Arguments for TermIOS::getOFlag()

Argument

Type

Description

n/a

n/a

This method takes no arguments.


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

Return Type

Description

Integer

The output mode flag for the object


4.5.8. TermIOS::setLFlag()

Synopsis

Sets the local mode flag for the object

Usage
TermIOS::setLFlag(lflag)

Table 4.211. Arguments for TermIOS::setLFlag()

Argument

Type

Description

lflag

Integer

The local mode to set for the object.


Table 4.212. Return Values for TermIOS::setLFlag()

Return Type

Description

n/a

This method returns no value


4.5.9. TermIOS::setCFlag()

Synopsis

Sets the control mode flag for the object

Usage
TermIOS::setCFlag(cflag)

Table 4.213. Arguments for TermIOS::setCFlag()

Argument

Type

Description

cflag

Integer

The control mode to set for the object.


Table 4.214. Return Values for TermIOS::setCFlag()

Return Type

Description

n/a

This method returns no value


4.5.10. TermIOS::setIFlag()

Synopsis

Sets the input mode flag for the object

Usage
TermIOS::setIFlag(iflag)

Table 4.215. Arguments for TermIOS::setIFlag()

Argument

Type

Description

iflag

Integer

The input mode to set for the object.


Table 4.216. Return Values for TermIOS::setIFlag()

Return Type

Description

n/a

This method returns no value


4.5.11. TermIOS::setOFlag()

Synopsis

Sets the output mode flag for the object

Usage
TermIOS::setOFlag(oflag)

Table 4.217. Arguments for TermIOS::setOFlag()

Argument

Type

Description

oflag

Integer

The output mode to set for the object.


Table 4.218. Return Values for TermIOS::setOFlag()

Return Type

Description

n/a

This method returns no value


4.5.12. TermIOS::getCC()

Synopsis

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

Usage
TermIOS::getCC(cc)

Table 4.219. Arguments for TermIOS::getCC()

Argument

Type

Description

cc

Integer

The control character to get from th object.


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

Return Type

Description

Integer

The value of the given control character.


4.5.13. TermIOS::setCC()

Synopsis

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

Usage
TermIOS::setCC(cc, val)

Table 4.221. Arguments for TermIOS::setCC()

Argument

Type

Description

cc

Integer

The control character to set.

val

Integer

The value to set


Table 4.222. Return Values for TermIOS::setCC()

Return Type

Description

n/a

This method returns no value


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

Usage
TermIOS::isEqual(termios)

Table 4.223. Arguments for TermIOS::isEqual()

Argument

Type

Description

termios

TermIOS

The object to compare to the current object.


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

Return Type

Description

Boolean

The result of comparing the current object to the argument


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

err

desc

TERMIOS-ISEQUAL-ERROR

argument passed is not a TermIOS object


4.5.15. static method: TermIOS::getWindowSize()

Synopsis

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

Usage
TermIOS::getWindowSize()
Example
$hash = TermIOS::getWindowSize()

Table 4.226. Arguments for TermIOS::getWindowSize()

Argument

Type

Description

n/a

n/a

This method takes no arguments.


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

Return Type

Description

Hash

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