NAME
Terminal::Identify - Perl extension for identifying the terminal emulator
SYNOPSIS
Use the package like this
use Terminal::Identify; # Exports all methods
use Terminal::Identify qw(whichterminalami); # Exports method whichterminalami()
# Identify the terminal emulator in use.
whichterminalami(["PROC"|"PATH"|"FTN"]); # Standard method call
Terminal::Identify::whichterminalami(["PROC"|"PATH"|"FTN"]); # Alternate method call
or like this
use Terminal::Identify; # Exports all methods
use Terminal::Identify qw(whichterminalami); # Exports method whichterminalami()
# Set the global output format flag of the package.
$OutputFormat = ["PROC"|"PATH"|"FTN"];
$Terminal::Identify::OutputFormat = ["PROC"|"PATH"|"FTN"];
# Identify the terminal emulator in use.
whichterminalami(); # Standard method call
Terminal::Identify::whichterminalami() ; # Alternate method call
USAGE
The string arguments in the method call in square brackets are optional. Without a subroutine argument the process name of the terminal is simply identified. The valid method arguments are separated by a logical or. These arguments are controlling the format of the output of the identified terminal.
In addition to the method arguments, a global package variable can be used to control the format of the output of the identified terminal. If the global package variable is set, the method arguments are ignored if existing in the method call.
DESCRIPTION
The main objective of this package is to provide a method which is capable of identifying the terminal emulator a logged-in user is actual using.
The logged-in user is related to a valid login shell. Knowing this, the logged-in user as well as the login shell of the logged-in user are determined. Next the terminal path to the pseudo terminal slave (pts) is identified. Based on this informations the related process of the logged-in user, the login shell and the terminal path is determined. The evaluation of the PID of the process of the running Perl script results in the PPID. The command related to this PPID is the name of the terminal emulator in use. Not only a terminal emulator can be identified by this package, it is also able to detect if a system console is being used by a logged-in user. The package also works if different terminal emulators are used and when they were spawned from on initial started terminal emulator.
The terminal emulator in use by the logged-in user can be identified by the main command whichterminalami
and the other defined aliases.
OUTPUT FORMAT
The output format of the identified terminal can be influenced by the subroutine arguments "PROC"
, "PATH"
and "FTN"
.
"PROC"
PROC => Full process of the terminal emulator in use.
"PATH"
PATH => Path to the location of the terminal emulator in use.
"FTN"
FTN => Friendly terminal name of the terminal emulator in use.
EXAMPLES
Example 1
# Load the Perl module.
use Terminal::Identify;
# Declare the terminal variable.
my $terminal;
# Method call without an argument.
$terminal = whichterminalami();
print $terminal . "\n";
# Method call with argument "PROC".
$terminal = whichterminalami("PROC");
print $terminal . "\n";
# Method call with argument "PATH".
$terminal = whichterminalami("PATH");
print $terminal . "\n";
# Method call with argument "FTN".
$terminal = whichterminalami("FTN");
print $terminal . "\n";
Example 2
# Load the Perl module.
use Terminal::Identify;
# Declare the terminal variable.
my $terminal;
# Reset the global output format flag.
$OutputFormat = "";
# Method call without an argument.
$terminal = whichterminalami();
print $terminal . "\n";
# Set the global output format flag.
$OutputFormat = "PROC";
# Method call without an argument.
$terminal = whichterminalami();
print $terminal . "\n";
# Set the global output format flag.
$OutputFormat = "PATH";
# Method call without an argument.
$terminal = whichterminalami();
print $terminal . "\n";
# Set the global output format flag.
$OutputFormat = "FTN";
# Method call without an argument.
$terminal = whichterminalami();
print $terminal . "\n";
ERROR CODES
No error codes yet
NOTES
No notes yet
SYSTEM COMPATIBILITY
The module should work on Linux and on Unix or Unix-like operating systems in general until something else was shown.
FUNCTIONALITY REQUIREMENT
Following Linux commands should be available for functionality:
ps
users
shells
passwd
which
grep
METHOD ALIASES
Aliases for whichterminalami
, which can be used are:
whichtermami <= whichterminalami
which_terminal <= whichterminalami
identify_terminal <= whichterminalami
TERMINALS TESTED
Terminal emulators tested so far with the package:
Aterm
Cool Retro Term
Deepin Terminal
Eterm
Guake Terminal
kitty
LXTerminal
MATE-Terminal
QTerminal
ROXTerm
Sakura
Terminator
Terminology
Termit
Tilda
Tilix
UXTerm
Xfce4-Terminal-Emulator
xiterm+thai
Xterm
Yakuake
LIMITATIONS
The limitations of the package are given by the Linux commands and the Linux system files which are used by the package. The Linux command ps
, the Linux command users
and the Linux command which
must be available. The Linux system files /etc/shells
and /etc/passwd
must be exist.
OPEN ISSUES
Problems were found with the use of the Inline C module. The problem is caused by user and root rights. Until this issue is resolved, the POSIX module is used instead of the C code.
KNOWN BUGS
Not known yet
ABSTRACT
The module identifies the terminal emulator which the logged-in user is using currently. For this purpose, the login shells and the logged-in users are determined. The Perl script from which we identify the terminal emulator itself runs in a pseudo terminal slave (pts) with its own identification number. This pseudo terminal slave (pts) is identified, too. Based on all the former informations, the terminal emulator in use can be determined. If the Perl script runs from within the system console, the output returns the system console.
SEE ALSO
users(1) - Linux manual page
shells(5) - Linux manual page
passwd(5) - Linux manual page
ps(1) - Linux manual page
which(1) - Linux manual page
grep(1) - Linux manual page
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.