Lightweight, simple library that provides an easy and intuitive way for adding color to your console applications, allowing you to add multiple different colors and styles to the same string variable.
Installation • Usage • Contributing • Support
The latest stable version is available on NuGet
dotnet add package AnsiStyles
Alternatively, you can easily build the package from source if needed
git clone https://github.com/Haise777/AnsiStyles
cd AnsiStyles/AnsiStyles
dotnet build --configuration Release
# Here you can find the compiled assembly file 'AnsiStyles.dll'
cd bin/Release/net6.0
You can add the compiled assembly to your projects by adding a reference to the assembly file, you can follow this entry in a Microsoft article for more information.
Here's a simple code demonstrating all you need to know about the intended use case of this library.
var rs = StringStyle.Reset;
var fc = StringStyle.Foreground;
var prpl = fc[129];
string text = $"This is {prpl}purple{rs} and this is {fc[196]}red{rs}";
Console.WriteLine(text); //Will print out 'text' with purple and red colored
//Can also use some ANSI code for styling
var boBlue = fc[21].Bold().Outline();
Console.WriteLine(fc[70].Faint() + "some text" + $"{boBlue} bold outlined blue{rs}");
//You can also concat it with regular strings
var text2 = fc.Yellow + "This is yellow " + rs + prpl + "and this is purple";
Console.WriteLine(text2);
Console.WriteLine("Look, i'm still purple!");
Console.WriteLine(rs); //Remember to always apply reset to the end of the strings
Console.WriteLine("i'm normal now!"); //Or you can just print the reset out, else the applied color/style
//will keep bleading in subsequent prints until it finds a reset
//All of the above but for the background of the string
var bc = StringStyle.Background;
Console.WriteLine(bc.White + fc.Black + "Black text with White highlighting" + rs);
fc.ColorTest(); //prints out all the available colors codes
bc.ColorTest();
- Just fork and clone the repository
- Then commit and pull request only for the
dev
branch.
- If you encouter a bug or would like to request a feature, please submit an issue.
- For any other question that is not related to bugs or feature, feel free to contact me.
AnsiStyles is released under BSD 3-Clause license
Contact me
Email: gashimabucoro@proton.me · Discord: @.haise_san