Skip to content

Latest commit

 

History

History
53 lines (41 loc) · 1.17 KB

README.md

File metadata and controls

53 lines (41 loc) · 1.17 KB

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" );