Ansi 1.0.3

Simple StringBuilder extensions for adding ansi escape sequences

Install-Package Ansi -Version 1.0.3
dotnet add package Ansi --version 1.0.3
<PackageReference Include="Ansi" Version="1.0.3" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Ansi --version 1.0.3
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

Ansi

Ansi extensions for your favourite StringBuilder

Example


/*** NOTE: To use esapce sequences on your Windows 
  Console, you need to enable virtual terminal 
  processing. This is easy; */
WindowsConsole.TryEnableVirtualTerminalProcessing();
/* TryEnableVirtualTerminalProcessing shouldn't fail 
   and only really does something on Windows Platforms
*/
Console.Write( new StringBuilder()
	.SetTitle("Hello World")
	.HideCursor()
	.SaveState() /* save state so we can restore it top of next loop*/
);

for( var i = 0;; i++ ) {
	/* What, ain't monochrome good enough for ya? */
	var color = new AnsiColor(
		(byte)(128 + Math.Sin( i / 200d ) * 127),
		(byte)(128 + Math.Sin( i / 100d ) * 127),
		(byte)(128 + Math.Sin( i / 130d ) * 80) );

	Console.Write( new StringBuilder()
		.RestoreState()
		.SaveState()
		.SetMode( Mode.Reset )
		.Append( "HELLO" )
		.SetMode( Mode.Bold )
		.SetForegroundColor( color )
		.Append( "WORLD" )
	);
	Thread.Sleep( 25 );
}
using static Ansi.AnsiFormatter;

Console.WriteLine( Colorize( $"Hello {ConsoleColor.Red} World" );
Console.WriteLine( Colorize( $"Hello {Rgb(100,20,30)} World" );

Ansi

Ansi extensions for your favourite StringBuilder

Example


/*** NOTE: To use esapce sequences on your Windows 
  Console, you need to enable virtual terminal 
  processing. This is easy; */
WindowsConsole.TryEnableVirtualTerminalProcessing();
/* TryEnableVirtualTerminalProcessing shouldn't fail 
   and only really does something on Windows Platforms
*/
Console.Write( new StringBuilder()
	.SetTitle("Hello World")
	.HideCursor()
	.SaveState() /* save state so we can restore it top of next loop*/
);

for( var i = 0;; i++ ) {
	/* What, ain't monochrome good enough for ya? */
	var color = new AnsiColor(
		(byte)(128 + Math.Sin( i / 200d ) * 127),
		(byte)(128 + Math.Sin( i / 100d ) * 127),
		(byte)(128 + Math.Sin( i / 130d ) * 80) );

	Console.Write( new StringBuilder()
		.RestoreState()
		.SaveState()
		.SetMode( Mode.Reset )
		.Append( "HELLO" )
		.SetMode( Mode.Bold )
		.SetForegroundColor( color )
		.Append( "WORLD" )
	);
	Thread.Sleep( 25 );
}
using static Ansi.AnsiFormatter;

Console.WriteLine( Colorize( $"Hello {ConsoleColor.Red} World" );
Console.WriteLine( Colorize( $"Hello {Rgb(100,20,30)} World" );

Release Notes

Updated repo URLs

  • .NETStandard 2.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
1.0.3 970 11/27/2018
1.0.2 1,349 11/3/2017
1.0.1 790 10/19/2017
1.0.0 819 10/11/2017