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

The 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. If TryLoad() fails and you've specified a name, it throws an exception. Otherwise, it gives you a fallback TermInfoDesc 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. If TryLoad() fails or $TERM is not specified, it gives you a fallback TermInfoDesc 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 a TermInfoDesc instance corresponding to your terminal type.

  • Fallback: Returns a TermInfoDesc instance corresponding to xterm-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:

<ESCAPE> is not a parameter at index 0
=        is not a parameter at index 1

%p1  starts at index 2
  Representation: %p1
  Index:          2
%' ' starts at index 5
  Representation: %' '
  Index:          5
%+   starts at index 9
  Representation: %+
  Index:          9
%c   starts at index 11
  Representation: %c
  Index:          11
%p2  starts at index 13
  Representation: %p2
  Index:          13
%' ' starts at index 16
  Representation: %' '
  Index:          16
%+   starts at index 20
  Representation: %+
  Index:          20
%c   starts at index 22
  Representation: %c
  Index:          22

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.