{"id":20475669,"url":"https://github.com/dan-almenar/colorize","last_synced_at":"2026-05-28T01:31:44.089Z","repository":{"id":233216911,"uuid":"786305074","full_name":"dan-almenar/colorize","owner":"dan-almenar","description":"Lightweight and zero dependency text formatter for Go CLI apps","archived":false,"fork":false,"pushed_at":"2024-04-14T15:15:44.000Z","size":77,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-04-14T18:56:13.196Z","etag":null,"topics":["ansi","go","text-formatting","xterm"],"latest_commit_sha":null,"homepage":"https://pkg.go.dev/github.com/dan-almenar/colorize","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/dan-almenar.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}},"created_at":"2024-04-14T03:27:47.000Z","updated_at":"2024-06-19T12:13:38.937Z","dependencies_parsed_at":null,"dependency_job_id":"25199518-b999-4711-9063-208538b6b4d0","html_url":"https://github.com/dan-almenar/colorize","commit_stats":null,"previous_names":["dan-almenar/colorize"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/dan-almenar/colorize","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dan-almenar%2Fcolorize","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dan-almenar%2Fcolorize/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dan-almenar%2Fcolorize/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dan-almenar%2Fcolorize/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dan-almenar","download_url":"https://codeload.github.com/dan-almenar/colorize/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dan-almenar%2Fcolorize/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33590884,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-05-27T02:00:06.184Z","response_time":53,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","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":["ansi","go","text-formatting","xterm"],"created_at":"2024-11-15T15:16:47.827Z","updated_at":"2026-05-28T01:31:44.074Z","avatar_url":"https://github.com/dan-almenar.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# colorize\n\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://github.com/dan-almenar/colorize/blob/master/LICENSE)\n[![Go Report Card](https://goreportcard.com/badge/github.com/dan-almenar/colorize)](https://goreportcard.com/report/github.com/dan-almenar/colorize)\n\nPackage colorize provides functions for formatting text with true color or Xterm approximations.\n\n## Overview\n\nThe `colorize` package offers developers the ability to format text with various colors and styles, supporting both true color (24-bit) and Xterm (256-color) systems. It provides flexibility in text formatting for terminal-based applications.\n\n**Features:**\n- Supports true color (24-bit) and Xterm (256-color) systems\n- No dependencies\n- Lightweight\n- Easy to use\n\n### Examples\n![Example 1](examples/examples_01.png)\n![Example 2](examples/examples_02.png)\n![Example 3](examples/examples_03.png)\n\n## Installation\n\n```bash\ngo get github.com/dan-almenar/colorize\n```\n\n## API Documentation\n\n**Note:** Functions that return the formatted string and an error, will return the original text string unmodified when the error is not nil. This design choice ensures that the formatted text is always displayed, even if there's an issue with the provided options or system support.\n\nDuring development, it's recommended to handle these errors appropriately to ensure the integrity of the formatted text.\nIn production environments, omitting error handling or simply logging them out in favor of displaying the unformatted text may be acceptable, depending on the application's requirements.\n\n### Functions\n- **GetColor(hex string, ctx ColorContext) (string, error)**:\n  Retrieves the ANSI escape code for setting true color (24-bit) or Xterm (256-color) color based on the provided hexadecimal color code and context (background or foreground).\n\n  Example:\n  ```go\n\n  red, err := c.GetColor(\"#FF0000\", c.Foreground)\n  if err != nil {\n\t  fmt.Println(\"Error:\", err)\n  }\n\n  // since there was no error, we can safely use red\n  fmt.Printf(\"%sThis text will be red%s\\n\", red, c.Reset)\n\n  ```\n\n- **ForegroundText(text string, color string) (string, error)**:\n  Formats text with the specified foreground color.\n\n  Example:\n  ```go\n\n  example, err := c.ForegroundText(\"Hello, world!\", \"#FF0000\") // Red color\n  if err != nil {\n      fmt.Println(\"Error:\", err)\n  }\n  fmt.Println(example)\n\n  ```\n\n- **BackgroundText(text string, color string) (string, error)**:\n  Formats text with the specified background color.\n\n  Example:\n  ```go\n\n  example, err := c.BackgroundText(\"Hello, world!\", \"#FF0000\") // Red color\n  if err != nil {\n\t  fmt.Println(\"Error:\", err)\n  }\n  fmt.Println(example)\n\n  ```\n\n- **StyleText(text string, style []string) string**:\n  Formats text with the specified style.\n  Valid styles are: bold, italic, underline, blink, reverse, hidden, stroke\n  Unlike the ForegroundText and BackgroundText functions, the **StyleText** function does not return an error. If an invalid style is provided, it will be ignored.\n\n  Example:\n  ```go\n\n  fmt.Println(c.StyleText(\"Hello, world!\", []string{\"bold\", \"underline\"})) // Bold and underline text\n\n  ```\n\n- **FormatText(text string, options *Options) (string, error)**:\n  Formats text with the specified options.\n\n  Example:\n  ```go\n\n  example, err := c.FormatText(\"Hello, world!\", \u0026Options{\n\tForeground: \"#FF0000\",\n\tBackground: \"#00FF00\",\n\tStyle:      []string{\"bold\", \"underline\"},\n  })\n  if err != nil {\n\t  fmt.Println(\"Error:\", err)\n  }\n  fmt.Println(example)\n\n  ```\n\t\n### Types\n- **Options**: \n  Represents the options for formatting text.\n  Fields:\n  - **Foreground**: (string) The foreground color for the text.\n  - **Background**: (string) The background color for the text.\n  - **Style**: ([]string) The style(s) for the text.\n- **ColorContext**:\n  Represents the context of the color (\"background\" or \"foreground\").\n\t \n## Test Information\n### Tests\nUnit tests have been conducted with over 96% code coverage. Detailed test results can be found in [tests_results](https://github.com/dan-almenar/colorize/blob/master/tests_results/tests_results.txt).\n\nTo run the tests locally, navigate to the package directory and execute:\n```bash\ngo test -v -cover\n```\n\n### Benchmarks\nBenchmarks have been performed to evaluate the performance of the package. Results are available in [benchmark_results](https://github.com/dan-almenar/colorize/blob/master/tests_results/benchmarks_results.txt).\n\nTo run the benchmarks locally, navigate to the package directory and execute:\n```bash\ngo test -v -bench=.\n```\n\n## How to Contribute\nContributions to the colorize package are welcome! Feel free to submit bug reports, feature requests, or pull requests through GitHub.\n\nTo contribute, follow these steps:\n1. Clone the repository:\n  ```bash\n   git clone https://github.com/dan-almenar/colorize.git\n  ```\n\n2. Create a new branch for your changes:\n   ```bash\n   git checkout -b feature/new-feature\n   ```\n\n3. Make your changes and ensure that tests pass:\n   ```bash\n   go test\n   ```\n\n4. Commit your changes and push to your forked repository:\n   ```bash\n   git commit -m \"Add new feature\"\n   git push origin feature/new-feature\n   ```\n\n5. Create a pull request on GitHub from your forked repository to the main repository.\n\n## Additional Information\nAuthor:\n**Dan Almenar Williams**\n\nVersion\n0.1.0\n\n## License\nThis project is licensed under the MIT License. See the [LICENSE](https://github.com/dan-almenar/colorize/blob/master/LICENSE.md) file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdan-almenar%2Fcolorize","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdan-almenar%2Fcolorize","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdan-almenar%2Fcolorize/lists"}