Skip to content

icanhasjonas/Ansi

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

.NET Ansi extensions for StringBuilder

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published