{"id":13414887,"url":"https://github.com/tomakita/Colorful.Console","last_synced_at":"2025-03-14T22:32:22.273Z","repository":{"id":39526394,"uuid":"46247545","full_name":"tomakita/Colorful.Console","owner":"tomakita","description":"Style your .NET console output!","archived":false,"fork":false,"pushed_at":"2024-06-06T07:55:55.000Z","size":3437,"stargazers_count":1302,"open_issues_count":32,"forks_count":127,"subscribers_count":40,"default_branch":"master","last_synced_at":"2024-10-29T15:29:21.057Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tomakita.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-11-16T02:37:20.000Z","updated_at":"2024-10-29T02:49:00.000Z","dependencies_parsed_at":"2024-09-20T21:30:27.126Z","dependency_job_id":null,"html_url":"https://github.com/tomakita/Colorful.Console","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomakita%2FColorful.Console","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomakita%2FColorful.Console/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomakita%2FColorful.Console/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomakita%2FColorful.Console/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tomakita","download_url":"https://codeload.github.com/tomakita/Colorful.Console/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243641926,"owners_count":20323937,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-30T21:00:39.307Z","updated_at":"2025-03-14T22:32:21.980Z","avatar_url":"https://github.com/tomakita.png","language":"C#","funding_links":[],"categories":["Frameworks, Libraries and Tools","CLI","others","C\\#","C# #","C#","框架, 库和工具","Build Automation"],"sub_categories":["Build Automation","自动部署"],"readme":"# [Colorful.Console](http://colorfulconsole.com/)\n[![Build status](https://ci.appveyor.com/api/projects/status/hf7y1un65mdfkfbx?svg=true)](https://ci.appveyor.com/project/tomakita/colorful-console)\n\n**Colorful.Console** is a C# library that wraps around the `System.Console` class, exposing enhanced styling functionality.\n\n![Colorful.Console icon](https://github.com/tomakita/Colorful.Console/blob/master/static/colorful_icon_ngsize.png)\n\n# How to Get It\n\n- Download [`Colorful.Console`](https://www.nuget.org/packages/Colorful.Console) from NuGet.\n- Perform a Git clone\n\u003e git clone https://github.com/tomakita/Colorful.Console.git\n\n# Basic Usage\n```c#\nusing System;\nusing System.Drawing;\nusing Console = Colorful.Console;\n...\n...\nConsole.WriteLine(\"console in pink\", Color.Pink);\nConsole.WriteLine(\"console in default\");\n```\n![Basic Example](https://github.com/tomakita/Colorful.Console/blob/master/static/basic_x.png)\n\n\n# Write With Full System.Drawing.Color Support\n```c#\nint r = 225;\nint g = 255;\nint b = 250;\nfor (int i = 0; i \u003c 10; i++)\n{\n    Console.WriteLine(storyFragments[i], Color.FromArgb(r, g, b));\n\n    r -= 18;\n    b -= 9;\n}\n```\n![Write With Full System.Drawing.Color Support](https://github.com/tomakita/Colorful.Console/blob/master/static/rgb_x.png)\n\n\n# Format Text Using Two Colors\n```c#\nstring dream = \"a dream of {0} and {1} and {2} and {3} and {4} and {5} and {6} and {7} and {8} and {9}...\";\nstring[] fruits = new string[]\n{\n    \"bananas\",\n    \"strawberries\",\n    \"mangoes\",\n    \"pineapples\",\n    \"cherries\",\n    \"oranges\",\n    \"apples\",\n    \"peaches\",\n    \"plums\",\n    \"melons\"\n};\n\nConsole.WriteLineFormatted(dream, Color.LightGoldenrodYellow, Color.Gray, fruits);\n```\n![Format Text Using Two Colors](https://github.com/tomakita/Colorful.Console/blob/master/static/formatter_x1.png)\n\n\n# Format Text Using Several Colors\n```c#\nstring dream = \"a dream of {0} and {1} and {2} and {3} and {4} and {5} and {6} and {7} and {8} and {9}...\";\nFormatter[] fruits = new Formatter[]\n{\n    new Formatter(\"bananas\", Color.LightGoldenrodYellow),\n    new Formatter(\"strawberries\", Color.Pink),\n    new Formatter(\"mangoes\", Color.PeachPuff),\n    new Formatter(\"pineapples\", Color.Yellow),\n    new Formatter(\"cherries\", Color.Red),\n    new Formatter(\"oranges\", Color.Orange),\n    new Formatter(\"apples\", Color.LawnGreen),\n    new Formatter(\"peaches\", Color.MistyRose),\n    new Formatter(\"plums\", Color.Indigo),\n    new Formatter(\"melons\", Color.LightGreen),\n};\n\nConsole.WriteLineFormatted(dream, Color.Gray, fruits);\n```\n![Format Text Using Several Colors](https://github.com/tomakita/Colorful.Console/blob/master/static/formatter_x2.png)\n\n\n# Alternate Between 2 or More Colors Based on Number of Console Writes\n```c#\nColorAlternatorFactory alternatorFactory = new ColorAlternatorFactory();\nColorAlternator alternator = alternatorFactory.GetAlternator(2, Color.Plum, Color.PaleVioletRed);\n\nfor (int i = 0; i \u003c 15; i++)\n{\n    Console.WriteLineAlternating(\"cats\", alternator);\n}\n```\n![Alternate Between 2 or More Colors Based on Number of Console Writes](https://github.com/tomakita/Colorful.Console/blob/master/static/alternator_x2.png)\n\n\n# Alternate Between 2 or More Colors Based on 1 or More Regular Expressions\n```c#\nColorAlternatorFactory alternatorFactory = new ColorAlternatorFactory();\nColorAlternator alternator = alternatorFactory.GetAlternator(new[] { \"hiss\", \"m[a-z]+w\" }, Color.Plum, Color.PaleVioletRed);\n\nfor (int i = 0; i \u003c 15; i++)\n{\n    string catMessage = \"cats\";\n\n    if (i % 3 == 0)\n    {\n        catMessage = meowVariant[meowCounter++];\n    }\n    else if (i % 10 == 0)\n    {\n        catMessage = \"hiss\";\n    }\n\n    Console.WriteLineAlternating(catMessage, alternator);\n}\n```\n![Alternate Between 2 or More Colors Based on 1 or More Regular Expressions](https://github.com/tomakita/Colorful.Console/blob/master/static/alternator_x1.png)\n\n\n# Style Specific Regions of Text\n```c#\nStyleSheet styleSheet = new StyleSheet(Color.White);\nstyleSheet.AddStyle(\"rain[a-z]*\", Color.MediumSlateBlue);\n\nConsole.WriteLineStyled(storyAboutRain, styleSheet);\n```\n![Alternate Between 2 or More Colors Based on 1 or More Regular Expressions](https://github.com/tomakita/Colorful.Console/blob/master/static/styler_x1.png)\n\n\n# Style Specific Regions of Text, Performing a Simple Transformation\n```c#\nStyleSheet styleSheet = new StyleSheet(Color.White);\nstyleSheet.AddStyle(\"rain[a-z]*\", Color.MediumSlateBlue, match =\u003e match.ToUpper());\n\nConsole.WriteLineStyled(storyAboutRain, styleSheet);\n```\n![Style Specific Regions of Text, Performing a Simple Transformation](https://github.com/tomakita/Colorful.Console/blob/master/static/styler_x2.png)\n\n\n# Style Specific Regions of Text, Performing a Transformation Based on Surrounding Text\n```c#\nStyleSheet styleSheet = new StyleSheet(Color.White);\nstyleSheet.AddStyle(\"rain[a-z]*\", Color.MediumSlateBlue,\n    (unstyledInput, matchLocation, match) =\u003e\n    {\n        if (unstyledInput[matchLocation.End] == '.')\n        {\n            return \"marshmallows\";\n        }\n        else\n        {\n            return \"s'mores\";\n        }\n    });\n\nConsole.WriteLineStyled(storyAboutRain, styleSheet);\n```\n![Style Specific Regions of Text, Performing a Simple Transformation](https://github.com/tomakita/Colorful.Console/blob/master/static/styler_x3.png)\n\n\n# Convert Text to ASCII Art Using a Default Font\n```c#\nint DA = 244;\nint V = 212;\nint ID = 255;\nfor (int i = 0; i \u003c 3; i++)\n{\n    Console.WriteAscii(\"HASSELHOFF\", Color.FromArgb(DA, V, ID));\n\n    DA -= 18;\n    V -= 36;\n}\n```\n![Convert Text to ASCII Art Using a Default Font](https://github.com/tomakita/Colorful.Console/blob/master/static/ascii_x1.png)\n\n\n# Convert Text to ASCII Art Using [FIGlet](http://www.figlet.org/) Fonts\n```c#\nFigletFont font = FigletFont.Load(\"chunky.flf\");\nFiglet figlet = new Figlet(font);\n\nConsole.WriteLine(figlet.ToAscii(\"Belvedere\"), ColorTranslator.FromHtml(\"#8AFFEF\"));\nConsole.WriteLine(figlet.ToAscii(\"ice\"), ColorTranslator.FromHtml(\"#FAD6FF\"));\nConsole.WriteLine(figlet.ToAscii(\"cream.\"), ColorTranslator.FromHtml(\"#B8DBFF\"));\n```\n![Convert Text to ASCII Art Using a Default Font](https://github.com/tomakita/Colorful.Console/blob/master/static/ascii_x2.png)\n\n\n# Style Collections With a Gradient\n```c#\nList\u003cchar\u003e chars = new List\u003cchar\u003e()\n{\n\t'r', 'e', 'x', 's', 'z', 'q', 'j', 'w', 't', 'a', 'b', 'c', 'l', 'm',\n\t'r', 'e', 'x', 's', 'z', 'q', 'j', 'w', 't', 'a', 'b', 'c', 'l', 'm',\n\t'r', 'e', 'x', 's', 'z', 'q', 'j', 'w', 't', 'a', 'b', 'c', 'l', 'm',\n\t'r', 'e', 'x', 's', 'z', 'q', 'j', 'w', 't', 'a', 'b', 'c', 'l', 'm'\n};\nConsole.WriteWithGradient(chars, Color.Yellow, Color.Fuchsia, 14);\n```\n![Style Collections With a Gradient](https://github.com/tomakita/Colorful.Console/blob/master/static/gradw_x.png)\n\n\n# Usage Notes\n\nConsole colors can be set back to their defaults using the `Colorful.Console.ReplaceAllColorsWithDefaults` function.\n\nIndividual colors in the console's color palette can be replaced using the `Colorful.Console.ReplaceColor` function. \n\n**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](https://msdn.microsoft.com/en-us/library/windows/desktop/ms682091(v=vs.85).aspx)), and it's one that we weren't able to work our way around.  If you know of a workaround, let us know!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftomakita%2FColorful.Console","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftomakita%2FColorful.Console","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftomakita%2FColorful.Console/lists"}