Colorify was created to simplify and automate tasks related to .Net console formatting. Was born in HardHat project as a Class. Now grown up as a library and can be used by other console applications.
The Code is Dark and Full of Errors! Console is your friend ... don't be afraid!
These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.
What things you need to install?
Colorify supports netstandard2.1
, netcoreapp3.1
, net5.0
, net6.0
and net7.0
target frameworks.
Colorify is available as project or package. We strong recommend add as a NuGet package if don't need make modifications directly on the source code library.
Follow these instructions to add Colorify in your project.
- dein.ToolBox Library
In your project folder, where is located .csproj file run this command on terminal:
dotnet add package dein.Colorify
If you want to use OS class highly recommend use ToolBox project.
dotnet add package dein.ToolBox
Official documentation: dotnet add package
Clone Colorify from GitHub on recommended path. Using this command on terminal:
OS | Command |
---|---|
win | git clone https://github.com/deinsoftware/colorify.git "D:\Developer\DEIN\Projects\_devCC" |
mac | git clone https://github.com/deinsoftware/colorify.git ~/Developer/DEIN/Projects/_devCC |
In your project folder, where is located .csproj file run this command on terminal:
OS | Command |
---|---|
win | dotnet add reference "D:\Developer\DEIN\Projects\_devCC\Colorify\Colorify.csproj" |
mac | dotnet add reference ~/Developer/DEIN/Projects/_devCC/Colorify/Colorify.csproj |
Official documentation: dotnet add reference
On the main class Program, add a static property Format and inside the Main method create an instance of the library according the Operative System.
class Program
{
public static Format _colorify {get; set;}
static void Main(string[] args)
{
switch (OS.GetCurrent())
{
case "win":
case "gnu":
_colorify = new Format(Theme.Dark);
break;
case "mac":
_colorify = new Format(Theme.Light);
break;
}
//Foo()
//Bar()
_colorify.ResetColor();
_colorify.Clear();
}
}
Take note that _colorify.ResetColor();
command is important in order to reset default terminal colors when programs finish.
If you want use themes with current user color use _colorify = new Format(new ThemeLight());
or _colorify = new Format(new ThemeDark());
If you want to use _colorify
in other class, add a static using to Program
class:
using static Namesapace.Program;
replace Namespace with a defined namespace in your project.
Keep calm, you are almost done. Review this usage steps and enjoy life.
To understand how this library works, take a look inside Sample folder. Better easy to use a guide than words.
Just go to Sample
project folder and run this command on terminal:
cd Sample
dotnet run
Colorify colors was created inspired on Bootstrap colors a list whit a meaning easy to remember.
_colorify.WriteLine("Text Default", Colors.txtDefault);
_colorify.WriteLine("Text Muted", Colors.txtMuted);
_colorify.WriteLine("Text Primary", Colors.txtPrimary);
_colorify.WriteLine("Text Success", Colors.txtSuccess);
_colorify.WriteLine("Text Info", Colors.txtInfo);
_colorify.WriteLine("Text Warning", Colors.txtWarning);
_colorify.WriteLine("Text Danger", Colors.txtDanger);
_colorify.WriteLine("Background Default", Colors.bgDefault);
_colorify.WriteLine("Background Muted", Colors.bgMuted);
_colorify.WriteLine("Background Primary", Colors.bgPrimary);
_colorify.WriteLine("Background Success", Colors.bgSuccess);
_colorify.WriteLine("Background Info", Colors.bgInfo);
_colorify.WriteLine("Background Warning", Colors.bgWarning);
_colorify.WriteLine("Background Danger", Colors.bgDanger);
Light (for macOS):
Dark (for Windows and Linux):
Colors are defined on Theme folder. There is two themes Light (for macOS) and Dark (for Windows and Linux). You can edit the ThemeLight.cs
or ThemeDark.cs
files or create a new one implementing the ITheme
interface.
Take a look on official documentation: ConsoleColor Enumeration
_colorify.Write
work like Console.Write
but wrapped with colors. If you don't specify a color will use the Colors.txtDefault
by default.
_colorify.Write("Text");
_colorify.Write("Text", Colors.bgDefault);
You can stack a multiple _colorify.Write
, just remember define the last one as WriteLine.
_colorify.Write(" Default ", Colors.bgDefault);
_colorify.Write(" Muted ", Colors.bgMuted);
_colorify.Write(" Primary ", Colors.bgPrimary);
_colorify.Write(" Success ", Colors.bgSuccess);
_colorify.Write(" Info ", Colors.bgInfo);
_colorify.Write(" Warning ", Colors.bgWarning);
_colorify.WriteLine(" Danger ", Colors.bgDanger);
_colorify.WriteLine
work like Console.WriteLine
with a line terminator after the text but wrapped with colors. If you don't specify a color will use the Colors.txtDefault
by default.
_colorify.WriteLine("Text with line terminator");
_colorify.WriteLine("Text with line terminator", Colors.bgDefault);
_colorify.Write("Short Text at First Preceded with a ", Colorify.Colors.bgInfo);
_colorify.WriteLine(" Long Multi line text with Line Wrap that bring a new line", Colorify.Colors.bgSuccess);
_colorify.Wrap
works like Console.WriteLine
with a line terminator after the text but wrapped with colors. If you don't specify a color then it will use the Colors.txtDefault
by default.
_colorify.Wrap("Very long text with gentle word wrapping at the end of console");
_colorify.Wrap("Very long text with gentle word wrapping at the end of console", Colors.bgDefault);
Automatic line wrap or word wrap with long text:
_colorify.Wrap("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer sed turpis in ligula aliquet ornare tristique sed ante. Nam pretium ullamcorper condimentum. Aliquam quis sodales ex, vitae gravida metus. Suspendisse potenti. Maecenas nunc sapien, semper vel tincidunt sed, scelerisque ut est. Nunc eu venenatis libero. Nulla consectetur pretium leo. Nullam suscipit scelerisque neque fringilla volutpat. Aliquam condimentum, neque quis malesuada ultrices, mauris velit tincidunt arcu, vel sodales tortor felis quis velit. Aliquam tempus ullamcorper orci, vitae pretium leo maximus ut. Aliquam iaculis leo sed tempor mattis.", bgWarning);
All the align methods (Center/Left/Right) works like Console.WriteLine
but with align operation and wrapped with colors. If you don't specify a color will use the Colors.txtDefault
by default.
_colorify.AlignCenter("Text Aligned to Center");
_colorify.AlignRight("Text Aligned to Right");
_colorify.AlignLeft("Text Aligned to Left");
_colorify.AlignCenter("Text Aligned to Center", Colors.bgInfo);
_colorify.AlignRight("Text Aligned to Right", Colors.txtDefault);
_colorify.AlignLeft("Text Aligned to Left", Colors.txtDanger);
AlignSplit
is the way to show two values on the same line. The text will be split with pipe |
character, the first element will be aligned to left and second aligned to right.
_colorify.AlignSplit("<-Text to Left| Text to Right->");
_colorify.AlignSplit("<-Text to Left| Text to Right->", Colors.bgSuccess);
_colorify.BlankLines
works like Console.WriteLine
but without text. You can combine the amount of lines and colors. Default values will be 1
line and Colors.txtDefault
.
_colorify.BlankLines();
_colorify.BlankLines(Colorify.Colors.bgDanger);
_colorify.BlankLines(3);
_colorify.BlankLines(3, Colors.bgSuccess);
_colorify.DivisionLine
works like Console.WriteLine
but without the same character as full-width text. If you don't specify a color will use the Colors.txtDefault
by default.
_colorify.DivisionLine('-', Colors.bgDefault);
_colorify.DivisionLine('+', Colors.bgMuted);
_colorify.DivisionLine('~', Colors.bgPrimary);
_colorify.DivisionLine('=', Colors.bgSuccess);
_colorify.DivisionLine('-', Colors.bgInfo);
_colorify.DivisionLine('*', Colors.bgWarning);
_colorify.DivisionLine('.', Colors.bgDanger);
- .Net - .Net is a free and open-source web framework, developed by Microsoft and the community.
- VS Code - Code editing redefined.
- SonarQube - Continuous code quality.
Please read CONTRIBUTING for details on our code of conduct, and the process for submitting pull requests to us.
We use SemVer for versioning. For the versions available, see the Colorify on GitHub.
- Camilo Martinez [Equiman]
See also the list of contributors who participated in this project.
If this project help you reduce time to develop, you can give me a cup of coffee.
No sponsors yet! Will you be the first?
This project is licensed under the MIT License - see the LICENSE file for details.
- StackOverflow: The largest online community for programmers.
- Dot Net Perls: C# Console Color, Text and BackgroundColor.