Terminal Info
What's your terminal type and its capabilities?
Terminal information database is a list of terminal capabilities that control how console applications determine capabilities in the terminal type that the emulator uses, such as the color depth capability and the method of writing sequences that change the background and the foreground color. Termcap was implemented in 1978, and Terminfo was implemented in 1981-1982. Applications that use ncurses
(for non-C# applications) or Terminaux (for C# applications) can use the database to get the capabilities.
TermInfoDesc
class
TermInfoDesc
classThe TermInfo feature of Terminaux can be found in the base console tools namespace, Terminaux.Base.TermInfo
. TermInfoDesc
's functions contain the following:
TryLoad()
: Tries to load a terminal information description given the terminal type name.Load()
: Loads a terminal information description given the terminal type name, and if the name is not given, it uses the current terminal type that your terminal emulator uses. IfTryLoad()
fails and you've specified a name, it throws an exception. Otherwise, it gives you a fallbackTermInfoDesc
instance.LoadSafe()
: Loads a terminal information description given the terminal type name, and if the name is not given, it uses the current terminal type that your terminal emulator uses. IfTryLoad()
fails or$TERM
is not specified, it gives you a fallbackTermInfoDesc
instance.GetBuiltins()
: Gets a list of built-in terminal type names that Terminaux can find in the built-in capabilities list.
This feature used to be exclusive to Linux users mostly, but we've added the built-in terminal information database so that Windows applications are now free to analyze such data, although conhost
doesn't emulate any terminal, and is assumed to be compatible with xterm
.
Built-in terminal capabilities can be accessed as properties in the TermInfoDesc
instance that the loading functions return when parsing the terminal information files. For extra properties that Terminaux doesn't cover, this class provides you with the following functions:
GetBoolean()
: Gets a boolean value that holds either true or false. Returns null, however, if Terminaux is unable to get the value.GetNum()
: Gets a number value that holds a numeric integer. Returns null, however, if Terminaux is unable to get the value.GetString()
: Gets a textual value. Returns null, however, if Terminaux is unable to get the value.
TermInfoDesc
also allows you to get an instance of TermInfoDesc
corresponding to the current terminal type as specified in the $TERM
environment variable for non-Windows systems. Windows systems always use the xterm-256color
terminal for maximum compatibility. You can get this instance using one of the following properties:
Current
: Returns aTermInfoDesc
instance corresponding to your terminal type.Fallback
: Returns aTermInfoDesc
instance corresponding toxterm-256color
.
TermInfo string parameters
Terminaux supports all the printf(3)-like string parameters that are defined in the Parameterized Strings section from the terminfo(5)
manual page found in the NCurses library. The following string parameters are supported according to the types:
Parameter Extraction
You can extract parameters from a capability string by using the ExtractParameters()
function found in the ParameterExtractor
class, passing it the capability that you want to parse. This returns an array of ParameterInfo
instances that contain the following properties:
Representation: The parameter that has been extracted from the capability string.
Index: Zero-based index of the first character of the representation relative to the capability string.
For example, we have this string: <ESCAPE>=%p1%' '%+%c%p2%' '%+%c
, with <ESCAPE>
being a designator for \u001b
that corresponds to the ESCAPE character essential for all terminal VT sequences according to Unicode and ASCII encoding. When we ran this string through the parameter extractor, we got this result:
For now, it's up to you how to process such strings to manipulate with the parameters. However, in a future Terminaux release, we'll release features that will assist you.
Last updated