gitlabEdit

wave-sineVT Sequences

We need to filter and build the VT sequences.

In your own terminal emulator, VT sequences are the power of any terminal emulator found in literally every PC.

This feature provides several filtering and manipulation tools which allow you to perform these operations on strings that contain escape sequences under the Terminaux.Sequences namespace.


VT sequence types

Each type of VT sequence contain their own class files that stores sequence generation functions based on the given action and argument. Here are a list of supported sequence types:

Sequence type
Description

APC sequences

Application program command

C1 sequences

8-bit control characters

CSI sequences

Controls beginning with control sequence introducer

DCS sequences

Device control

ESC sequences

Controls beginning with ESC

OSC sequences

Operating system command sequences

PM sequences

Privacy message

To learn more about these sequences, visit the below page:


Usage

Place the using Terminaux.Sequences; clause at the top of the file that you want to call these functions in. You need to put the class name VtSequenceTools before the function name mentioned above so that it looks like this:

Here are some of the common tools. Expand one of the expandables to get more info.

chevron-rightAvailable functionshashtag

Currently, these tools are provided:

Function
Description

FilterVTSequences()

Filters all of the VT sequences that are of either a single type or of multiple types

MatchVTSequences()

Matches all of the VT sequences that are of either a single type or of multiple types

IsMatchVTSequences()

Does the string contain all of the VT sequences or a VT sequence of one or more types?

IsMatchVTSequencesSpecific()

Does the string contain all of the VT sequences or a VT sequence of any specific type?

SplitVTSequences()

Splits all of the VT sequences that are either of a single type or of multiple types

DetermineTypeFromText()

Determines the VT sequence type from the given text

chevron-rightSequence builderhashtag

Terminaux offers a Builder namespace that contains building blocks for building a VT sequence for your console applications.

It starts with VtSequenceBasicChars which allows you to get a variety of starting-point characters for your VT sequence in case you want to manually build the sequence yourself.

Here are the available characters:

Character code
Character number
Character property

BEL

\x07

BellChar

BS

\x08

BackspaceChar

CR

\x0D

CarriageReturnChar

ENQ

\x05

ReturnTerminalStatusChar

FF

\x0C

FormFeedChar

LF

\x0A

LineFeedChar

SI

\x0F

StandardCharacterSetChar

SO

\x0E

AlternateCharacterSetChar

SP

" "

SpaceChar

TAB

\x09

HorizontalTabChar

VT

\x0B

VerticalTabChar

ESC

\x1B

EscapeChar

ST

\x9C

StChar

CSI

\x9B

CsiChar

OSC

\x9D

OSCChar

APC

\x9F

APCChar

DCS

\x90

DCSChar

PM

\x9E

PMChar

The builder also provides a powerful tool which allows you to build almost any VT sequence using only the arguments and the specific type of VT sequence (Character attributes for example). This tool is found inside the VtSequenceBuilderTools class under the Terminaux.Sequences.Builder namespace.

Currently, it provides these tools:

Function
Description
Returns

BuildVtSequence()

Builds a VT sequence

A string consisting of a VT sequence of the requested type with the requested arguments

DetermineTypesFromSequence()

Determines the types from a VT sequence

An enumerable containing a list of types and specific types

chevron-rightOperationshashtag

When Terminaux tokenizes all VT sequences found in a target text, one of the below operations happen.

There are currently four types of operations.

Operation

Filtering

FilterVTSequences() replaces the found sequences with blanks. You can optionally replace it with something, like a text, a syntax, or even another VT sequence.

Matching

MatchVTSequences() gets all the matched sequences. You can then wrap the values in the for or the foreach loop to get information for each sequence.

Querying

IsMatchVTSequences() checks the text to see if any part of the text is a VT sequence.

IsMatchVTSequencesSpecific() checks the text for any specific VT sequence type.

Splitting

SplitVTSequences() splits the text with the VT sequences as delimiters.

chevron-rightUsage in console writers for Monohashtag

All console writers internally use the VT sequence filtering tools, like GetFilteredPositions(), to be able to determine the exact text position. This is to work around Linux Mono installs that report wrong position when VT sequences are appended.

circle-info

This workaround was not necessary as of the modern .NET implementation, but the workaround is still in place, because Terminaux targets .NET Standard, which means that it can be used for .NET Framework console projects, and, thus, Mono on Linux.

It works by seeking through every visible letter from the text in the form of "advancing" so that GetFilteredPositions() can make sure that the filtered positions are actually correct and sought "to the last letter" rather than "past the last letter" that Mono and the normal Console.Write() and Console.WriteLine() functions were suffering.

Last updated