{"id":17870152,"url":"https://github.com/williamragstad/ansiconsole","last_synced_at":"2025-03-21T13:31:29.410Z","repository":{"id":102086693,"uuid":"400477364","full_name":"WilliamRagstad/ANSIConsole","owner":"WilliamRagstad","description":"A .NET library for creating beautiful console applications.","archived":false,"fork":false,"pushed_at":"2021-08-30T07:18:37.000Z","size":3006,"stargazers_count":33,"open_issues_count":1,"forks_count":4,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-18T01:51:15.943Z","etag":null,"topics":["ansi","colors","console","formatting","terminal"],"latest_commit_sha":null,"homepage":"https://www.nuget.org/packages/ANSI.Console","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/WilliamRagstad.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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":"2021-08-27T10:50:51.000Z","updated_at":"2025-03-16T14:44:58.000Z","dependencies_parsed_at":null,"dependency_job_id":"89a0dfb9-08f6-4bc1-b197-4dfbc925333d","html_url":"https://github.com/WilliamRagstad/ANSIConsole","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WilliamRagstad%2FANSIConsole","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WilliamRagstad%2FANSIConsole/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WilliamRagstad%2FANSIConsole/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WilliamRagstad%2FANSIConsole/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/WilliamRagstad","download_url":"https://codeload.github.com/WilliamRagstad/ANSIConsole/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244806100,"owners_count":20513381,"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":["ansi","colors","console","formatting","terminal"],"created_at":"2024-10-28T10:12:29.045Z","updated_at":"2025-03-21T13:31:29.402Z","avatar_url":"https://github.com/WilliamRagstad.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n    \u003cimg src=\"assets/logo_cropped.png\" alt=\"ANSI Console\" width=\"30%\" /\u003e\n    \u003ch1\u003e\u003ccode\u003eANSI Console\u003c/code\u003e\u003c/h1\u003e\n    \u003cp\u003e\n        Lightweight and flexible text formatter\u003cbr\u003e\n        for creating \u003cem\u003ebeautiful\u003c/em\u003e console applications.\n\t\t\u003cbr\u003e\u003cbr\u003e\n        \u003cimg alt=\"Nuget\" src=\"https://img.shields.io/nuget/v/ANSI.Console\"\u003e\n    \t\u003cimg alt=\"Nuget\" src=\"https://img.shields.io/nuget/dt/ANSI.Console\"\u003e\n        \u003cimg alt=\"GitHub\" src=\"https://img.shields.io/github/license/WilliamRagstad/ANSIConsole\"\u003e\n        \u003cimg alt=\"GitHub code size in bytes\" src=\"https://img.shields.io/github/languages/code-size/WilliamRagstad/ANSIConsole\"\u003e\n    \u003c/p\u003e\n    \u003cbr\u003e\u003cbr\u003e\n\u003c/div\u003e\n\n## About\n\nANSI Console aims to be as **developer friendly and easy to use** as possible. The reason this library was created is because many of the already existing libraries doesn't provide a good user interface. The main purpose of this library is to fix this, console formatting should be **accessible and fun**!\n\n\n\n## Install\n\n```\n\u003e dotnet add package ANSI.Console\n```\n\nOr download `ANSI.Console` directly from [NuGet](https://www.nuget.org/packages/ANSI.Console).\n\n\n\n## Features\n* Color formatting using: `System.ConsoleColor`, `System.Drawing.Color`, **RGB**, **HEX**, **Named/known colors** ([list](https://docs.microsoft.com/en-us/dotnet/api/system.windows.media.brushes?view=net-5.0)) and **True color** (24-bit format with over 16.7 million colors, [Wikipedia](https://en.wikipedia.org/wiki/Color_depth#True_color_(24-bit)))\n* Styles: Bold, Italic, Underlined, Overlined, Strike-through, Inverted, Faint, Opacity, Blink, Uppercase and Lowercase.\n* Hyperlinks\n* Custom inline formatting method `FormatANSI`.\n* Chainable formatting methods.\n* ANSI initialization for the system console (If not enabled already).\n* Builds on-top of the default `Console` using `string` extension methods.\n* Mapping methods using generators\n* Gradients with unlimited colors\n\nLearn more about ANSI escape sequences [here](https://stackoverflow.com/a/33206814/5698805).\n\n### Initialization\n\nOne should always initialize the ANSI console mode before writing anything to the console. The line below will try to initialize returning true if successful. If initialization failed, disable all ANSI codes from being printed without needing to change any of your formatting logic. Colors and formatting is automatically disabled for systems with the `NO_COLOR` environment variable enabled, read more [here](#NO_COLOR).\n\n```c#\nif (!ANSIInitializer.Init(false)) ANSIInitializer.Enabled = false;\n```\n\n### Colors and styles\n\n#### Colors\n\n* Use regular `ConsoleColor`.\n\n```c#\n\"My text\".Color(ConsoleColor.Red)\n```\n\n* Or even better, any `Color`.\n\n```c#\n\"My text\".Color(Color.IndianRed)\n```\n\n* Too long still? Use just the color name.\n\n```c#\n\"My text\".Color(\"IndianRed\")\n```\n\n* Want more control? Use hexadecimal color values.\n\n```c#\n\"My text\".Color(\"#775500\")\n```\n\n* Or even RGB color values.\n\n```c#\n\"My text\".Color(256, 127, 0)\n```\n\n#### Styles\n\nYou can chain all formatting styles in any order.\n\n```c#\n\"My text\".Bold().Italic().Color(\"IndianRed\").Underlined().StrikeThrough().Blink();\n```\n\n#### Opacity\n\nAdd opacity easily using `.Opacity(percent)`. `percent` must be between 0 and 100. The code below could be rewritten and improved using the map method below.\n\n```c#\nConsole.WriteLine($\"{\"O\".Opacity(10)}{\"p\".Opacity(20)}{\"a\".Opacity(30)}{\"c\".Opacity(50)}{\"i\".Opacity(60)}{\"t\".Opacity(80)}{\"y\".Opacity(90)}\");\n```\n\n\n\n![](assets/opacity.png)\n\n#### Links\n\nUse `.Link()` if the text is also a valid URL. This only works on strings, and not if you have used any other formatting method before it.\n\n```c#\n\"https://www.nuget.org/packages/ANSI.Console\".Link().Bold();\n```\n\nIf you fancy using a custom title, use `.Link(url)`. This can be used in any order in the chained formatting list.\n\n```c#\n\"ANSI.Console\".Bold().Link(\"https://www.nuget.org/packages/ANSI.Console\");\n```\n\n#### Map\n\nUse the `MapANSI` method to generate custom patterns, highlighting or anything else you can think of.\n\n```c#\nConsole.WriteLine(\"Every second letter is yellow\".MapANSI((c, i) =\u003e i % 2 == 0 ? c.Color(ConsoleColor.Yellow) : c.ToANSI()));\n```\n\n\n\n![](assets/map.png)\n\n#### Gradients\n\nAdd text gradients interpolating between any amount of colors. The first argument is the background color.\n\n```c#\nConsole.WriteLine(\"This is a gradient\".Gradient(ANSIString.FromConsoleColor(Console.BackgroundColor), Color.Yellow, Color.Red, Color.Blue, Color.Cyan));\n```\n\n\n\n![](assets/gradient.png)\n\nOr background gradients. The first argument is the foreground color. (Sadly the two cannot be combined yet. But maybe in a future release if there is interest)\n\n```c#\nConsole.WriteLine(\"This is a gradient\".GradientBackground(Color.Black, Color.Yellow, Color.Red, Color.Blue, Color.Cyan));\n```\n\n\n\n![](assets/gradient_background.png)\n\n### Inline formatting using `FormatANSI`\n\nFormat text directly in line, applying the corresponding ANSI format in the formatting array to the matching **\\`(color|(background|))text´** in the text.\nUse **\\`color|text´** to add foreground color, and **\\`|background|text´** to only add background color.\n\n#### Example: Only color\n\n```c#\nConsole.WriteLine($\"This `Green|text´ has `Black|Gray|inline {\"formatted\".Italic().NoClear()}´ `Yellow|c´`Orange|o´`Red|l´`Purple|o´`Blue|r´`Aqua|s´\".FormatANSI());\n```\n![](assets/formatting_colors.png)\n\n#### Example: Multi formatted\n\n```c#\nConsole.WriteLine(\"`Red|This´ is `|Green|a´ `Blue|formatted´ `string´\".FormatANSI(ANSIFormatting.Bold | ANSIFormatting.Overlined, ANSIFormatting.None, ANSIFormatting.Blink, ANSIFormatting.Inverted));\n```\n![formatted result](assets/formatting.gif)\n\n### Inline colors using `FormatColor`\n\nUnless you don't want any other formatting that colors, use this method instead. You don't need to specify the color in the text itself, but as arguments to the `FormatColor` method.\n\nThis is perfect if you want to quickly spice-up your console applications usage/about/help message or manual page.\n\n```c#\nConsole.WriteLine($\"This `text´ has `inline {\"formatted\".Italic().NoClear()}´ `c´`o´`l´`o´`r´`s´\".FormatColor(ConsoleColor.Green, ConsoleColor.Magenta, ConsoleColor.Yellow, ConsoleColor.DarkYellow, ConsoleColor.Red, ConsoleColor.DarkMagenta, ConsoleColor.Blue, ConsoleColor.Cyan));\n```\n\n![](assets/format_colors.png)\n\n\n\n## NO_COLOR\n\nNo formatting will be applied for systems where console color output has explicitly been requested to be turned off using the environment variable `NO_COLOR`. See more information about this initiative at [https://no-color.org](https://no-color.org/).\n\nThis can be overwritten by setting the `ANSIInitializer.Enabled = true`.\n\n## Resources\n\n* [ANSI escape code](https://en.wikipedia.org/wiki/ANSI_escape_code)\n* [List of ANSI color escape sequences](https://stackoverflow.com/a/33206814/5698805)\n* [Hyperlinks (a.k.a. HTML-like anchors) in terminal emulators](https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda#the-escape-sequence), [Support hyperlink ansi escapes in the integrated terminal](https://github.com/microsoft/vscode/issues/39278)\n* [Operating System Command (OSC)](https://chromium.googlesource.com/apps/libapps/+/a5fb83c190aa9d74f4a9bca233dac6be2664e9e9/hterm/doc/ControlSequences.md#OSC)\n\n## Blogs\n\n* [Build your own Command Line with ANSI escape codes](https://www.lihaoyi.com/post/BuildyourownCommandLinewithANSIescapecodes.html)\n* [Using ANSI color codes in .NET Core Console applications](https://www.jerriepelser.com/blog/using-ansi-color-codes-in-net-console-apps/)\n* [Spectre.Console lets you make beautiful console apps with .NET Core](https://www.hanselman.com/blog/spectreconsole-lets-you-make-beautiful-console-apps-with-net-core)\n\n## Related projects\n\n* [Spectre.Console](https://github.com/spectreconsole/spectre.console)\n* [Colorful.Console](https://github.com/tomakita/Colorful.Console)\n* [Pastel](https://github.com/silkfire/Pastel)\n* [rich](https://github.com/willmcgugan/rich)\n* [Spectre.Terminals](https://github.com/spectreconsole/terminal)\n* [System.Terminal](https://github.com/alexrp/system-terminal)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwilliamragstad%2Fansiconsole","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwilliamragstad%2Fansiconsole","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwilliamragstad%2Fansiconsole/lists"}