{"id":20245775,"url":"https://github.com/immense/console-helpers","last_synced_at":"2026-05-11T17:38:22.640Z","repository":{"id":75108382,"uuid":"64239973","full_name":"immense/console-helpers","owner":"immense","description":"Collection of utilities for writing console-based applications in .NET","archived":false,"fork":false,"pushed_at":"2016-07-26T20:48:17.000Z","size":10,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2026-05-01T11:42:42.578Z","etag":null,"topics":["csharp","dotnet"],"latest_commit_sha":null,"homepage":null,"language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/immense.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2016-07-26T17:13:15.000Z","updated_at":"2023-05-18T04:51:29.000Z","dependencies_parsed_at":"2023-06-05T08:45:25.118Z","dependency_job_id":null,"html_url":"https://github.com/immense/console-helpers","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/immense/console-helpers","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/immense%2Fconsole-helpers","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/immense%2Fconsole-helpers/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/immense%2Fconsole-helpers/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/immense%2Fconsole-helpers/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/immense","download_url":"https://codeload.github.com/immense/console-helpers/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/immense%2Fconsole-helpers/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32906506,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-11T17:09:15.040Z","status":"ssl_error","status_checked_at":"2026-05-11T17:08:45.420Z","response_time":120,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["csharp","dotnet"],"created_at":"2024-11-14T09:23:56.395Z","updated_at":"2026-05-11T17:38:22.624Z","avatar_url":"https://github.com/immense.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Console Helpers\n\nCollection of utilities for writing console-based applications in .NET\n\n## Quick start ##\n\n```c#\nusing static ConsoleHelpers.Helpers;\n\nclass FooBar\n{\n  public string foo { get; set; }\n  public string bar { get; set; }\n}\n\nclass Program\n{\n  static void Main(string[] args)\n  {\n    Header(\"This is a header\");\n    string input = PromptRead(\"This is a prompt\");\n    string input2 = PromptRead(\"You can also specify default values\", \"foobar\");\n    \n    IList\u003cstring\u003e choices = new List\u003cstring\u003e\n    {\n      \"foo\",\n      \"bar\",\n      \"baz\"\n    };\n    \n    string selected = PromptSelect(\"IEnumerables of strings are selectable by their index\", choices);\n    \n    IList\u003cFooBar\u003e fooBarChoices = new List\u003cFooBar\u003e\n    {\n      new FooBar { foo = \"foo\"; bar = \"bar\" },\n      new FooBar { foo = \"bar\"; bar = \"foo\" }\n    };\n    \n    FooBar selectedFooBar = PromptSelect\u003cFooBar\u003e(\n      \"IEnumerables of objects are selectable too!\",\n      fooBarChoices,\n      fooBar =\u003e $\"foo = {foo}, bar = {bar}\"\n    );\n  }\n}\n```\n\n## API ##\n\n**Classes**\n\n* SelectedIndex - represents either:\n  * the index of a selected item within a list or\n  * a cancelled selection\n\n```c#\npublic class SelectedIndex\n{\n  public int Value { get; }\n  public bool Cancelled { get; } = false;\n}\n```\n\n* SelectedValue\u0026lt;T\u0026gt; - represents either:\n  * the value of a selected item (T) within a list (IEnumberable\u0026lt;T\u0026gt;) or\n  * a cancelled selection\n\n```c#\npublic class SelectedValue\u003cT\u003e where T : class\n{\n  public T Value { get; } = default(T);\n  public bool Cancelled { get; } = false;\n}\n```\n\n**Constants**\n\n* string EOL\n  * Equivelent to `Environment.NewLine` (just simpler to type!)\n\n**Variables**\n\n* ConsoleColor HEADER_COLOR\n  * The color of text written by the `Header` method\n  * Default: ConsoleColor.White\n* ConsoleColor HEADER_BG\n  * The color of the background of text written by the `Header` method\n  * Default: ConsoleColor.DarkBlue\n* ConsoleColor PROMPT_COLOR\n  * Defualt: ConsoleColor.Gray\n* ConsoleColor PROMPT_BG\n  * Default: ConsoleColor.Black\n\n**Methods**\n\n* `void WriteWithColor(ConsoleColor textColor, ConsoleColor bgColor, string message, bool newLine)`\n  * Prints the provided `message` to the console using the provided colors\n  * textColor - the color of the text to print\n  * bgColor - the color of the background to print\n  * message - the message to print\n  * newLine - whether or not to print a newline after the message\n* `void Blue(string message [, bool newLine = true ])`\n  * Prints message with text color of blue\n  * By default, prints a newline character after the message unless `false` is provided for the `newLine` argument\n* `void Red(string message [, bool newLine = true ])`\n  * Prints message in red\n  * By default, prints a newline character after the message unless `false` is provided for the `newLine` argument\n* `void Yellow(string message [, bool newLine = true ])`\n  * Prints message in yellow\n  * By default, prints a newline character after the message unless `false` is provided for the `newLine` argument\n* `void White(string message [, bool newLine = true ])`\n  * Prints message in white\n  * By default, prints a newline character after the message unless `false` is provided for the `newLine` argument\n* `void Gray(string message [, bool newLine = true ])`\n  * Prints message in gray\n  * By default, prints a newline character after the message unless `false` is provided for the `newLine` argument\n* `void Header(string message)`\n  * Prints a new line followed by `\"## {message} ##\"`\n  * Text color / background color can be changed by setting `HEADER_COLOR` and `HEADER_BG` respectively\n* `void Prompt(string message)`\n  * Prints a tab followed by `\"{message}: \"`\n  * Text color / background color can be changed by setting `PROMPT_COLOR` and `PROMPT_BG` respectively\n\n* `string PromptRead(string prompt)`\n  * Prompts the user to enter a value\n  * Returns `null` if the user presses enter without typing anything\n  * Returns the entered string if the user types something and presses enter\n\n* `string PromptRead(string prompt, object defaultValue)`\n  * Prompts the user to enter a value\n  * Returns `defaultValue` if the user presses enter without typing anything\n    * If defaultValue is `null`, this method will return `null` when nothing is entered.\n    * For any non-`null` value of `defaultValue`, this method will return `defaultValue.ToString()` when nothing is entered\n  * Returns the entered string if the user types something and presses enter\n\n* `SelectedIndex PromptSelect(string prompt, IEnumberable\u003cstring\u003e choices [, bool allowCancel = true, bool allowNull = false])`\n  * Prompts the user to choose one of the provided `choice`s\n  * Each element of `choices` will be listed alongside its index within `choices`, and the user can enter the number corresponding to their choice\n  * The return value `SelectedIndex` contains the users's selection\n  * allowCancel - whether or not the user will be allowed to enter `-1` to cancel this selection\n    * if user enters `-1`, the `SelectedIndex` that is returned will have `Cancelled = true`\n  * allowNull - whether or not to allow the user to simply press enter, choosing nothing\n    * if user chooses nothing, `null` will be returned\n\n* `SelectedIndex PromptSelect(string prompt, IEnumberable\u003cstring\u003e choices, object defaultValue [, bool allowCancel = true, bool allowNull = false])`\n  * Prompts the user to choose one of the provided `choice`s\n  * Each element of `choices` will be listed alongside its index within `choices`, and the user can enter the number corresponding to their choice\n  * Returns the index of `defaultValue` within `choices` wrapped in a `SelectedIndex` if the user presses enter without typing anything\n    * If defaultValue is `null`, this method will return `null` when nothing is entered.\n    * For any non-`null` value of `defaultValue`, this method will return the index of `defaultValue.ToString()` wrapped in a `SelectedIndex` when nothing is entered\n  * The return value `SelectedIndex` contains the users's selection\n  * allowCancel - whether or not the user will be allowed to enter `-1` to cancel this selection\n    * if user enters `-1`, the `SelectedIndex` that is returned will have `Cancelled = true`\n  * allowNull - whether or not to allow the user to simply press enter, choosing nothing\n    * if user chooses nothing, `null` will be returned\n\n* `SelectedValue\u003cT\u003e PromptSelect\u003cT\u003e(string prompt, IEnumberable\u003cT\u003e choices, Func\u003cT, string\u003e mapping [, bool allowCancel = true, bool allowNull = false])`\n  * Prompts the user to choose one of the provided `choice`s\n  * Each element of `choices` will be mapped to a string using `mapping` and listed alongside its index within `choices`, and the user can enter the number corresponding to their choice\n  * The return value `SelectedValue\u003cT\u003e` contains the users's selection\n  * allowCancel - whether or not the user will be allowed to enter `-1` to cancel this selection\n    * if user enters `-1`, the `SelectedValue\u003cT\u003e` that is returned will have `Cancelled = true`\n  * allowNull - whether or not to allow the user to simply press enter, choosing nothing\n    * if user chooses nothing, `null` will be returned\n\n* `SelectedValue\u003cT\u003e PromptSelect\u003cT\u003e(string prompt, IEnumberable\u003cT\u003e choices, Func\u003cT, string\u003e mapping, T defaultValue [, bool allowCancel = true, bool allowNull = false])`\n  * Prompts the user to choose one of the provided `choice`s\n  * Each element of `choices` will be mapped to a string using `mapping` and listed alongside its index within `choices`, and the user can enter the number corresponding to their choice\n  * Returns `defaultValue` wrapped in a `SelectedValue\u003cT\u003e` if the user presses enter without typing anything\n    * If defaultValue is `null`, this method will return `null` when nothing is entered.\n  * The return value `SelectedValue\u003cT\u003e` contains the users's selection\n  * allowCancel - whether or not the user will be allowed to enter `-1` to cancel this selection\n    * if user enters `-1`, the `SelectedValue\u003cT\u003e` that is returned will have `Cancelled = true`\n  * allowNull - whether or not to allow the user to simply press enter, choosing nothing\n    * if user chooses nothing, `null` will be returned\n\n* `SelectedValue\u003cT\u003e PromptSelect\u003cT\u003e(string prompt, IEnumberable\u003cT\u003e choices, Func\u003cT, string\u003e mapping, int defaultIndex [, bool allowCancel = true, bool allowNull = false])`\n  * Prompts the user to choose one of the provided `choice`s\n  * Each element of `choices` will be mapped to a string using `mapping` and listed alongside its index within `choices`, and the user can enter the number corresponding to their choice\n  * Returns `choices[defaultIndex]` wrapped in a `SelectedValue\u003cT\u003e` if the user presses enter without typing anything\n    * If `choices[defaultIndex]` is `null`, this method will return `null` when nothing is entered.\n  * The return value `SelectedValue\u003cT\u003e` contains the users's selection\n  * allowCancel - whether or not the user will be allowed to enter `-1` to cancel this selection\n    * if user enters `-1`, the `SelectedValue\u003cT\u003e` that is returned will have `Cancelled = true`\n  * allowNull - whether or not to allow the user to simply press enter, choosing nothing\n    * if user chooses nothing, `null` will be returned\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fimmense%2Fconsole-helpers","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fimmense%2Fconsole-helpers","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fimmense%2Fconsole-helpers/lists"}