{"id":16513941,"url":"https://github.com/twin/go-color","last_synced_at":"2025-04-08T11:14:51.572Z","repository":{"id":40001214,"uuid":"165744375","full_name":"TwiN/go-color","owner":"TwiN","description":"A lightweight, simple and cross-platform package to colorize text in terminals","archived":false,"fork":false,"pushed_at":"2025-01-14T04:07:35.000Z","size":54,"stargazers_count":105,"open_issues_count":3,"forks_count":13,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-04-01T10:09:44.356Z","etag":null,"topics":["ansi","color","console","go","golang","shell","terminal"],"latest_commit_sha":null,"homepage":"","language":"Go","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/TwiN.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},"funding":{"github":["TwiN"]}},"created_at":"2019-01-14T22:19:07.000Z","updated_at":"2025-02-06T14:33:49.000Z","dependencies_parsed_at":"2025-01-12T04:31:43.923Z","dependency_job_id":"db6d3e89-6ede-4568-abaa-f3299654d37d","html_url":"https://github.com/TwiN/go-color","commit_stats":{"total_commits":52,"total_committers":4,"mean_commits":13.0,"dds":0.5,"last_synced_commit":"97211549ab49cffc23e0436e6011a3ecca010a46"},"previous_names":["twinproduction/go-color"],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TwiN%2Fgo-color","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TwiN%2Fgo-color/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TwiN%2Fgo-color/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TwiN%2Fgo-color/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/TwiN","download_url":"https://codeload.github.com/TwiN/go-color/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247829512,"owners_count":21002997,"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","color","console","go","golang","shell","terminal"],"created_at":"2024-10-11T16:10:55.512Z","updated_at":"2025-04-08T11:14:51.549Z","avatar_url":"https://github.com/TwiN.png","language":"Go","funding_links":["https://github.com/sponsors/TwiN"],"categories":[],"sub_categories":[],"readme":"# go-color\n![test](https://github.com/TwiN/go-color/actions/workflows/test.yml/badge.svg)\n[![Go Report Card](https://goreportcard.com/badge/github.com/TwiN/go-color)](https://goreportcard.com/report/github.com/TwiN/go-color)\n[![Go version](https://img.shields.io/github/go-mod/go-version/TwiN/go-color.svg)](https://github.com/TwiN/go-color)\n[![Go Reference](https://pkg.go.dev/badge/github.com/TwiN/go-color.svg)](https://pkg.go.dev/github.com/TwiN/go-color)\n[![Follow TwiN](https://img.shields.io/github/followers/TwiN?label=Follow\u0026style=social)](https://github.com/TwiN)\n\nAn extremely lightweight cross-platform package to colorize text in terminals.\n\nThis is not meant for maximal compatibility, nor is it meant to handle a plethora of scenarios.\nIt will simply wrap a message with the necessary characters, if the OS handles it.\n\n\n## Usage\n```console\ngo get github.com/TwiN/go-color\n```\n\n\n### Using Functions\nYou can use the `color.Colorize(color, str)`, the `color.Ize(color, str)`, or the `color.With(color, str)` function\nin conjunction with a variable like so:\n```go\npackage main\n\nimport \"github.com/TwiN/go-color\"\n\nfunc main() {\n    // These all have the same effect:\n    println(color.With(color.Red, \"This is red\"))\n    println(color.Ize(color.Red, \"This is red\"))\n    println(color.Colorize(color.Red, \"This is red\"))\n    println(color.InRed(\"This is red\"))\n}\n```\n\nBecause I felt reading `color.With()`/`color.Ize()` to be more visually pleasant than `color.Colorize()`, \nI included `Ize()` and `With()` as aliases for `Colorize()`.\n\nI'm not usually a big fan of having two methods doing the same thing, but since\nthis package doesn't have much room for growth (its only purpose is to colorize\nterminal outputs, after all, and there aren't hundreds of ways to go about it),\nI believe it's acceptable to have both.\n\nAlternatively, you can use color-specific functions:\n```go\npackage main\n\nimport \"github.com/TwiN/go-color\"\n\nfunc main() {\n    // Special\n    println(color.InBold(\"This is bold\"))\n    println(color.InUnderline(\"This is underlined\"))\n    // Text colors\n    println(color.InBlack(\"This is in black\"))\n    println(color.InRed(\"This is in red\"))\n    println(color.InGreen(\"This is in green\"))\n    println(color.InYellow(\"This is in yellow\"))\n    println(color.InBlue(\"This is in blue\"))\n    println(color.InPurple(\"This is in purple\"))\n    println(color.InCyan(\"This is in cyan\"))\n    println(color.InGray(\"This is in gray\"))\n    println(color.InWhite(\"This is in white\"))\n    // Background colors\n    println(color.OverBlack(\"This is over a black background\"))\n    println(color.OverRed(\"This is over a red background\"))\n    println(color.OverGreen(\"This is over a green background\"))\n    println(color.OverYellow(\"This is over a yellow background\"))\n    println(color.OverBlue(\"This is over a blue background\"))\n    println(color.OverPurple(\"This is over a purple background\"))\n    println(color.OverCyan(\"This is over a cyan background\"))\n    println(color.OverGray(\"This is over a gray background\"))\n    println(color.OverWhite(\"This is over a white background\"))\n}\n```\n\nIf you wish, you can also combine text and background colors by using the `In\u003ccolor\u003eOver\u003ccolor\u003e` functions, e.g.:\n```go\ncolor.InWhiteOverBlack(\"This is white text on a black background\")\ncolor.InRedOverYellow(\"This is red text on a yellow background\")\ncolor.InGreenOverBlue(\"This is green text on a blue background\")\n```\nNote that the example above is not exhaustive.\n\n#### Automatic coloring\n\u003e ⚠ **WARNING**: This is an experimental feature and may be removed depending on user feedback.\n\u003e If you have any feedback, please comment on [poll: Keep or Remove color.Autof?](https://github.com/TwiN/go-color/discussions/13).\n\nYou may use `color.Autof(string, args...)` as a replacement to `fmt.Sprintf(string, args...)` but with colors for\neach argument:\n```go\n// 20 will be in red while \"cookie jar\" will be in green.\nprintln(color.Autof(\"I have $%.02f in my %s\", 20, \"cookie jar\"))\n```\n\n\n### Using Variables\n\u003e ⚠ **WARNING**: By using this approach, you will not be able to disable colors with `color.Toggle(false)`. \n\u003e Consider using the function approach instead for maximal cross-library compatibility.\n\nUnlike using the aforementioned approach, directly using the color variables will require you to manually\nprepend `color.Reset` at the end of your string.\n\nYou can directly use the variables like so:\n```go\npackage main\n\nimport \"github.com/TwiN/go-color\"\n\nfunc main() {\n    println(color.Bold + \"This is bold\" + color.Reset)\n    println(color.Underline + \"This is underlined\" + color.Reset)\n    println(color.Black + \"This is black\" + color.Reset)\n    println(color.Red + \"This is red\" + color.Reset)\n    println(color.Green + \"This is green\" + color.Reset)\n    println(color.Yellow + \"This is yellow\" + color.Reset)\n    println(color.Blue + \"This is blue\" + color.Reset)\n    println(color.Purple + \"This is purple\" + color.Reset)\n    println(color.Cyan + \"This is cyan\" + color.Reset)\n    println(color.Gray + \"This is gray\" + color.Reset)\n    println(color.White + \"This is white\" + color.Reset)\n}\n```\n\n**NOTE**: If you're going to use this approach, don't forget to prepend your string with `color.Reset`, \notherwise everything else in your terminal will be that color until the color is reset or overridden.\n\n\n### Disabling Colors\nYou can disable colors by using `color.Toggle(false)`, which will cause all functions to not colorize the text.\n\nAs mentioned in [Using Variables](#using-variables), disabling colors will have no effect on the variables, so \nmake sure you are using functions if you have a need to toggle colors.\n\n\n### Examples\n```go\nprintln(\"My name is \" + color.InGreen(\"John Doe\") + \" and I have \" + color.InRed(32) + \" apples.\")\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftwin%2Fgo-color","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftwin%2Fgo-color","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftwin%2Fgo-color/lists"}