{"id":13788140,"url":"https://github.com/anderseknert/colorized","last_synced_at":"2026-01-03T23:31:05.318Z","repository":{"id":109367035,"uuid":"474952260","full_name":"anderseknert/colorized","owner":"anderseknert","description":"Colorized output for the Rego print function!","archived":false,"fork":false,"pushed_at":"2022-03-28T12:28:55.000Z","size":32,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-14T20:50:41.602Z","etag":null,"topics":["colorize","colors","opa","open-policy-agent","print","rego"],"latest_commit_sha":null,"homepage":"","language":"Open Policy Agent","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/anderseknert.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-03-28T10:28:22.000Z","updated_at":"2022-03-29T18:51:29.000Z","dependencies_parsed_at":"2023-04-26T08:00:26.878Z","dependency_job_id":null,"html_url":"https://github.com/anderseknert/colorized","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anderseknert%2Fcolorized","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anderseknert%2Fcolorized/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anderseknert%2Fcolorized/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anderseknert%2Fcolorized/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/anderseknert","download_url":"https://codeload.github.com/anderseknert/colorized/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244538573,"owners_count":20468740,"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":["colorize","colors","opa","open-policy-agent","print","rego"],"created_at":"2024-08-03T21:00:37.458Z","updated_at":"2026-01-03T23:31:05.239Z","avatar_url":"https://github.com/anderseknert.png","language":"Open Policy Agent","funding_links":[],"categories":["Fun and Quirky"],"sub_categories":["Testing Blogs and Articles"],"readme":"# colorized\n\nColorized output for the Rego\n[print](https://blog.openpolicyagent.org/introducing-the-opa-print-function-809da6a13aee)\nfunction!\n\n## Colors\n\nSupport \"all\" the [ANSI color codes](https://talyian.github.io/ansicolors/) by their name:\n\n- black\n- \u003cspan style=\"color:red\"\u003ered\u003c/span\u003e\n- \u003cspan style=\"color:green\"\u003egreen\u003c/span\u003e\n- \u003cspan style=\"color:yellow\"\u003eyellow\u003c/span\u003e\n- \u003cspan style=\"color:blue\"\u003eblue\u003c/span\u003e\n- \u003cspan style=\"color:magenta\"\u003emagenta\u003c/span\u003e\n- \u003cspan style=\"color:cyan\"\u003ecyan\u003c/span\u003e\n- white\n\n## Functions\n\n### `colorize(str, settings)`\n\nAccepts as the first argument the string to colorize, and as the second argument either string, an array, or an object.\n\n---\n\n`string` - colorize the provided string using the value of argument as the foreground color.\n\n#### Example\n\n```rego\nprint(colorize(\"foo bar baz\", \"red\"))\n```\n\n![fg_red](assets/fg_red.png)\n\n---\n\n`array` - colorize the provided string using the first value of the array as foreground color,\n          and the second value as the background color.\n\n#### Example\n\n```rego\nprint(colorize(\"foo bar baz\", [\"yellow\", \"blue\"]))\n```\n\n![fg_y_bg_b](assets/fg_y_bg_b.png)\n\n---\n\n`object` - colorize the provided string using the `\"fg\"` attribute of the object as foreground color,\n           and the `\"bg\"` attribute as the background color. The optional `\"reset\"` boolean attribute\n           may also be used to disable resetting the colors back to the defaults. This is useful when\n           e.g. printing multiple lines of output without having to repeat the calls to colorize.\n           NOTE: If disabled, ensure that the `reset(str)` function is called manually, or else _any_\n           subsequent output will remain colorized, including the result of evaluation.\n\n#### Example\n\n```rego\nprint(colorize(\"foo bar baz\", {\"fg\": \"cyan\", \"bg\": \"red\", \"reset\": false}]))\nprint(\"this too!\")\nprint(reset(\"\"))\n```\n\n![advanced](assets/advanced.png)\n\n### `rainbow(str)`\n\nReturn the provided string with a different foreground color used for each letter of the string.\n\n#### Example\n\n```rego\nprint(rainbow(\"Double rainbows!!\"))\n```\n\n![rainbow](assets/rainbow.png)\n\n### `reset(str)`\n\nResets the colors to the default. Only necessary when reset was disabled in the first place, using the\nobject variant of `colorize`. You'll most likely won't need this.\n\n## Caveats\n\n* JSON (luckily!) does not support the escape sequences required for colorization, so this works only\n  for the `print` command - not values returned by OPA itself\n* This is only for fun. Don't use this for anything serious.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanderseknert%2Fcolorized","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fanderseknert%2Fcolorized","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanderseknert%2Fcolorized/lists"}