{"id":27633708,"url":"https://github.com/djaus2/consoletextformat","last_synced_at":"2025-04-23T18:19:13.017Z","repository":{"id":261353397,"uuid":"869959933","full_name":"djaus2/ConsoleTextFormat","owner":"djaus2","description":"Simple c# Lib for formatting text in Console apps","archived":false,"fork":false,"pushed_at":"2025-02-23T04:30:05.000Z","size":134,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-23T18:19:09.057Z","etag":null,"topics":["console-application","csharp","dnet","formatting","interpolated-strings","string"],"latest_commit_sha":null,"homepage":"https://davidjones.sportronics.com.au/tags/console/","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"cc0-1.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/djaus2.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","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":"2024-10-09T07:46:36.000Z","updated_at":"2025-04-17T07:13:01.000Z","dependencies_parsed_at":"2024-11-06T05:04:50.656Z","dependency_job_id":"8292204d-a614-4ec8-a072-afb6d883baa6","html_url":"https://github.com/djaus2/ConsoleTextFormat","commit_stats":null,"previous_names":["djaus2/consoletextformat"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/djaus2%2FConsoleTextFormat","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/djaus2%2FConsoleTextFormat/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/djaus2%2FConsoleTextFormat/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/djaus2%2FConsoleTextFormat/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/djaus2","download_url":"https://codeload.github.com/djaus2/ConsoleTextFormat/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250487534,"owners_count":21438612,"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":["console-application","csharp","dnet","formatting","interpolated-strings","string"],"created_at":"2025-04-23T18:19:12.313Z","updated_at":"2025-04-23T18:19:13.009Z","avatar_url":"https://github.com/djaus2.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ConsoleTextFormat\n\n## Summary\n\nA simple static class library facilitating \n.NET Console app text formatting in ```Console.Write()``` \nand ```Console.WriteLine()``` statements without explicitly using escape codes.\n\n## Links\n\n- Nuget Package: [ConsoleTextFormat](https://www.nuget.org/packages/ConsoleTextFormat)\n- [Detailed blog post](https://davidjones.sportronics.com.au/coding/ConsoleTextFormat-Formatting_Console_App_Text-coding.html)\n- [Console Virtual Terminal Sequences: MS Learn Ref](https://learn.microsoft.com/en-us/windows/console/console-virtual-terminal-sequences?wt.mc_id=WDIT-MVP-5000301)\n\n## About\nWhilst there are same Console class methods for setting text and background colors, there are no methods for setting text attributes such as bold, underline, etc. This library provides a simple way to do this.\nThis library enables inline code _(that is, with in a string)_ to change  text format when\nwriting to the console using ```Console.Write() and Console.WriteLine()``` methods. \n\nThe class entities have been made a cryptic as possible whilst maintaining interpretation upon inspection.\nThe strings so used are not escaped, but are interpreted by the library. \n\n**String Interpolation** is used to embed the format strings in the text to be written to the console.\n\nThe format strings are at 2 levels.\n  - Quite explicit e.g. ```{Fmt.fg(Fmt.Col.yellow)}```\n  - Cryptic e.g. ```{F.fgYel}```\n\nBoth of the code segments above will produce the same result. \nThe cryptic version requires the using statements as in the following code to alias the class names.\n\n## Example Console Code\n\n```cs\nusing B = ConsoleTextFormat.Fmt.Bold;\nusing F = ConsoleTextFormat.Fmt;\nnamespace ConsoleApp9\n{\n    using System;\n    using ConsoleTextFormat;\n\n    internal class Program\n    {\n\n        enum Animals { fox,cat,dog,zebra,lion,tiger, rat, bird, butterfly,fish, stingray,snake }\n        static void Main(string[] args)\n        {\n\n\n            Layout.Heading(\"Hello, World!\",Fmt.Col.yellow, Fmt.Col.blue);\n            Layout.RainbowHeading(\"Hello, World!\", Fmt.Col.yellow);\n            Layout.Info(\"This is a topic:\", \"Information\");\n            Console.WriteLine($\"{Fmt.bg(Fmt.Col.white)}Hello, {Fmt.b}World!{Fmt._b}{Fmt.clear}\");\n            Console.WriteLine($\"{Fmt.fg(Fmt.Col.yellow)}Hello, {Fmt.b}World!{Fmt._b}{Fmt.clear}\");\n            Console.WriteLine($\"{Fmt.fg(Fmt.Col.blue)}Hello, {Fmt.clear}World!\");\n            Console.WriteLine($\"{B.fgRed}{B.bgCya}Hello, {Fmt.clear}World!\");\n            Console.WriteLine($\"{F.fgRed}{F.bgCya}Hello, {Fmt.clear}World!\");\n\n            var lst = Layout.GenerateEnumMenuList\u003cAnimals\u003e();\n            foreach (var item in lst)\n            {\n                Console.WriteLine(item);\n            }\n            char ch = Layout.Prompt4Ch(\"Hello Joe\", '2', new List\u003cchar\u003e { '1', '2' });\n            Console.WriteLine($\"{ch} selected\");\n            int menuResp = Layout.Prompt4Num(2, 4, true);\n            if (menuResp \u003c 0)\n                return; //Quit\n            menuResp = Layout.Prompt4Num(2, 12, true);\n            if (menuResp \u003c 0)\n                return; //Quit\n            bool quit = false;\n            //fish is hidden so won't show in next menu.\n            Layout.AddHideMenuItems(\"fish\");\n            Animals vv = Layout.SelectEnum\u003cAnimals\u003e(2, ref quit, true);\n            if (quit)\n                return;\n            Console.WriteLine($\"Selected: {vv}\");\n            Layout.Press2Continue();\n            Layout.Press2Continue(\"Wait for completion\");\n            Layout.Press2Continue(\"\",\"when ready.\");\n            Layout.Press2Continue(\"Wait for completion\", \"when ready.\");\n            var col = ConColors.SelevctaConsoleColor();\n            var rgb = ConColors.GetRGBfromConsoleColor(col);\n            Console.WriteLine($\"{rgb.Item1},{rgb.Item2},{rgb.Item3}\");\n        }\n    }\n}\n\n```\n\n[Image of running app](https://davidjones.sportronics.com.au/media/consoleformat.png)  \n**_Console app output_**\n\n## Updates\n\n- 2024-09-07: Added ```Fmt.Heading()``` and ```Fmt.RainbowHeading()``` methods to format text as headings.\n- 2024-09-07: Added ```Fmt.Info(topic,info)``` method.\n- 2024-09-13: Added ```Press2Con``` \"Press any key to continue\" method. Optional messages to pre and post pend. Also, Info() 2nd parameter IS optional.\n- 2024-09-13: Added ```Prompt()``` added. As per Info() but no newline. Heading clears screen. And '_' in heading to blank.\n- 2024-11-06: Added  HideMenu Items to Layout. So items on end of enum list can not appear in menu.\n```cs\n    Layout.AddHideMenuItems(\"MaxType\");\n    Layout.AddHideMenuItems(\"Undefined\");\n    Testtype = Layout.SelectEnum\u003cConsoleTestType\u003e((int)Testtype + 1, ref quit, true);\n    Layout.ClearHideMenuItems();\n```\n- 2024-11-07: Added ConColors class:\n```cs\n    public static class ConColors\n    {\n        /// Menu to select a ConsoleColor\n        public static ConsoleColor SelevctaConsoleColor()\n\n        /// Menu to select a ConsoleColor and return the RGB values\n        public static Tuple\u003cbyte, byte, byte\u003e SelectRGB()\n\n        /// Get RGB values from a ConsoleColor\n        public static Tuple\u003cbyte, byte, byte\u003e GetRGBfromConsoleColor(ConsoleColor col)\n\n        /// Get a ConsoleColor from RGB values          \n        public static ConsoleColor GetConsoleColorFromRGB(byte r, byte g, byte b)\n\n    }\n```\n- 2024-11-08 Bug Fix: DarkYellow returns (0,0,0) Reason: No DarkYellow in Color wheras is in ConsoleColors. Set to (139,128,0)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdjaus2%2Fconsoletextformat","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdjaus2%2Fconsoletextformat","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdjaus2%2Fconsoletextformat/lists"}