{"id":15036681,"url":"https://github.com/onevcat/rainbow","last_synced_at":"2025-05-14T00:08:50.003Z","repository":{"id":3107291,"uuid":"48460820","full_name":"onevcat/Rainbow","owner":"onevcat","description":"Delightful console output for Swift developers.","archived":false,"fork":false,"pushed_at":"2025-01-08T07:16:23.000Z","size":376,"stargazers_count":1874,"open_issues_count":1,"forks_count":112,"subscribers_count":32,"default_branch":"master","last_synced_at":"2025-05-03T02:11:28.608Z","etag":null,"topics":["console","log","output","swift"],"latest_commit_sha":null,"homepage":"","language":"Swift","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/onevcat.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":"Support/Info.plist","governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-12-23T00:40:29.000Z","updated_at":"2025-04-29T15:29:35.000Z","dependencies_parsed_at":"2024-10-19T12:37:53.596Z","dependency_job_id":"186d6bf7-be25-42ff-b857-7722280b3dc7","html_url":"https://github.com/onevcat/Rainbow","commit_stats":{"total_commits":169,"total_committers":13,"mean_commits":13.0,"dds":"0.18934911242603547","last_synced_commit":"f5004e438b7e7377466ca5cf8aea97aea8ad2486"},"previous_names":[],"tags_count":22,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/onevcat%2FRainbow","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/onevcat%2FRainbow/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/onevcat%2FRainbow/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/onevcat%2FRainbow/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/onevcat","download_url":"https://codeload.github.com/onevcat/Rainbow/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254044036,"owners_count":22005063,"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":["console","log","output","swift"],"created_at":"2024-09-24T20:31:55.939Z","updated_at":"2025-05-14T00:08:44.994Z","avatar_url":"https://github.com/onevcat.png","language":"Swift","readme":"![Rainbow](https://raw.githubusercontent.com/onevcat/Rainbow/assets/rainbow.png)\n\n\u003cp align=\"center\"\u003e\n\u003ca href=\"https://github.com/onevcat/Rainbow/actions/workflows/ci.yaml\"\u003e\u003cimg src=\"https://github.com/onevcat/Rainbow/actions/workflows/ci.yaml/badge.svg\"\u003e\u003c/a\u003e\n\u003ca href=\"https://codecov.io/github/onevcat/Rainbow?branch=master\"\u003e\u003cimg src=\"https://img.shields.io/codecov/c/github/onevcat/Rainbow.svg\"\u003e\u003c/a\u003e\n\u003ca href=\"https://swift.org/package-manager/\"\u003e\u003cimg src=\"https://img.shields.io/badge/SPM-ready-orange.svg\"\u003e\u003c/a\u003e\n\u003ca href=\"http://cocoadocs.org/docsets/RainbowSwift\"\u003e\u003cimg src=\"https://img.shields.io/badge/platform-osx%7Clinux%7Cwindows-lightgrey.svg\"\u003e\u003c/a\u003e\n\u003ca href=\"https://raw.githubusercontent.com/onevcat/Rainbow/master/LICENSE\"\u003e\u003cimg src=\"https://img.shields.io/cocoapods/l/RainbowSwift.svg?style=flat\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n`Rainbow` adds text color, background color and style for console and command \nline output in Swift. It is born for cross-platform software logging \nin terminals, working in both Apple's platforms and Linux.\n\n## Basic Usage\n\nNifty way, using the `String` extension, and print the colorized string.\n\n### Named Color \u0026 Style\n\n```swift\nimport Rainbow\n\nprint(\"Red text\".red)\nprint(\"Blue background\".onBlue)\nprint(\"Light green text on white background\".lightGreen.onWhite)\n\nprint(\"Underline\".underline)\nprint(\"Cyan with bold and blinking\".cyan.bold.blink)\n\nprint(\"Plain text\".red.onYellow.bold.clearColor.clearBackgroundColor.clearStyles)\n```\n\nIt gives you something like this:\n\n![](https://user-images.githubusercontent.com/1019875/110485682-3fdfa700-812f-11eb-83f7-ca79795a0514.png)\n\n## Installation\n\n### Swift Package Manager\n\nIf you are developing a cross platform software in Swift, \n[Swift Package Manager](https://github.com/apple/swift-package-manager) might \nbe your choice for package management. Just add the url of this repo to your \n`Package.swift` file as a dependency:\n\n```swift\nimport PackageDescription\n\nlet package = Package(\n    name: \"YourAwesomeSoftware\",\n    dependencies: [\n        .package(url: \"https://github.com/onevcat/Rainbow\", .upToNextMajor(from: \"4.0.0\"))\n    ],\n    targets: [\n        .target(\n            name: \"MyApp\",\n            dependencies: [\"Rainbow\"]\n        )\n    ]\n)\n```\n\nThen run `swift build` whenever you get prepared.\n\nYou could know more information on how to use Swift Package Manager in Apple's [official page](https://swift.org/package-manager/).\n\n## Other Usage\n\n### String Interpolation \u0026 Nested\n\nSwift string interpolation is supported. Define the color for part of the string. Or even create nested colorful strings. The inner color style will be kept:\n\n```swift\nprint(\"接天莲叶\\(\"无穷碧\".green)，映日荷花\\(\"别样红\".red)\")\nprint(\"\\(\"两只黄鹂\".yellow)鸣翠柳，一行白鹭\\(\"上青天\".lightBlue)。\".lightGreen.underline)\n```\n\n![](https://user-images.githubusercontent.com/1019875/110489426-bcc05000-8132-11eb-8b13-caab01faa416.png)\n\n### ANSI 256-Color Mode\n\n[8-bit color](https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit) is fully supported, for both text color and background color:\n\n```swift\nprint(\"停车坐爱\\(\"枫林晚\".bit8(31))，\\(\"霜叶\".bit8(160))红于\\(\"二月花\".bit8(198))。\")\nprint(\"\\(\"一道残阳\".bit8(202))铺水中，\\(\"半江瑟瑟\".bit8(30).onBit8(226))半江红。\")\n```\n\n![](https://user-images.githubusercontent.com/1019875/110490505-bda5b180-8133-11eb-97b2-f376d62e07de.png)\n\n### Hex Colors (approximated)\n\nIt also accepts a Hex color. Rainbow tries to convert it to a most approximate `.bit8` color:\n\n```swift\nprint(\"黑云压城\\(\"城欲摧\".hex(\"#666\"))，甲光向日\\(\"金鳞开\".hex(\"000000\").onHex(\"#E6B422\"))。\")\nprint(\"日出江花\\(\"红胜火\".hex(0xd11a2d))，春来江水\\(\"绿如蓝\".hex(0x10aec2))\")\n```\n\n![](https://user-images.githubusercontent.com/1019875/110492277-60aafb00-8135-11eb-9aba-e25658f5bc06.png)\n\n\u003e Valid format: `\"FFF\"`, `\"#FFF\"`, `\"FFFFFF\"`, `\"#FFFFFF\"`, `0xFFFFFF`\n\n### True color\n\nA few terminal emulators supports 24-bit true color. If you are sure the 24-bit colors can be displayed in your user's\nterminal, Rainbow has no reason to refuse them!\n\n```swift\nprint(\"疏影横斜\\(\"水清浅\".bit24(36,116,181))，暗香浮动\\(\"月黄昏\".bit24(254,215,26))\")\nprint(\"\\(\"春色满园\".hex(\"#ea517f\", to: .bit24))关不住，\\(\"一枝红杏\".hex(\"#f43e06\", to: .bit24))出墙来。\")\n```\n\n![](https://user-images.githubusercontent.com/1019875/110496210-9d2c2600-8138-11eb-803d-15a745ef1dfb.png)\n\n### Output Target\n\nBy default, Rainbow should be smart enough to detect the output target, to determine if it is a tty. For example, it\nautomatically output plain text if written to a file:\n\n```sh\n// main.swift\nprint(\"Hello Rainbow\".red)\n\n$ .build/debug/RainbowDemo \u003e output.txt\n\n// output.txt\nHello Rainbow\n```\n\nThis is useful for sharing the same code for logging to console and to a log file.\n\nYou can manually change this behavior. Rainbow follows these rules in priority:\n\n- Set the `Rainbow.enabled` in your code explicitly.\n- Pass `FORCE_COLOR=1` to enable color even if the output is not a tty. ([`FORCE_COLOR`](https://force-color.org/) has a higher priority than `NO_COLOR`)\n- Pass `NO_COLOR=1` as environment value when executing your app to disable color.\n- Set the `Rainbow.outputTarget` yourself.\n\n### Verbose Way\n\nYou can also use the more verbose way if you want:\n\n```swift\nimport Rainbow\nlet output = \"The quick brown fox jumps over the lazy dog\"\n                .applyingCodes(Color.red, BackgroundColor.yellow, Style.bold)\nprint(output) // Red text on yellow, bold of course :)\n```\n\nOr even construct everything from scratch:\n\n```swift\nlet entry = Rainbow.Entry(\n    segments: [\n        .init(text: \"Hello \", color: .named(.magenta)),\n        .init(text: \"Rainbow\", color: .bit8(214), backgroundColor: .named(.lightBlue), styles: [.underline]),\n    ]\n)\nprint(Rainbow.generateString(for: entry))\n```\n\nPlease remember, the string extensions (such as `\"Hello\".red`) is `O(n)`. So if you are handling a huge string or very \ncomplex nesting, there might be a performance issue or hard to make things in stream. The manual way is a rescue for these\ncases.\n\n\n## Motivation and Compatibility\n\nThanks to the open source of Swift, developers now could write cross platform \nprograms with the same language. And I believe the command line software would be \nthe next great platform for Swift. Colorful and well-organized output always \nhelps us to understand what happens. It is really a necessary utility to create \nwonderful software. \n\n`Rainbow` should work well in both OS X and Linux terminals. It is smart enough \nto check whether the output is connected to a valid text terminal or not, to \ndecide the log should be modified or not. This could be useful when you want to\n send your log to a file instead to console.\n\n\n## Contact\n\nFollow and contact me on [Twitter](http://twitter.com/onevcat) or \n[Sina Weibo](http://weibo.com/onevcat). If you find an issue, \njust [open a ticket](https://github.com/onevcat/Rainbow/issues/new) on it. Pull \nrequests are warmly welcome as well.\n\n## Backers \u0026 Sponsors\n\nOpen-source projects cannot live long without your help. If you find Kingfisher is useful, please consider supporting this\nproject by becoming a sponsor. Your user icon or company logo shows up [on my blog](https://onevcat.com/tabs/about/) with a link to your home page.\n\nBecome a sponsor through [GitHub Sponsors](https://github.com/sponsors/onevcat). :heart:\n\n## License\n\nRainbow is released under the MIT license. See LICENSE for details.\n","funding_links":["https://github.com/sponsors/onevcat"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fonevcat%2Frainbow","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fonevcat%2Frainbow","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fonevcat%2Frainbow/lists"}