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 |
|---|---|---|
Y | Creates the TermIOS object. | |
N | Destroys the TermIOS object. | |
N | Returns a copy of the object. | |
N | Gets the local mode value of the object. | |
N | Gets the control mode value of the object. | |
N | Gets the output mode value of the object. | |
N | Gets the input mode value of the object. | |
|
| N | Sets the local mode of the object. |
|
| N | Sets the control mode of the object. |
|
| N | Sets the output mode of the object. |
|
| N | Sets the input mode of the object. |
|
| Y | Gets the value of a control character for the object. |
|
| Y | Sets the value of a control character for the object. |
|
| Y | Returns true if the object passed is equal to the current object, false if not. |
|
| Y | Returns a hash giving the current terminal window size in hash keys |
Creates the TermIOS object with random contents. Use File::getTerminalAttributes() with a terminal I/O constant to initialize the object with terminal settings.
my TermIOS $termios();
stdin.getTerminalAttributes($termios);
Table 4.192. Exceptions Thrown by TermIOS::constructor()
err | desc |
|---|---|
| This exception is thrown when the method is not available on the runtime platform; for maximum portability, check the constant |
Destroys the TermIOS object.
delete $termios;
This method does not throw any exceptions.
Returns a copy of the object.
my TermIOS $t2 = $t.copy();
This method does not throw any exceptions.
Returns the local mode flag for the object
Table 4.193. Return Values for TermIOS::getLFlag()
Return Type | Description |
|---|---|
The local mode flag for the object |
Table 4.194. Exceptions Thrown by TermIOS::getLFlag()
err | desc |
|---|---|
| This exception is thrown when the method is not available on the runtime platform; for maximum portability, check the constant |
Returns the control mode flag for the object
Table 4.195. Return Values for TermIOS::getCFlag()
|
Return Type |
Description |
|---|---|
|
The control mode flag for the object |
Table 4.196. Exceptions Thrown by TermIOS::getCFlag()
err | desc |
|---|---|
| This exception is thrown when the method is not available on the runtime platform; for maximum portability, check the constant |
Returns the input mode flag for the object
Table 4.197. Return Values for TermIOS::getIFlag()
|
Return Type |
Description |
|---|---|
|
The input mode flag for the object |
Table 4.198. Exceptions Thrown by TermIOS::getIFlag()
err | desc |
|---|---|
| This exception is thrown when the method is not available on the runtime platform; for maximum portability, check the constant |
Returns the output mode flag for the object
Table 4.199. Return Values for TermIOS::getOFlag()
|
Return Type |
Description |
|---|---|
|
The output mode flag for the object |
Table 4.200. Exceptions Thrown by TermIOS::getOFlag()
err | desc |
|---|---|
| This exception is thrown when the method is not available on the runtime platform; for maximum portability, check the constant |
Sets the local mode flag for the object
nothing TermIOS::setLFlag(softint $val = 0)
Table 4.201. Arguments for TermIOS::setLFlag()
Argument | Description |
|---|---|
| The local mode to set for the object. |
Table 4.202. Exceptions Thrown by TermIOS::setLFlag()
err | desc |
|---|---|
| This exception is thrown when the method is not available on the runtime platform; for maximum portability, check the constant |
Sets the control mode flag for the object
nothing TermIOS::setCFlag(softint $val = 0)
Table 4.203. Arguments for TermIOS::setCFlag()
Argument | Description |
|---|---|
|
The control mode to set for the object. |
Table 4.204. Exceptions Thrown by TermIOS::setCFlag()
err | desc |
|---|---|
| This exception is thrown when the method is not available on the runtime platform; for maximum portability, check the constant |
Sets the input mode flag for the object
nothing TermIOS::setIFlag(softint $val = 0)
Table 4.205. Arguments for TermIOS::setIFlag()
Argument | Description |
|---|---|
|
The input mode to set for the object. |
Table 4.206. Exceptions Thrown by TermIOS::setIFlag()
err | desc |
|---|---|
| This exception is thrown when the method is not available on the runtime platform; for maximum portability, check the constant |
Sets the output mode flag for the object
nothing TermIOS::setOFlag(softint $val = 0)
Table 4.207. Arguments for TermIOS::setOFlag()
Argument | Description |
|---|---|
|
The output mode to set for the object. |
Table 4.208. Exceptions Thrown by TermIOS::setOFlag()
err | desc |
|---|---|
| This exception is thrown when the method is not available on the runtime platform; for maximum portability, check the constant |
Returns the value of the control character corresponding to the argument passed.
int TermIOS::getCC(softint $offset = 0)
Table 4.209. Arguments for TermIOS::getCC()
|
Argument |
Description |
|---|---|
| The control character to get from th object. |
Table 4.210. Return Values for TermIOS::getCC()
|
Return Type |
Description |
|---|---|
|
The value of the given control character. |
Table 4.211. Exceptions Thrown by TermIOS::getCC()
err | desc |
|---|---|
| This exception is thrown when the method is not available on the runtime platform; for maximum portability, check the constant |
Sets the control character corresponding to the first argument to the value of the second argument.
nothing TermIOS::setCC(softint $offset = 0, softint $value = 0)
Table 4.212. Arguments for TermIOS::setCC()
|
Argument |
Description |
|---|---|
|
The control character to set. |
|
The value to set |
Table 4.213. Exceptions Thrown by TermIOS::setCC()
err | desc |
|---|---|
| This exception is thrown when the method is not available on the runtime platform; for maximum portability, check the constant |
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
bool TermIOS::isEqual(TermIOS $other)
Table 4.214. Arguments for TermIOS::isEqual()
|
Argument |
Description |
|---|---|
|
The object to compare to the current object. |
Table 4.215. Return Values for TermIOS::isEqual()
|
Return Type |
Description |
|---|---|
|
The result of comparing the current object to the argument |
Table 4.216. Exceptions thrown by TermIOS::isEqual()
|
err |
desc |
|---|---|
|
|
argument passed is not a TermIOS object |
| This exception is thrown when the method is not available on the runtime platform; for maximum portability, check the constant |
Returns a hash giving the current terminal window size in hash keys rows and columns.
static hash TermIOS::getWindowSize()
$hash = TermIOS::getWindowSize()
Not available with PO_NO_FILESYSTEM
Table 4.217. Return Values for TermIOS::getWindowSize()
Return Type | Description |
|---|---|
Returns a hash giving the current terminal window size in hash keys |
Table 4.218. Exceptions Thrown by TermIOS::getWindowSize()
err | desc |
|---|---|
| This exception is thrown when the method is not available on the runtime platform; for maximum portability, check the constant |