Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/icanhasjonas/ansi
.NET Ansi extensions for StringBuilder
https://github.com/icanhasjonas/ansi
Last synced: about 2 months ago
JSON representation
.NET Ansi extensions for StringBuilder
- Host: GitHub
- URL: https://github.com/icanhasjonas/ansi
- Owner: icanhasjonas
- License: mit
- Created: 2017-10-11T17:15:25.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2021-04-29T19:44:31.000Z (almost 4 years ago)
- Last Synced: 2024-12-09T01:48:00.940Z (about 2 months ago)
- Language: C#
- Size: 11.7 KB
- Stars: 5
- Watchers: 2
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Ansi
Ansi extensions for your favourite `StringBuilder`# Example
```csharp
/*** 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
*/
``````csharp
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 );
}
``````csharp
using static Ansi.AnsiFormatter;Console.WriteLine( Colorize( $"Hello {ConsoleColor.Red} World" );
Console.WriteLine( Colorize( $"Hello {Rgb(100,20,30)} World" );```