NAME
Terminal::Control - Perl extension for terminal control
SYNOPSIS
use Terminal::Control;
# Clear screen.
clear_screen();
# Reset screen.
reset_screen();
# Get terminal size and print to screen.
my ($rows, $cols, $xpix, $ypix) = winsize();
printf ("%s\n%s\n%s\n%s\n", $rows, $cols, $xpix, $ypix);
# Get chars and print to screen.
($rows, $cols) = chars();
printf ("%s\n%s\n", $rows, $cols);
# Get pixels and print to screen.
($xpix, $ypix) = pixels();
printf ("%s\n%s\n", $xpix, $ypix);
# Get cursor position.
my ($y, $x) = get_cursor_position();
printf ("%s\n%s\n", $y, $x);
# Set cursor position.
my $rows = 20;
my $cols = 80;
set_cursor_position(20, 80);
Aliases
*reset_terminal = \&reset_screen;
*clear_terminal = \&clear_screen;
*reset = \&reset_screen;
*clear = \&clear_screen;
Requirement
The Perl header 'sys/ioctl.ph' is required for ioctl and TIOCGWINSZ.
DESCRIPTION
Implemented Methods
The following methods have been implemented so far:
clear_screen()
reset_screen()
get_cursor_position()
set_cursor_position()
winsize()
chars()
pixels()
Method description
The method clear_screen is clearing the terminal. This is similar to the system call system('clear'). The method reset_screen is reseting the terminal. This is similar to the system call system('reset').
The method winsize gets the dimensions in x-direction and y-direction of the terminal. The methods chars and pixels extract chars (rows and cols) and pixels (xpix and ypix.)
The method get_cursor_position() gets the current cursor position in the terminal window. The method set_cursor_position() sets the cursor position in the terminal window.
Programmable background
The methods clear_screen and reset_screen are using escape sequences. Doing this no other Perl modules are needed to clear and reset a screen. Both are in principle one liners.
The method winsize is using the C/C++ header for the system ioctl call and there the command TIOCGWINSZ. The call return winsize in rows and cols and xpix and ypix.
SEE ALSO
ASCII escape sequences
AUTHOR
Dr. Peter Netz, <ztenretep@cpan.org>
COPYRIGHT AND LICENSE
Copyright (C) 2022 by Dr. Peter Netz
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.30.0 or, at your option, any later version of Perl 5 you may have available.