NAME
Term::Detect - Detect running under terminal (and get terminal information)
VERSION
version 0.08
SYNOPSIS
use Term::Detect qw(detect_terminal);
say "Running under terminal" if detect_terminal();
DESCRIPTION
FUNCTIONS
detect_terminal([$flag]) => ANY
Return undef if not detected running under terminal. Otherwise return a hash of information about terminal (emulator software, color depth). Some information are only returned if requested via $flag
, for performance reason.
$flag
is a string and can contain one or more characters to enable/request extra information. Currently known flags:
p (for parent processes)
Result:
emulator_engine => STR
emulator_software => STR
Currently Konsole and xterm can be detected through environment because they publish some environment variables.
If $flag contains "p", will execute
pstree
to try to find out emulator software from parent process.color_depth => INT
Either 0 (does not support ANSI color codes), 16, 256, or 16777216 (2**24).
default_bgcolor => STR (6-hexdigit RGB)
For example, any xterm is assumed to have white background (ffffff) by default, while Konsole is assumed to have black (000000).
unicode => BOOL
Whether terminal supports Unicode/wide characters.
detect_terminal_cached([$flag]) => ANY
Just like detect_terminal()
but will cache the result. Can be used by applications or modules to avoid repeating detection process.
TODO
Better detection of terminal emulator's background color by peeking into its configuration.
SEE ALSO
AUTHOR
Steven Haryanto <stevenharyanto@gmail.com>
COPYRIGHT AND LICENSE
This software is copyright (c) 2013 by Steven Haryanto.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.