AnsiVtConsole.NetCore 1.0.11

There is a newer version of this package available.
See the version list below for details.
dotnet add package AnsiVtConsole.NetCore --version 1.0.11                
NuGet\Install-Package AnsiVtConsole.NetCore -Version 1.0.11                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="AnsiVtConsole.NetCore" Version="1.0.11" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add AnsiVtConsole.NetCore --version 1.0.11                
#r "nuget: AnsiVtConsole.NetCore, 1.0.11"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install AnsiVtConsole.NetCore as a Cake Addin
#addin nuget:?package=AnsiVtConsole.NetCore&version=1.0.11

// Install AnsiVtConsole.NetCore as a Cake Tool
#tool nuget:?package=AnsiVtConsole.NetCore&version=1.0.11                

AnsiVtConsole.NetCore AnsiVtConsole.NetCore


AnsiVtConsole.NetCore library provides ANSI VT support (cursor,colors,screen size) for multi-plateform (windows, linux, osx, arm) console applications using C# and .NET Core 6

licence mit This project is licensed under the terms of the MIT license: LICENSE.md
last commit version


Features

The library provides functionalities needed to build console applications running in a terminal (WSL/WSL2, cmd.exe, ConEmu, bash, ...) with text interface. That includes:

  • a text printer engine that supports print directives allowing to manage console functionalities from text itself, as html would do but with a simplest grammar (that can be configured). That makes possible colored outputs, cursor control, text scrolling and also dynamic C# execution (scripting), based on System.Console and ANSI VT100 / VT52 (VT100 type Fp or 3Fp, Fs, CSI, SGR)
  • The console output can be controlled by:
    • tokens in a string (print directives)
    • as string shortcuts (dynamic ansi vt strings)
    • throught API methods

Usage

using cons=AnsiVtConsole.NetCore;
// get the ansi vt console
var console = new cons.AnsiVTConsole();

1. using the text parser:

console.Write("(br,f=yellow,b=red)yellow text on red background(br)(f=cyan)current time is: (exec=System.DateTime.Now,br)");

2. using the string shortcuts :

using static AnsiVtConsole.NetCore.Component.EchoDirective;

System.Console.Out.Writeline($"{Br}{Yellow}{BRed}yellow text on red background{Br}{Cyan}current time is: {System.DateTime.Now}{Br}");

both outputs:

output

text can contains echo directives that changes the echo behavior. the echo directive syntax is formed according to this pattern: (printDirective) or (printDirective=printDirectiveValue)

  • multiple echo directives can be separated by a , that can be grouped in a single text in parentheses: (echoDirective1,echoDirective2=..,echoDirective3)
  • an echo directive value can be written inside a 'code' text block, depending on each echo directive, with the syntax: [[...]]
  • symbols of this grammar can be configured throught the class: AnsiVtConsole.NetCore.Component.Settings
  • alternatively to the print directives you can use the strings shortcuts from the class: AnsiVtConsole.NetCore.Component.EchoDirective

1. Colorization

f=ConsoleColor      : set foreground color
f8=Int32            : set foreground 8bit color index, where 0 <= index <= 255
f24=Int32:Int32:Int32 : set foreground 24bit color red:green:blue, where 0 <= red,green,blue <= 255
f=ConsoleColor      : set foreground color
b=ConsoleColor      : set background color
b8=Int32            : set background 8bit color index, where 0 <= index <= 255
b24=Int32:Int32:Int32 : set background 24bit color red:green:blue, where 0 <= red,green,blue <= 255
df=ConsoleColor     : set default foreground
db=ConsoleColor     : set default background
bkf                 : backup foreground color
bkb                 : backup background color
rsf                 : restore foreground color
rsb                 : restore background color
rdc                 : restore default colors```

ConsoleColor := darkblue|darkgreen|darkcyan|darkred|darkmagenta|darkyellow|gray|darkgray|blue|green|cyan|red|magenta|yellow|white (not case sensitive)

2. Text decoration (vt100)

uon                 : underline on
invon               : inverted colors on
tdoff               : text decoration off and reset default colors
lion                : ligtht colors
bon                 : bold on
blon                : blink on (not supported on Windows)

3. Echo flow control

cls                 : clear screen
br                  : jump begin of next line (line break)
bkcr                : backup cursor position
rscr                : restore cursor position
crx=Int32           : set cursor x (0<=x<=WindowWidth)
cry=Int32           : set cursor y (0<=y<=WindowHeight)
cleft               : move cursor left
cright              : move cursor right
cup                 : move cursor up
cdown               : move cursor down
cnleft=Int32        : move cursor n characters left
cnright=Int32       : move cursor n characters right
cnup=Int32          : move cursor n lines up
cndown=Int32        : move cursor n lines down
cl                  : clear line
clleft              : clear line from cursor left
clright             : clear line from cursor right
chome               : move cursor to upper left corner
tab                 : add a tab

4. Script engine

exec=CodeBlock|[[CodeBlock]] : executes and echo result of a C# code block

5. Application control

info                : output infos about the console
exit                : exit the current process

Examples

To try these examples, compile and run the project AnsiVtConsole.NetCore.Examples:

example1 example1 example1 example1


Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on AnsiVtConsole.NetCore:

Package Downloads
CommandLine.NetCore

Provides support to handle command line arguments (parse, validate, command pattern) for .Net Core console applications with ANSI VT support (cursor,colors,screen size) for multi-plateform (windows, linux, osx, arm) console applications using C# and .NET Core 6 or higher

AnsiVtConsole.NetCore.Imaging

ANSI VT console library for .Net Core system console Imaging component

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.26 710 2/15/2024
1.0.24 260 2/15/2024
1.0.20 4,959 1/23/2023
1.0.19 932 1/18/2023
1.0.18 916 1/14/2023
1.0.17 1,139 1/10/2023
1.0.16 963 1/5/2023
1.0.15 1,164 12/17/2022
1.0.14 813 12/17/2022
1.0.13 804 12/17/2022
1.0.12 793 12/17/2022
1.0.11 772 12/16/2022
1.0.9 764 12/14/2022

milestone 1