{"id":24935528,"url":"https://github.com/followtheprocess/hue","last_synced_at":"2025-03-28T15:34:22.024Z","repository":{"id":272149182,"uuid":"915621309","full_name":"FollowTheProcess/hue","owner":"FollowTheProcess","description":"A simple, modern colour/style package for CLI applications in Go","archived":false,"fork":false,"pushed_at":"2025-03-15T08:16:51.000Z","size":994,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-15T09:23:07.444Z","etag":null,"topics":["ansi","cli","color","go"],"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/FollowTheProcess.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":"2025-01-12T11:13:40.000Z","updated_at":"2025-03-15T08:16:45.000Z","dependencies_parsed_at":"2025-01-12T14:40:45.280Z","dependency_job_id":"76c8a535-f672-4f56-8917-2a6046cc5118","html_url":"https://github.com/FollowTheProcess/hue","commit_stats":null,"previous_names":["followtheprocess/hue"],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FollowTheProcess%2Fhue","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FollowTheProcess%2Fhue/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FollowTheProcess%2Fhue/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FollowTheProcess%2Fhue/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/FollowTheProcess","download_url":"https://codeload.github.com/FollowTheProcess/hue/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246053897,"owners_count":20716284,"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","cli","color","go"],"created_at":"2025-02-02T15:38:42.725Z","updated_at":"2025-03-28T15:34:22.018Z","avatar_url":"https://github.com/FollowTheProcess.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# hue\n\n[![License](https://img.shields.io/github/license/FollowTheProcess/hue)](https://github.com/FollowTheProcess/hue)\n[![Go Reference](https://pkg.go.dev/badge/github.com/FollowTheProcess/hue.svg)](https://pkg.go.dev/github.com/FollowTheProcess/hue)\n[![Go Report Card](https://goreportcard.com/badge/github.com/FollowTheProcess/hue)](https://goreportcard.com/report/github.com/FollowTheProcess/hue)\n[![GitHub](https://img.shields.io/github/v/release/FollowTheProcess/hue?logo=github\u0026sort=semver)](https://github.com/FollowTheProcess/hue)\n[![CI](https://github.com/FollowTheProcess/hue/workflows/CI/badge.svg)](https://github.com/FollowTheProcess/hue/actions?query=workflow%3ACI)\n[![codecov](https://codecov.io/gh/FollowTheProcess/hue/branch/main/graph/badge.svg)](https://codecov.io/gh/FollowTheProcess/hue)\n\nA simple, modern colour/style package for CLI applications in Go\n\n![demo](https://github.com/FollowTheProcess/hue/raw/main/docs/img/demo.gif)\n\n## Project Description\n\nThe dominant package in this space for Go is [fatih/color] which I've used before and is very good! However, I want to see if I can make something that improves on it. Specifically I want to try and address the following:\n\n- Alignment/width of colourised text is maintained for [text/tabwriter]\n  - Sort of... I cheated and shipped a fork of tabwriter with the right modifications to support ANSI colours (`hue/tabwriter`)\n- Support both `$NO_COLOR` and `$FORCE_COLOR`\n- Smaller public interface\n- Make it so simple you don't even have to think about it\n- As low performance overhead as possible\n\nLike most libraries that do this sort of thing, hue uses [ANSI Escape Codes] to instruct the terminal emulator to render particular colours. See [here](https://gist.github.com/fnky/458719343aabd01cfb17a3a4f7296797) for a helpful breakdown of how these codes work.\n\n\u003e [!IMPORTANT]\n\u003e Windows support is best effort, I don't own or use any windows devices so it's not a super high priority for me. If Windows support is important to you, you should use [fatih/color]\n\n## Installation\n\n```shell\ngo get github.com/FollowTheProcess/hue@latest\n```\n\n## Quickstart\n\nColours and styles in `hue` are implemented as a bitmask and are therefore compile time constants! This means you can do this...\n\n```go\npackage main\n\nimport \"github.com/FollowTheProcess/hue\"\n\nconst (\n    success = hue.Green | hue.Bold\n    failure = hue.Red | hue.Underline\n)\n\nfunc main() {\n    success.Println(\"It worked!\")\n    failure.Println(\"Not really\")\n}\n```\n\n\u003e [!TIP]\n\u003e Most functions from the `fmt` package are implemented for hue styles including `Sprintf`, `Fprintln` etc.\n\n### Performance\n\n`hue` has been designed such that each new style is not a new allocated struct, plus the use of bitmasks to encode style leads to some nice performance benefits!\n\nThis benchmark measures returning a bold cyan string, one from [fatih/color] and one from `hue`:\n\n```plaintext\n❯ go test ./... -run None -benchmem -bench BenchmarkColour\ngoos: darwin\ngoarch: arm64\npkg: github.com/FollowTheProcess/hue\ncpu: Apple M1 Pro\nBenchmarkColour/hue-8            7497607               138.7 ns/op            80 B/op          3 allocs/op\nBenchmarkColour/color-8          2893501               415.2 ns/op           248 B/op         12 allocs/op\nPASS\nok      github.com/FollowTheProcess/hue 3.044s\n```\n\n- Nearly 70% faster\n- Nearly 70% less bytes copied\n- 9 fewer heap allocations!\n\n\u003e [!NOTE]\n\u003e This benchmark used to be in here and run as part of CI, but I found that `fatih/color` would show up as an indirect dependency\n\u003e in code that imported `hue` so I got rid of it, you'll just have to trust me I guess 😂\n\n### Tabwriter\n\nA common issue with ANSI colour libraries in Go are that they don't play well with [text/tabwriter]. This is because tabwriter includes the ANSI escape sequence in the cell width calculations, throwing off where it aligns the columns.\n\nThis has always annoyed me so when making my own ANSI colour library I had to tackle the tabwriter issue!\n\nEnter `hue/tabwriter` a drop in replacement for [text/tabwriter] that doesn't care about ANSI colours ✨\n\n![tabwriter](https://github.com/FollowTheProcess/hue/raw/main/docs/img/tabwriter.gif)\n\n\u003e [!NOTE]\n\u003e The actual change is incredibly simple, just teaching [text/tabwriter] to ignore ANSI codes when it sees them so compatibility\n\u003e should be seamless\n\n### Credits\n\nThis package was created with [copier] and the [FollowTheProcess/go_copier] project template.\n\n[copier]: https://copier.readthedocs.io/en/stable/\n[FollowTheProcess/go_copier]: https://github.com/FollowTheProcess/go_copier\n[fatih/color]: https://github.com/fatih/color\n[text/tabwriter]: https://pkg.go.dev/text/tabwriter\n[ANSI Escape Codes]: https://en.wikipedia.org/wiki/ANSI_escape_code\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffollowtheprocess%2Fhue","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffollowtheprocess%2Fhue","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffollowtheprocess%2Fhue/lists"}