{"id":42669030,"url":"https://github.com/mdm-code/termcols","last_synced_at":"2026-01-29T10:22:32.910Z","repository":{"id":62865140,"uuid":"556423872","full_name":"mdm-code/termcols","owner":"mdm-code","description":"Colorize text on the terminal with the Termcols Go package and Tcols terminal command.","archived":false,"fork":false,"pushed_at":"2024-02-04T21:16:49.000Z","size":97,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-06-20T10:13:21.832Z","etag":null,"topics":["cli","color","colorized","colors","go","golang","rgb","rgb24","rgb8","terminal","unix"],"latest_commit_sha":null,"homepage":"https://pkg.go.dev/github.com/mdm-code/termcols","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/mdm-code.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":"2022-10-23T20:21:50.000Z","updated_at":"2023-09-26T12:03:28.000Z","dependencies_parsed_at":"2024-06-20T09:22:22.204Z","dependency_job_id":"36f8336d-2817-4638-9cd2-3c160dd7500d","html_url":"https://github.com/mdm-code/termcols","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"purl":"pkg:github/mdm-code/termcols","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mdm-code%2Ftermcols","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mdm-code%2Ftermcols/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mdm-code%2Ftermcols/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mdm-code%2Ftermcols/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mdm-code","download_url":"https://codeload.github.com/mdm-code/termcols/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mdm-code%2Ftermcols/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28875450,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-29T09:47:23.353Z","status":"ssl_error","status_checked_at":"2026-01-29T09:47:19.357Z","response_time":59,"last_error":"SSL_read: 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":["cli","color","colorized","colors","go","golang","rgb","rgb24","rgb8","terminal","unix"],"created_at":"2026-01-29T10:22:32.373Z","updated_at":"2026-01-29T10:22:32.896Z","avatar_url":"https://github.com/mdm-code.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ch1 align=\"center\"\u003e\n  \u003cdiv\u003e\n    \u003cimg src=\"https://raw.githubusercontent.com/mdm-code/mdm-code.github.io/main/termcols_logo.png\" alt=\"logo\"/\u003e\n  \u003c/div\u003e\n\u003c/h1\u003e\n\n\u003ch4 align=\"center\"\u003eColorful text in your terminal implemented in Go\u003c/h4\u003e\n\n\u003cdiv align=\"center\"\u003e\n\u003cp\u003e\n    \u003ca href=\"https://github.com/mdm-code/termcols/actions?query=workflow%3ACI\"\u003e\n        \u003cimg alt=\"Build status\" src=\"https://github.com/mdm-code/termcols/workflows/CI/badge.svg\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://app.codecov.io/gh/mdm-code/termcols\"\u003e\n        \u003cimg alt=\"Code coverage\" src=\"https://codecov.io/gh/mdm-code/termcols/branch/main/graphs/badge.svg?branch=main\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://opensource.org/licenses/MIT\" rel=\"nofollow\"\u003e\n        \u003cimg alt=\"MIT license\" src=\"https://img.shields.io/github/license/mdm-code/termcols\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://goreportcard.com/report/github.com/mdm-code/termcols\"\u003e\n        \u003cimg alt=\"Go report card\" src=\"https://goreportcard.com/badge/github.com/mdm-code/termcols\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://pkg.go.dev/github.com/mdm-code/termcols\"\u003e\n        \u003cimg alt=\"Go package docs\" src=\"https://img.shields.io/badge/go.dev-reference-007d9c?logo=go\u0026logoColor=white\"\u003e\n    \u003c/a\u003e\n\u003c/p\u003e\n\u003c/div\u003e\n\nThe `termcols` package implements ANSI color codes that can be used to color\ntext on the terminal. Different styles and foreground/background colors can be\nchained together through an intuitive package API to arrive at some cool visual\neffects.\n\nThe selection of style and color control sequences implemented by the package\nwas largely based on an exhaustive list of Select Graphic Rendition (SGR)\ncontrol sequences available at [Wikipedia ANSI](https://en.wikipedia.org/wiki/ANSI_escape_code).\nIt is a great resource in case one or more elements appear not to be supported\nin a given terminal.\n\nThe Escape sequence for `termcols` is set to `\\033`, which means that it should\nwork without any issues with Bash, Zsh or Dash. Other shells might not support\nit.\n\nThe same applies to 8-bit and 24-bit colors: there is no guarantee that these\nescape sequences are supported will be rendered properly on some terminals.\nResults may vary, so it is good practice to test it first for compatibility.\n\nConsult the [package documentation](https://pkg.go.dev/github.com/mdm-code/termcols)\nor see [Usage](#usage) section below to check how to use the public API of the\n`termcols` package.\n\n\n## Installation\n\nUse the following command to add the package to an existing project.\n\n```sh\ngo get github.com/mdm-code/termcols\n```\n\nInstall the package to use the command-line `tcols` command to colorize\ntext on the terminal.\n\n```sh\ngo install github.com/mdm-code/termcols@latest\n```\n\n\n## Usage\n\nHere is an example of how to use the public API of the `termcols` package.\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\n\t\"github.com/mdm-code/termcols\"\n)\n\nfunc main() {\n\ts := termcols.Colorize(\n\t\t\"Colorized text!\",\n\t\ttermcols.RedFg,\n\t\ttermcols.Underline,\n\t\ttermcols.Rgb24(termcols.BG, 120, 255, 54),\n\t)\n\tfmt.Println(s)\n}\n```\n\nAside from using the `termcols` package API that can be used in your Go\nproject, can use the `tcols` terminal command:\n\n```sh\ntcols --style 'redfg underline rgb24=bg:120:255:54' \u003c \u003c(echo -n 'Hello, world!')\n```\n\nType `tcols -h` to get a list of styles and colors to (1) see what is implemented\nand (2) what is supported by your terminal.\n\n\nAlternatively, `tcols` can be run from inside of the Docker container:\n\n```sh\ndocker run --rm --tty --volume \"$(pwd)/:/files\" ghcr.io/mdm-code/tcols tcols -s \"redfg bluebg\" files/test.txt\n```\n\nThis however, requires some additional configuration to how the container is\nrun. The default stdout of the container is not recognized as tty by the\nprocess run inside of the container even though it would be printed out to the\nterminal by default. `tcols` detects if stdout is attached to tty or whether\nits piped to stdin of some other process. In the case of the latter, the output\nis not colored because additional SGR control sequences and escape sequences\nwould mess up the text and possibly result in some unexpected output being\npiped out.\n\nThis means that in order to print out the colored output `docker run` has to\ninclude the `--tty` flag to attach the pseudo-tty to the container. This\nprevents piping data with through the stdin of the container as its already\nreserved by the pseudo-tty, so this option is out. `tcols` accepts file names\nas positional arguments, but since files are not immediately accessible from\ninside of the container, one way to go about it is to attach a volume to the\ncontainer and then reference these files accordingly. This is what the example\nabove does.\n\n\n## Development\n\nConsult [Makefile](Makefile) to see how to format, examine code with `go vet`,\nrun unit test, run code linter with `golint` get test coverage and check if the\npackage builds all right.\n\nRemember to install `golint` before you try to run tests and test the build:\n\n```sh\ngo install golang.org/x/lint/golint@latest\n```\n\nIn order to run the benchmark test on unsafe pointers in the tercmols package,\nfire up the following command:\n\n```sh\ngo test -bench=.\n```\n\nThis will give you ns/op value for the setup it's been benchmarked on.\n\n\n## License\n\nCopyright (c) 2024 Michał Adamczyk.\n\nThis project is licensed under the [MIT license](https://opensource.org/licenses/MIT).\nSee [LICENSE](LICENSE) for more details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmdm-code%2Ftermcols","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmdm-code%2Ftermcols","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmdm-code%2Ftermcols/lists"}