{"id":29708906,"url":"https://github.com/sapteamdev/commontk.console","last_synced_at":"2025-07-23T19:08:04.428Z","repository":{"id":149749000,"uuid":"620650595","full_name":"SAPTeamDEV/CommonTK.Console","owner":"SAPTeamDEV","description":"All in One and Multi Purpose .NET Library for Professional Console actions.","archived":false,"fork":false,"pushed_at":"2024-08-16T08:06:46.000Z","size":148,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-07-22T06:39:46.084Z","etag":null,"topics":["cmd","color","colorize-console","console","console-application","console-form","console-manager","console-tools","console-ui","create-console","desktop-console"],"latest_commit_sha":null,"homepage":"https://www.nuget.org/packages/SAPTeam.CommonTK.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/SAPTeamDEV.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":"2023-03-29T05:23:56.000Z","updated_at":"2024-10-19T12:43:47.000Z","dependencies_parsed_at":"2023-11-16T03:30:21.250Z","dependency_job_id":"7a3c35ae-8bd0-49c1-b787-f73026f1d88c","html_url":"https://github.com/SAPTeamDEV/CommonTK.Console","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/SAPTeamDEV/CommonTK.Console","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SAPTeamDEV%2FCommonTK.Console","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SAPTeamDEV%2FCommonTK.Console/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SAPTeamDEV%2FCommonTK.Console/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SAPTeamDEV%2FCommonTK.Console/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SAPTeamDEV","download_url":"https://codeload.github.com/SAPTeamDEV/CommonTK.Console/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SAPTeamDEV%2FCommonTK.Console/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266737769,"owners_count":23976395,"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","status":"online","status_checked_at":"2025-07-23T02:00:09.312Z","response_time":66,"last_error":null,"robots_txt_status":null,"robots_txt_updated_at":null,"robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["cmd","color","colorize-console","console","console-application","console-form","console-manager","console-tools","console-ui","create-console","desktop-console"],"created_at":"2025-07-23T19:08:03.533Z","updated_at":"2025-07-23T19:08:04.418Z","avatar_url":"https://github.com/SAPTeamDEV.png","language":"C#","readme":"# CommonTK.Console - All in One and Multi Purpose .NET Library for Professional Console actions\n\n[![Gawe CI](https://github.com/SAPTeamDEV/CommonTK.Console/actions/workflows/main.yml/badge.svg?event=push)](https://github.com/SAPTeamDEV/CommonTK.Console/actions/workflows/main.yml)\n[![Nuget](https://img.shields.io/nuget/v/SAPTeam.CommonTK.Console)](https://www.nuget.org/packages/SAPTeam.CommonTK.Console)\n[![Nuget](https://img.shields.io/nuget/dt/SAPTeam.CommonTK.Console)](https://www.nuget.org/packages/SAPTeam.CommonTK.Console)\n\nThis library has many utilities for doing Advanced action Directly with Console using main Win32 P/Invoke APIs.\nand also has various amazing features for creating beautiful console User Interface.\n\n## Installation\nYou can install this library with Package manager console.\n\nSAPTeam.CommonTK.Console\n```\nPM\u003e Install-Package SAPTeam.CommonTK.Console\n```\nCommonTK is dependency of Console library, so it will be installed automatically.\n\n## Features\n\n### Console Form\nConsole form is the biggest feature in this library. With `ConsoleForm` you can create an amazing and different UI inside the Console window!\n\nUsers can control and select items with keyboard keys. You can Notify users with a `ScreenMessage` toast notification! Console Forms also support Multi paging without issues. It can manage and handle many pages using a platform named `Interface`.\n\nYou can install the [Console Form Template](https://www.nuget.org/packages/SAPTeam.CommonTK.Console.FormTemplates) package with the following command to get access to the latest api templates:\n```\ndotnet new install SAPTeam.CommonTK.Console.FormTemplates\n```\n\n#### Create a new `Form`\nIn the beginning you must create a `Form` for defining form Title, Options and Behaviors.\nHere is a Example of simple Console Form:\n```\npublic class ExampleForm : ConsoleForm.Form\n{\n    // Creates Form options. called just one time\n    protected override void CreateItems()\n    {\n        // Create new Sections. if you dont need sections, use \"\" in section name.\n        // Items[\"\"] = new();\n\n        // Sections ordered by name.\n        Items[\"Tools\"] = new();\n        Items[\"Actions\"] = new();\n\n        // Adds Options to Specified sections.\n        Items[\"Tools\"].Add(\"Create a new File\");\n        Items[\"Tools\"].Add(\"Open a File\");\n        Items[\"Tools\"].Add(\"Open a Folder\");\n\n        Items[\"Actions\"].Add(\"Close File\");\n        Items[\"Actions\"].Add(\"Delete File\");\n        Items[\"Actions\"].Add(\"Exit\");\n    }\n\n    // Shows Title of Form. Called many times after each Refresh or during Form creation.\n    protected override void OnTitle()\n    {\n        Utils.Echo(\"Example page\");\n        Utils.Echo(\"Press ESC to Close this page\");\n\n        // Because Console window is not notify program about Events, We have disabled the Close Button and users must enter ESC key to exit.\n\n        // Write a Empty line for better look.\n        Utils.Echo();\n    }\n\n    // Called just one time when Form is about to start and before reading user inputs.\n    protected override void OnStart()\n    {\n        \n    }\n\n    // Called once before close and clearing the contents of form.\n    protected override void OnClose()\n    {\n        \n    }\n\n    // This is the main logic Entry point of form. Called every time that a Option is selected by user.\n    protected override void OnEnter(ConsoleOption option)\n    {\n        // This is the names that described in CreateItems().\n        switch (option.Text)\n        {\n            // Handles functionality of option Create a new File.\n            case \"Create a new File\":\n                break;\n            case \"Delete File\":\n                // Creates and Takes Console control to the SubForm.\n                Platform.AddSubForm(new DeleteFile());\n                break;\n            case \"Exit\":\n                // If this form is a sub form, you must call CloseSubForm();\n                Platform.Close();\n                break;\n            default:\n                // notify user with a ScreenMessage.\n                Platform.ScreenMessage(\"There is nothing\");\n                break;\n        }\n    }\n}\n\n// Create a SubForm.\n// Sub Forms creation is same as Form but in initialization and closing is different.\npublic class DeleteFile : ConsoleForm.Form\n{\n    // Prohibit close this page with ESC key.\n    public override bool IsClosable =\u003e false;\n\n    // This Form is Always ceated as sub form.\n    public DeleteFile() : base(false) { }\n\n    // You can use all features described in Form. all this functions replaces Form functions until it closed.\n\n    // Creates SubForm options. called during object ceation one time.\n    protected override void CreateItems()\n    {\n        Items[\"\"] = new() { \"Yes\", \"No\" };\n    }\n\n    protected override void OnTitle()\n    {\n        Utils.Echo(\"Delete this file?\");\n        Utils.Echo();\n    }\n\n    // Called when user select an option.\n    protected override void OnEnter(ConsoleOption option)\n    {\n        // This is the names that described in CreateItems(). Yes or No.\n        switch (option.Text)\n        {\n            case \"Yes\":\n            case \"No\":\n                // Return Control to the Form and Close this sub form.\n                Platform.CloseSubForm();\n                break;\n        }\n    }\n}\n```\n\n#### Start Form\nConsole forms can be runned in any Console applications and even UI Applications using `ConsoleWindow` Context that described later.\nFor Console applications simply Create an Instance of your form and call `Start()`.\n\nFor Desktop applications you need to create a Console windows using `ConsoleWindow` Context:\n```\nusing ConsoleWindow console = new();\nvar form = new ExampleForm();\nform.Start();\n```\n\n### Contexts\nThis library has three Context classes that can be accessed trough `SAPTeam.CommonTK.Contexts`.\n\n#### `ConsoleWindow`\nThis context is a key utility for desktop applications, with this Context you can Allocate a new Console window and simply close it.\n```\nusing (ConsoleWindow console = new())\n{\n    // Write your code.\n    Console.WriteLine(\"Hello\");\n}\n```\n\n#### `DisposableWriter`\nThis context gives you a temporary writing session that you can write your Contents in any color that you want and in end, Simply clear exactly what you wrote.\n\nFor using this Context you must use `Utils.Echo(string)` to correctly write your text and record it's coordinates in context.\n```\nusing (DisposableWriter dw = new(backgroundColor: ConsoleColor.White, foregroundColor: ConsoleColor.Black))\n{\n    // Write your texts.\n    Utils.Echo(\"Temporary text.\");\n}\n```\n\n#### `RedirectConsole`\nMain usage of this Context is in Console Forms for hiding Form creation process.\n```\nusing (RedirectConsole rc = new())\n{\n    // Run codes that have unwanted text writings.\n}\n```\n\n### `Colorize`\nWith this struct you can format a text to have different colors in each parts of that.\n\nPut every parts that you want to change it's color in a `[]` and determine colors in next parameters respectively. \n```\n// Create a Colorized string.\nColorize colorizedString = new(\"Welcome to [Sample App] version [1.2]\", ConsoleColor.Red, ConsoleColor.Green);\n\n// Pass this string to Utils.Echo to process and write it.\nUtils.Echo(colorizedString);\n\n// In output text all words except \"Sample App\" and \"1.2\" Follows global color theme defined in ColorSet.Current.\n// First word wrote with Red color and Second one is green.\n```\n\n### `ColorSet`\nThis is a Data-Type struct for keeping pairs of Foreground and Background colors, for example `ScreenMessage` uses ColorSet for setting it's color.\nIt also used for setting **Global Color Set**. This color is used in every methods that defined in this library.\n```\n// Creates a new Color Set with White background and Black text color.\nColorSet colors = new(ConsoleColor.White, ConsoleColor.Black);\n\n// Changes current default Color Set. This also changes the System.Console color set.\nColorSet.Current = colors;\n\n// Resets Global Color Set to the default Black/Gray Back/Fore.\nColorSet.Current = new();\n```\n\n### Console Manager\nThis is an Advanced utility intended for desktop Applications for get access to Console Windows using Win32 P/Invoke APIs.\nA simple usage of methods that provided by `ConsoleManager` is available with `ConsoleWindow` Context. but this class give you more options for creating and releasing a Console.\n\nThere is Different ways to creating Console window:\n- Allocation (Default): In this way, Library calls AllocConsole() Win32 API to Allocate a new Console window to this application.\n- AttachToParent (Unreliable): In this way Application attaches to the Console that called this application.\n- AttachProcess: Starts a new cmd.exe process, then kill it and uses Console window provided with that process.\n\nThere is also some Limitations:\n- Applications can't have more than One Console windows.\n- Closing console window also Kills application process Immediately.\n\nFor resolving second issue, we have Disabled the Close button of console window. Applications must implement a way for Calling `ConsoleManager.HideConsole()` after job is finished, otherwise Console is stay unresponsive. When using `ConsoleWindow` Context this method called automatically.\n\n### Utils\n\n#### `Echo`\nThis method is the main handler of all text-related actions in this library. if you're using COntexts of Colorized Strings you must use this method for writing texts.\n\n#### `ClearLine`\nClears Previous or Current line contents.\n\n#### `SetColor`\nTemporarily changes color of System.Console, but don't change The **Global Color Set** and simply can be reverted with `ResetColor()`.\nDon't confused with `System.Console.ResetColor` it's don't take care of Global Color Set.\n\n## Contribution\nFeel free to grab the source, open issues or pull requests.\n\n## Credits\nAlmost all the Classes of this library were extracted from The public API of my private repository `Windows Pro` and published in two libraries, [CommonTK](https://github.com/SAPTeamDEV/CommonTK) and [CommonTK.Console](https://github.com/SAPTeamDEV/CommonTK.Console)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsapteamdev%2Fcommontk.console","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsapteamdev%2Fcommontk.console","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsapteamdev%2Fcommontk.console/lists"}