{"id":22615733,"url":"https://github.com/polyvariant/colorize-scala","last_synced_at":"2025-04-11T12:12:43.575Z","repository":{"id":60032476,"uuid":"540681422","full_name":"polyvariant/colorize-scala","owner":"polyvariant","description":"Scala microlibrary for ANSI colored strings.","archived":false,"fork":false,"pushed_at":"2024-07-29T23:32:05.000Z","size":26,"stargazers_count":16,"open_issues_count":13,"forks_count":2,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-03-25T08:38:16.125Z","etag":null,"topics":["hacktoberfest"],"latest_commit_sha":null,"homepage":"","language":"Scala","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/polyvariant.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-09-24T02:16:18.000Z","updated_at":"2025-02-16T22:14:01.000Z","dependencies_parsed_at":"2023-02-08T03:31:06.989Z","dependency_job_id":null,"html_url":"https://github.com/polyvariant/colorize-scala","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/polyvariant%2Fcolorize-scala","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/polyvariant%2Fcolorize-scala/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/polyvariant%2Fcolorize-scala/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/polyvariant%2Fcolorize-scala/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/polyvariant","download_url":"https://codeload.github.com/polyvariant/colorize-scala/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248398600,"owners_count":21097292,"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":["hacktoberfest"],"created_at":"2024-12-08T19:09:14.581Z","updated_at":"2025-04-11T12:12:43.550Z","avatar_url":"https://github.com/polyvariant.png","language":"Scala","funding_links":[],"categories":[],"sub_categories":[],"readme":"# colorize-scala\n\nScala microlibrary for ANSI colored strings.\n\n## Installation\n\n```scala\n// for normal usage\n\"org.polyvariant\" %% \"colorize\" % \"0.3.2\"\n// for Scala.js / Scala Native\n\"org.polyvariant\" %%% \"colorize\" % \"0.3.2\"\n```\n\n## Usage\n\n```scala\nimport org.polyvariant.colorize._\n```\n\nYou can colorize any string by calling `.colorize`, `.overlay`, or one of the default helpers (we define one for each color in scala's `AnsiColor` trait):\n\n```scala\n\"hello\".red\n// res0: string.ColorizedString = Overlay(\n//   underlying = Wrap(s = \"hello\"),\n//   color = Ansi(prefix = \"\\u001b[31m\")\n// )\n```\n\nIf you colorize a string twice, the displayed color will be the one you used first.\nThis also applies if the string is part of a larger colored string:\n\n```scala\ncolorize\"hello ${\"world\".blue}.red\"\n// res1: string.ColorizedString = Concat(\n//   lhs = Wrap(s = \"hello \"),\n//   rhs = Concat(\n//     lhs = Wrap(s = \"\"),\n//     rhs = Concat(\n//       lhs = Overlay(\n//         underlying = Wrap(s = \"world\"),\n//         color = Ansi(prefix = \"\\u001b[34m\")\n//       ),\n//       rhs = Wrap(s = \".red\")\n//     )\n//   )\n// )\n```\n\nThis will render as \"hello\" in red and \"world\" in blue.\n\nAs you've seen, There's a `colorize` string interpolator which allows you to easily nest colorized strings in each other.\nYou can also combine colorized strings with `++`:\n\n```scala\n\"hello \".red ++ \"world\".blue\n// res2: string.ColorizedString = Concat(\n//   lhs = Overlay(\n//     underlying = Wrap(s = \"hello \"),\n//     color = Ansi(prefix = \"\\u001b[31m\")\n//   ),\n//   rhs = Overlay(\n//     underlying = Wrap(s = \"world\"),\n//     color = Ansi(prefix = \"\\u001b[34m\")\n//   )\n// )\n```\n\nYou can define a default way to colorize a type by creating an instance of the `Colorize` typeclass.\n\n```scala\ncase class Taco(size: Int)\n\nimplicit val tacoColorize: Colorize[Taco] =\n  taco =\u003e \"Taco(\".cyan ++ \"size\".yellow ++ \" = \" ++ taco.size.toString.red ++ \")\".cyan\n\nval taco = Taco(2)\n\ncolorize\"you can colorize $taco\"\n```\n\n## Rendering\n\nTo actually render a colorized string, call `.render`.\n\n```scala\nprintln(\"hello\".red.render) // like this\n```\n\nYou can customize rendering, currently this is limited to passing a custom color suffix.\nInternally, `colorize` works by prepending the desired color sequence to your string and appending a suffix, and `render`'s default suffix is `Console.RESET`.\n\n## RGB color support\n\nIf your terminal supports truecolor, you can display text colorized to an exact RGB value.\nInstead of the default import, use:\n\n```scala\nimport org.polyvariant.colorize.trueColor._\n\n\"hello\".rgb(255, 0, 0).render\n// res6: String = \"\\u001b[38;2;255;0;0mhello\\u001b[0m\"\n```\n\nTo automatically detect RGB support, use:\n\n```scala\nimport org.polyvariant.colorize.auto._\n\n\"hello\".rgb(255, 0, 0).render\n```\n\nIf truecolor isn't available, `rgb` will be ignored. You can use this to implement an ANSI fallback:\n\n```scala\n// if RGB is ignored, `.red` will still be applied\n\"hello\".rgb(255, 0, 0).red.render\n```\n\n\n## Color removal\n\nTo remove all colors and other overlays from a colorized string, use `.dropOverlays`.\n\n## Customization\n\nTo apply customizations, you can make your own `colorize` by extending `ConfiguredColorize`. For example:\n\n```scala\nimport org.polyvariant.colorize.custom._\n\nobject myColorize extends ConfiguredColorize(RenderConfig.Default.copy(resetString = \"\u003cRESET\u003e\"))\n\nimport myColorize._\n\nprintln(\"hello\".overlay(\"\u003cRED\u003e\").render)\n// \u003cRED\u003ehello\u003cRESET\u003e\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpolyvariant%2Fcolorize-scala","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpolyvariant%2Fcolorize-scala","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpolyvariant%2Fcolorize-scala/lists"}