AnsiVtConsole.NetCore
1.0.12
See the version list below for details.
dotnet add package AnsiVtConsole.NetCore --version 1.0.12
NuGet\Install-Package AnsiVtConsole.NetCore -Version 1.0.12
<PackageReference Include="AnsiVtConsole.NetCore" Version="1.0.12" />
paket add AnsiVtConsole.NetCore --version 1.0.12
#r "nuget: AnsiVtConsole.NetCore, 1.0.12"
// Install AnsiVtConsole.NetCore as a Cake Addin #addin nuget:?package=AnsiVtConsole.NetCore&version=1.0.12 // Install AnsiVtConsole.NetCore as a Cake Tool #tool nuget:?package=AnsiVtConsole.NetCore&version=1.0.12
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
This project is licensed under the terms of the MIT license: LICENSE.md
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:
Print directives:
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:
Version history
1.0.12 - 12-17-2022
- rename Writeln methods by WriteLine
- suppress Log,Logln & logger refactoring
- add code documentation
Product | Versions 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. |
-
net6.0
- Microsoft.CodeAnalysis.CSharp.Scripting (>= 4.4.0)
- Microsoft.Extensions.Hosting (>= 7.0.0)
- Newtonsoft.json (>= 13.0.2)
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 | 735 | 2/15/2024 |
1.0.24 | 264 | 2/15/2024 |
1.0.20 | 5,205 | 1/23/2023 |
1.0.19 | 937 | 1/18/2023 |
1.0.18 | 921 | 1/14/2023 |
1.0.17 | 1,147 | 1/10/2023 |
1.0.16 | 968 | 1/5/2023 |
1.0.15 | 1,168 | 12/17/2022 |
1.0.14 | 817 | 12/17/2022 |
1.0.13 | 808 | 12/17/2022 |
1.0.12 | 797 | 12/17/2022 |
1.0.11 | 776 | 12/16/2022 |
1.0.9 | 768 | 12/14/2022 |
milestone 1