Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

90 Commits

Repository files navigation

Build status

Colorful.Console is a C# library that wraps around the System.Console class, exposing enhanced styling functionality.

Colorful.Console icon

How to Get It

git clone https://github.com/tomakita/Colorful.Console.git

Basic Usage

usingSystem;usingSystem.Drawing;usingConsole=Colorful.Console;
...
...Console.WriteLine("console in pink",Color.Pink);Console.WriteLine("console in default");

Basic Example

Write With Full System.Drawing.Color Support

intr=225;intg=255;intb=250;for(inti=0;i<10;i++){Console.WriteLine(storyFragments[i],Color.FromArgb(r,g,b));r-=18;b-=9;}

Write With Full System.Drawing.Color Support

Format Text Using Two Colors

stringdream="a dream of {0} and {1} and {2} and {3} and {4} and {5} and {6} and {7} and {8} and {9}...";string[]fruits=newstring[]{"bananas","strawberries","mangoes","pineapples","cherries","oranges","apples","peaches","plums","melons"};Console.WriteLineFormatted(dream,Color.LightGoldenrodYellow,Color.Gray,fruits);

Format Text Using Two Colors

Format Text Using Several Colors

stringdream="a dream of {0} and {1} and {2} and {3} and {4} and {5} and {6} and {7} and {8} and {9}...";Formatter[]fruits=newFormatter[]{newFormatter("bananas",Color.LightGoldenrodYellow),newFormatter("strawberries",Color.Pink),newFormatter("mangoes",Color.PeachPuff),newFormatter("pineapples",Color.Yellow),newFormatter("cherries",Color.Red),newFormatter("oranges",Color.Orange),newFormatter("apples",Color.LawnGreen),newFormatter("peaches",Color.MistyRose),newFormatter("plums",Color.Indigo),newFormatter("melons",Color.LightGreen),};Console.WriteLineFormatted(dream,Color.Gray,fruits);

Format Text Using Several Colors

Alternate Between 2 or More Colors Based on Number of Console Writes

ColorAlternatorFactoryalternatorFactory=newColorAlternatorFactory();ColorAlternatoralternator=alternatorFactory.GetAlternator(2,Color.Plum,Color.PaleVioletRed);for(inti=0;i<15;i++){Console.WriteLineAlternating("cats",alternator);}

Alternate Between 2 or More Colors Based on Number of Console Writes

Alternate Between 2 or More Colors Based on 1 or More Regular Expressions

ColorAlternatorFactoryalternatorFactory=newColorAlternatorFactory();ColorAlternatoralternator=alternatorFactory.GetAlternator(new[]{"hiss","m[a-z]+w"},Color.Plum,Color.PaleVioletRed);for(inti=0;i<15;i++){stringcatMessage="cats";if(i%3==0){catMessage=meowVariant[meowCounter++];}elseif(i%10==0){catMessage="hiss";}Console.WriteLineAlternating(catMessage,alternator);}

Alternate Between 2 or More Colors Based on 1 or More Regular Expressions

Style Specific Regions of Text

StyleSheetstyleSheet=newStyleSheet(Color.White);styleSheet.AddStyle("rain[a-z]*",Color.MediumSlateBlue);Console.WriteLineStyled(storyAboutRain,styleSheet);

Alternate Between 2 or More Colors Based on 1 or More Regular Expressions

Style Specific Regions of Text, Performing a Simple Transformation

StyleSheetstyleSheet=newStyleSheet(Color.White);styleSheet.AddStyle("rain[a-z]*",Color.MediumSlateBlue, match =>match.ToUpper());Console.WriteLineStyled(storyAboutRain,styleSheet);

Style Specific Regions of Text, Performing a Simple Transformation

Style Specific Regions of Text, Performing a Transformation Based on Surrounding Text

StyleSheetstyleSheet=newStyleSheet(Color.White);styleSheet.AddStyle("rain[a-z]*",Color.MediumSlateBlue,(unstyledInput,matchLocation,match)=>{if(unstyledInput[matchLocation.End]=='.'){return"marshmallows";}else{return"s'mores";}});Console.WriteLineStyled(storyAboutRain,styleSheet);

Style Specific Regions of Text, Performing a Simple Transformation

Convert Text to ASCII Art Using a Default Font

intDA=244;intV=212;intID=255;for(inti=0;i<3;i++){Console.WriteAscii("HASSELHOFF",Color.FromArgb(DA,V,ID));DA-=18;V-=36;}

Convert Text to ASCII Art Using a Default Font

Convert Text to ASCII Art Using FIGlet Fonts

FigletFontfont=FigletFont.Load("chunky.flf");Figletfiglet=newFiglet(font);Console.WriteLine(figlet.ToAscii("Belvedere"),ColorTranslator.FromHtml("#8AFFEF"));Console.WriteLine(figlet.ToAscii("ice"),ColorTranslator.FromHtml("#FAD6FF"));Console.WriteLine(figlet.ToAscii("cream."),ColorTranslator.FromHtml("#B8DBFF"));

Convert Text to ASCII Art Using a Default Font

Style Collections With a Gradient

List<char>chars=newList<char>(){'r','e','x','s','z','q','j','w','t','a','b','c','l','m','r','e','x','s','z','q','j','w','t','a','b','c','l','m','r','e','x','s','z','q','j','w','t','a','b','c','l','m','r','e','x','s','z','q','j','w','t','a','b','c','l','m'};Console.WriteWithGradient(chars,Color.Yellow,Color.Fuchsia,14);

Style Collections With a Gradient

Usage Notes

Console colors can be set back to their defaults using the Colorful.Console.ReplaceAllColorsWithDefaults function.

Individual colors in the console's color palette can be replaced using the Colorful.Console.ReplaceColor function.

Colorful.Console can only write to the console in 16 different colors (including the black that's used as the console's background, by default!) in a single console session. This is a limitation of the Windows console itself (ref: MSDN), and it's one that we weren't able to work our way around. If you know of a workaround, let us know!

About

Style your .NET console output!

Resources

Stars

3 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages