{"id":13416792,"url":"https://github.com/fatih/color","last_synced_at":"2025-09-09T21:15:49.262Z","repository":{"id":14200882,"uuid":"16907502","full_name":"fatih/color","owner":"fatih","description":"Color package for Go (golang)","archived":false,"fork":false,"pushed_at":"2025-04-07T01:03:18.000Z","size":2071,"stargazers_count":7589,"open_issues_count":21,"forks_count":625,"subscribers_count":51,"default_branch":"main","last_synced_at":"2025-05-05T15:53:40.730Z","etag":null,"topics":["ansi","color","coloring","go","golang"],"latest_commit_sha":null,"homepage":"https://pkg.go.dev/github.com/fatih/color","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/fatih.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","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,"zenodo":null}},"created_at":"2014-02-17T09:13:35.000Z","updated_at":"2025-05-05T15:29:11.000Z","dependencies_parsed_at":"2023-02-12T18:00:32.866Z","dependency_job_id":"1689eb43-a1a8-4ef0-98ee-623dda3e7486","html_url":"https://github.com/fatih/color","commit_stats":{"total_commits":148,"total_committers":38,"mean_commits":"3.8947368421052633","dds":0.4797297297297297,"last_synced_commit":"1c8d8706604ee5fb9a464e5097ba113101828a75"},"previous_names":[],"tags_count":23,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fatih%2Fcolor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fatih%2Fcolor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fatih%2Fcolor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fatih%2Fcolor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fatih","download_url":"https://codeload.github.com/fatih/color/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253796771,"owners_count":21965776,"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","coloring","go","golang"],"created_at":"2024-07-30T22:00:22.212Z","updated_at":"2025-05-12T18:25:59.225Z","avatar_url":"https://github.com/fatih.png","language":"Go","readme":"# color [![](https://github.com/fatih/color/workflows/build/badge.svg)](https://github.com/fatih/color/actions) [![PkgGoDev](https://pkg.go.dev/badge/github.com/fatih/color)](https://pkg.go.dev/github.com/fatih/color)\n\nColor lets you use colorized outputs in terms of [ANSI Escape\nCodes](http://en.wikipedia.org/wiki/ANSI_escape_code#Colors) in Go (Golang). It\nhas support for Windows too! The API can be used in several ways, pick one that\nsuits you.\n\n![Color](https://user-images.githubusercontent.com/438920/96832689-03b3e000-13f4-11eb-9803-46f4c4de3406.jpg)\n\n## Install\n\n```\ngo get github.com/fatih/color\n```\n\n## Examples\n\n### Standard colors\n\n```go\n// Print with default helper functions\ncolor.Cyan(\"Prints text in cyan.\")\n\n// A newline will be appended automatically\ncolor.Blue(\"Prints %s in blue.\", \"text\")\n\n// These are using the default foreground colors\ncolor.Red(\"We have red\")\ncolor.Magenta(\"And many others ..\")\n\n```\n\n### RGB colors\n\nIf your terminal supports 24-bit colors, you can use RGB color codes.\n\n```go\ncolor.RGB(255, 128, 0).Println(\"foreground orange\")\ncolor.RGB(230, 42, 42).Println(\"foreground red\")\n\ncolor.BgRGB(255, 128, 0).Println(\"background orange\")\ncolor.BgRGB(230, 42, 42).Println(\"background red\")\n```\n\n### Mix and reuse colors\n\n```go\n// Create a new color object\nc := color.New(color.FgCyan).Add(color.Underline)\nc.Println(\"Prints cyan text with an underline.\")\n\n// Or just add them to New()\nd := color.New(color.FgCyan, color.Bold)\nd.Printf(\"This prints bold cyan %s\\n\", \"too!.\")\n\n// Mix up foreground and background colors, create new mixes!\nred := color.New(color.FgRed)\n\nboldRed := red.Add(color.Bold)\nboldRed.Println(\"This will print text in bold red.\")\n\nwhiteBackground := red.Add(color.BgWhite)\nwhiteBackground.Println(\"Red text with white background.\")\n\n// Mix with RGB color codes\ncolor.RGB(255, 128, 0).AddBgRGB(0, 0, 0).Println(\"orange with black background\")\n\ncolor.BgRGB(255, 128, 0).AddRGB(255, 255, 255).Println(\"orange background with white foreground\")\n```\n\n### Use your own output (io.Writer)\n\n```go\n// Use your own io.Writer output\ncolor.New(color.FgBlue).Fprintln(myWriter, \"blue color!\")\n\nblue := color.New(color.FgBlue)\nblue.Fprint(writer, \"This will print text in blue.\")\n```\n\n### Custom print functions (PrintFunc)\n\n```go\n// Create a custom print function for convenience\nred := color.New(color.FgRed).PrintfFunc()\nred(\"Warning\")\nred(\"Error: %s\", err)\n\n// Mix up multiple attributes\nnotice := color.New(color.Bold, color.FgGreen).PrintlnFunc()\nnotice(\"Don't forget this...\")\n```\n\n### Custom fprint functions (FprintFunc)\n\n```go\nblue := color.New(color.FgBlue).FprintfFunc()\nblue(myWriter, \"important notice: %s\", stars)\n\n// Mix up with multiple attributes\nsuccess := color.New(color.Bold, color.FgGreen).FprintlnFunc()\nsuccess(myWriter, \"Don't forget this...\")\n```\n\n### Insert into noncolor strings (SprintFunc)\n\n```go\n// Create SprintXxx functions to mix strings with other non-colorized strings:\nyellow := color.New(color.FgYellow).SprintFunc()\nred := color.New(color.FgRed).SprintFunc()\nfmt.Printf(\"This is a %s and this is %s.\\n\", yellow(\"warning\"), red(\"error\"))\n\ninfo := color.New(color.FgWhite, color.BgGreen).SprintFunc()\nfmt.Printf(\"This %s rocks!\\n\", info(\"package\"))\n\n// Use helper functions\nfmt.Println(\"This\", color.RedString(\"warning\"), \"should be not neglected.\")\nfmt.Printf(\"%v %v\\n\", color.GreenString(\"Info:\"), \"an important message.\")\n\n// Windows supported too! Just don't forget to change the output to color.Output\nfmt.Fprintf(color.Output, \"Windows support: %s\", color.GreenString(\"PASS\"))\n```\n\n### Plug into existing code\n\n```go\n// Use handy standard colors\ncolor.Set(color.FgYellow)\n\nfmt.Println(\"Existing text will now be in yellow\")\nfmt.Printf(\"This one %s\\n\", \"too\")\n\ncolor.Unset() // Don't forget to unset\n\n// You can mix up parameters\ncolor.Set(color.FgMagenta, color.Bold)\ndefer color.Unset() // Use it in your function\n\nfmt.Println(\"All text will now be bold magenta.\")\n```\n\n### Disable/Enable color\n\nThere might be a case where you want to explicitly disable/enable color output. the \n`go-isatty` package will automatically disable color output for non-tty output streams \n(for example if the output were piped directly to `less`).\n\nThe `color` package also disables color output if the [`NO_COLOR`](https://no-color.org) environment\nvariable is set to a non-empty string.\n\n`Color` has support to disable/enable colors programmatically both globally and\nfor single color definitions. For example suppose you have a CLI app and a\n`-no-color` bool flag. You can easily disable the color output with:\n\n```go\nvar flagNoColor = flag.Bool(\"no-color\", false, \"Disable color output\")\n\nif *flagNoColor {\n\tcolor.NoColor = true // disables colorized output\n}\n```\n\nIt also has support for single color definitions (local). You can\ndisable/enable color output on the fly:\n\n```go\nc := color.New(color.FgCyan)\nc.Println(\"Prints cyan text\")\n\nc.DisableColor()\nc.Println(\"This is printed without any color\")\n\nc.EnableColor()\nc.Println(\"This prints again cyan...\")\n```\n\n## GitHub Actions\n\nTo output color in GitHub Actions (or other CI systems that support ANSI colors), make sure to set `color.NoColor = false` so that it bypasses the check for non-tty output streams. \n\n\n## Credits\n\n* [Fatih Arslan](https://github.com/fatih)\n* Windows support via @mattn: [colorable](https://github.com/mattn/go-colorable)\n\n## License\n\nThe MIT License (MIT) - see [`LICENSE.md`](https://github.com/fatih/color/blob/master/LICENSE.md) for more details\n","funding_links":[],"categories":["命令行","Popular","Go","开源类库","Misc","Command Line","Go Libraries","Open source library","CUI","Programming Languages","语言资源库","\u003cspan id=\"命令行-command-line\"\u003e命令行 Command Line\u003c/span\u003e","Go 🐹"],"sub_categories":["Advanced Console UIs","命令行","Atom Extensions","Command Line","Go","go","高级控制台界面","高級控制台界面","\u003cspan id=\"高级控制台用户界面-advanced-console-uis\"\u003e高级控制台用户界面 Advanced Console UIs\u003c/span\u003e"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffatih%2Fcolor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffatih%2Fcolor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffatih%2Fcolor/lists"}