{"id":18729419,"url":"https://github.com/alexwkleung/termstylist","last_synced_at":"2025-04-12T16:53:24.243Z","repository":{"id":155670082,"uuid":"517244470","full_name":"alexwkleung/TermStylist","owner":"alexwkleung","description":"🎨 A header-only terminal colours library","archived":false,"fork":false,"pushed_at":"2022-09-06T14:39:28.000Z","size":746,"stargazers_count":4,"open_issues_count":3,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-26T11:21:18.071Z","etag":null,"topics":["16-colors","256-colors","ansi-colors","cpp","cpp-library","cpp17","header-only","terminal-colors","termstylist"],"latest_commit_sha":null,"homepage":"","language":"C++","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/alexwkleung.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-07-24T06:23:48.000Z","updated_at":"2024-02-15T00:54:20.000Z","dependencies_parsed_at":null,"dependency_job_id":"c4b0c8d3-cd79-47d7-a631-18e646bbd4af","html_url":"https://github.com/alexwkleung/TermStylist","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/alexwkleung%2FTermStylist","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexwkleung%2FTermStylist/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexwkleung%2FTermStylist/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexwkleung%2FTermStylist/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alexwkleung","download_url":"https://codeload.github.com/alexwkleung/TermStylist/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248601371,"owners_count":21131609,"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":["16-colors","256-colors","ansi-colors","cpp","cpp-library","cpp17","header-only","terminal-colors","termstylist"],"created_at":"2024-11-07T14:27:03.065Z","updated_at":"2025-04-12T16:53:24.237Z","avatar_url":"https://github.com/alexwkleung.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Table of Contents\n1) [TermStylist](#termstylist)\n2) [Dependencies](#dependencies)\n3) [Installation](#installation)\n4) [Usage (Default Syntax)](#usage-default-syntax)\n5) [Usage (Creating an Object](#usage-creating-an-object)\n6) [Usage (TermStylist Objects Syntax)](#usage-termstylist-objects-syntax)\n7) [Examples](#examples)\n8) [License](#license)\n\n# 🎨 TermStylist\n\n![](img/demo.png)\n*Screenshot above is running demo.cpp in iTerm2.*\n\nTermStylist is a terminal colours library that is header-only. \n\nFeel free to submit any issues or improvements.\n\nEnjoy!\n\n# Dependencies \n\nNo external dependencies are needed in order to use TermStylist. \n\nC++17 is the minimum version you can use since TermStylist has inline variables to prevent duplicate symbols across multiple files due to the internal objects. Now if you need to support an older version, then you may have to rework this part in the header. If necessary, I can tweak the library to make it compatible with older versions.\n\nThe internal objects look like this (removed comments):\n\n```cpp\nnamespace obj_internal {\n    Attributes inline ATTRS;\n\n    Reset inline RESET;\n\n    FGColours816 inline FG816;\n\n    BGColours816 inline BG816;\n\n    FGColours256 inline FG256;\n\n    BGColours256 inline BG256;\n}\n```\n\n**Also**, you need to make sure your terminal supports both ANSI escape codes and at the minimum, 8/16 colours. A terminal that supports both ANSI escape codes and up to 256 colours would be preferred, although not necessary. This will vary depending on your OS platform, but there are tons of good terminal emulators that have proper colour support out of the box. \n\n# Installation\n\nClone the repository.\n\n```bash\ngit clone \u003cSSH/HTTPS URL\u003e\n```\n\nGo to the directory `TermStylist/include` and copy `termstylist.h` into your project - preferrably in an `include` folder.\n\nInclude the header in your project.\n\n```cpp\n#include \"include/termstylist.h\"\n```\n\n**Alternatively:**\n\n1) Go to releases on the right-hand side of this repository.\n2) Find the latest version available for the library (MUST be at least v1.2.0).\n3) Download the `termstylist.h` file.\n4) Copy `termstylist.h` into the `include` directory of your project.\n5) Include the header in your project\n\n```cpp\n#include \"include/termstylist.h\"\n```\n\n# Usage (Default Syntax)\n\nThe ANSI escape code strings are split into 6 categories:\n\n1) Attributes\n2) Reset \n3) Foreground colours - 8/16 colours (FGColours816)\n4) Background colours - 8/16 colours (BGColours816)\n5) Foreground colours - 256 colours (FGColours256)\n6) Background colours - 256 colours (BGColours256)\n\nTermStylist uses `ostream` overloads with a function that returns an output stream containing the string of the ANSI escape code.\n\n**Note:** Remember to reset your attributes/colours using the Reset syntax (i.e., `termstylist::RESET_Default`) or the default syntax correlated to the colour type you're using (i.e., `termstylist::FG_Default`).\n\nIf you need compatibility for terminals that don't support 256 colours, then you should use the syntax for 8/16 colours which is the standard. Using the syntax for 256 colours usually won't be necessary unless you really need a specific colour in there.\n\n--- \n\n**Attributes:**\n\n1) Bold (`termstylist::ATTRS_Bold`)\n2) Dim (`termstylist::ATTRS_Dim`)\n3) Underline (`termstylist::ATTRS_Underline`)\n4) Reverse (`termstylist::ATTRS_Reverse`)\n5) Clear (`termstylist::ATTRS_Clear`)\n\n**Reset:**\n\n1) Default (`termstylist::RESET_Default`)\n2) Bold (`termstylist::RESET_Bold`)\n3) Dim (`termstylist::RESET_Dim`)\n4) Underline (`termstylist::RESET_Underline`)\n5) Reverse (`termstylist::RESET_Reverse`)\n\n**Foreground colours - 8/16 colours (FGColours816):**\n\n*8 colours:*\n\n1) Default (`termstylist::FG_Default`)\n2) Black (`termstylist::FG_Black`)\n3) Red (`termstylist::FG_Red`)\n4) Green (`termstylist::FG_Green`)\n5) Yellow (`termstylist::FG_Yellow`)\n6) Blue (`termstylist::FG_Blue`\n7) Magenta (`termstylist::FG_Magenta`)\n8) Cyan (`termstylist::FG_Cyan`)\n9) White (`termstylist::FG_White`)\n10) Light Grey (`termstylist::FG_LightGrey`)\n11) Dark Grey (`termstylist::FG_DarkGrey`)\n13) Light Red (`termstylist::FG_LightRed`)\n14) Light Green (`termstylist::FG_LightGreen`)\n15) Light Yellow (`termstylist::FG_LightYellow`)\n16) Light Blue (`termstylist::FG_LightBlue`)\n17) Light Magenta (`termstylist::FG_LightMagenta`)\n18) Light Cyan (`termstylist::FG_LightCyan`)\n\n*16 colours (bold, aka bright):*\n\n1) Bold Black (`termstylist::FG_BoldBlack`)\n2) Bold Red (`termstylist::FG_BoldRed`)\n3) Bold Green (`termstylist::FG_BoldGreen`)\n4) Bold Yellow (`termstylist::FG_BoldYellow`)\n5) Bold Blue (`termstylist::FG_BoldBlue`)\n6) Bold Magenta (`termstylist::FG_BoldMagenta`)\n7) Bold Cyan (`termstylist::FG_BoldCyan`)\n8) Bold White (`termstylist::FG_BoldWhite`)\n9) Bold Light Grey (`termstylist::FG_BoldLightGrey`)\n10) Bold Dark Grey (`termstylist::FG_BoldDarkGrey`)\n11) Bold Light Red (`termstylist::FG_BoldLightRed`)\n12) Bold Light Green (`termstylist::FG_BoldLightGreen`)\n13) Bold Light Yellow (`termstylist::FG_BoldLightYellow`)\n14) Bold Light Blue (`termstylist::FG_BoldLightBlue`)\n15) Bold Light Magenta (`termstylist::FG_BoldLightMagenta`)\n16) Bold Light Cyan (`termstylist::FG_BoldLightCyan`)\n\n**Background colours - 8/16 colours (BGColours816):**\n\n*8 colours:*\n\n1) Default (`termstylist::BG_Default`)\n2) Black (`termstylist::BG_Black`)\n3) Red (`termstylist::BG_Red`)\n4) Green (`termstylist::BG_Green`)\n5) Yellow (`termstylist::BG_Yellow`\n6) Blue (`termstylist::BG_Blue`)\n7) Magenta (`termstylist::BG_Magenta`)\n8) Cyan (`termstylist::BG_Cyan`)\n9) White (`termstylist::BG_White`)\n10) Light Grey (`termstylist::BG_LightGrey`)\n11) Dark Grey  (`termstylist::BG_DarkGrey`)\n12) Light Red (`termstylist::BG_LightRed`)\n13) Light Green (`termstylist::BG_LightGreen`)\n14) Light Yellow (`termstylist::BG_LightYellow`)\n15) Light Blue (`termstylist::BG_LightBlue`)\n16) Light Magenta (`termstylist::BG_LightMagenta`)\n17) Light Cyan (`termstylist::BG_LightCyan`)\n\n*16 colours (bold, aka bright):*\n\n1) Bold Black (`termstylist::BG_BoldBlack`)\n2) Bold Red (`termstylist::BG_BoldRed`)\n3) Bold Green (`termstylist::BG_BoldGreen`)\n4) Bold Yellow (`termstylist::BG_BoldYellow`)\n5) Bold Blue (`termstylist::BG_BoldBlue`)\n6) Bold Magenta (`termstylist::BG_BoldMagenta`)\n7) Bold Cyan (`termstylist::BG_BoldCyan`)\n8) Bold White (`termstylist::BG_BoldWhite`)\n9) Bold Light Grey (`termstylist::BG_BoldLightGrey`)\n10) Bold Dark Grey (`termstylist::BG_BoldDarkGrey`)\n11) Bold Light Red (`termstylist::BG_BoldLightRed`)\n12) Bold Light Green (`termstylist::BG_BoldLightGreen`)\n13) Bold Light Yellow (`termstylist::BG_BoldLightYellow`)\n14) Bold Light Blue (`termstylist::BG_BoldLightBlue`)\n15) Bold Light Magenta (`termstylist::BG_BoldLightMagenta`)\n16) Bold Light Cyan (`termstylist::BG_BoldLightCyan`)\n\n**Foreground colours - 256 colours (FGColours256):**\n\n1) 0-256 (`termstylist::FG256_0-256`)\n\nTo use foreground colours (256 colours), the syntax is `termstylist::FG256_0-256`, where the number after the underscore correlates to one of the 256 foreground colours (i.e., 0, 1, 2, etc).\n\n**Background colours - 256 colours (BGColours256):**\n\n1) 0-256 (`termstylist::BG256_0-256`)\n\nTo use background colours (256 colours), the syntax is `termstylist::BG256_0-256`, where the number after the underscore correlates to one of the 256 background colours (i.e., 0, 1, 2, etc).\n\n# Usage (Creating an Object)\n\nYou may opt to create your own objects from the structs to minimize the verboseness or if you prefer to access the ANSI escape codes that way.\n\n1) Attributes (object created via `termstylist::Attributes \u003cobject name\u003e`)\n2) Reset (object created via `termstylist::Reset \u003cobject name\u003e`)\n3) Foreground colours - 8/16 colours (object created via `termstylist::FGColours816 \u003cobject name\u003e`)\n4) Background colours - 8/16 colours (object created via `termstylist::BGColours816 \u003cobject name\u003e`)\n5) Foreground colours - 256 colours (object created via `termstylist::FGColours256 \u003cobject name\u003e`)\n6) Background colours - 256 colours (object created via `termstylist::BGColours256 \u003cobject name\u003e`)\n\nYou can access the objects' members via the dot operator (i.e., `\u003cobject name\u003e.\u003cmember\u003e`).\n\n# Usage (TermStylist Objects Syntax)\n\nTermStylist allows the user to access the ANSI escape code strings from the structs via its own created objects. They are contained within an unnamed namespace in the library header. It's useful if you don't want to create an object yourself, but it might not be depending on your use case. \n\nYou can access the objects' members via the dot operator (i.e., `termstylist::EO_ATTRS.\u003cmember\u003e`).\n\n**Note:** EO means \"External Object\", denoting that it is used only in external files and not within the library's namespace.\n\n1. Attributes (object accessed via `termstylist::EO_ATTRS.\u003cmember\u003e`)\n2. Reset (object accessed via `termstylist::EO_RESET.\u003cmember\u003e`)\n3. Foreground colours - 8/16 colours (object accessed via `termstylist::EO_FG816.\u003cmember\u003e`)\n4. Background colours - 8/16 colours (object accessed via `termstylist::EO_BG816.\u003cmember\u003e`)\n5. Foreground colours - 256 colours (object accessed via `termstylist::EO_FG256.\u003cmember\u003e`)\n6. Background colours - 256 colours (object accessed via `termstylist::EO_BG256.\u003cmember\u003e`)\n\n# Examples \n\n**Attributes**\n\n```cpp\n#include \"include/termstylist.h\"\n#include \u003ciostream\u003e\n\nint main() {\n    std::cout \u003c\u003c termstylist::ATTRS_Bold \u003c\u003c \"I am bold!\" \u003c\u003c termstylist::RESET_Default \u003c\u003c '\\n';\n\n    return 0;\n}\n```\n\n**Foreground colours - 8/16 colours**\n\n```cpp\n#include \"include/termstylist.h\"\n#include \u003ciostream\u003e\n\nint main() {\n    std::cout \u003c\u003c termstylist::FG_LightYellow \u003c\u003c \"I am light yellow!\" \u003c\u003c termstylist::FG_Default \u003c\u003c '\\n';\n    \n    return 0;\n}\n```\n\n**Background colours - 8/16 colours**\n\n```cpp\n#include \"include/termstylist.h\"\n#include \u003ciostream\u003e\n\nint main() {\n    std::cout \u003c\u003c termstylist::BG_BoldBlue \u003c\u003c \"I am bold blue!\" \u003c\u003c termstylist::BG_Default \u003c\u003c '\\n';\n\n    return 0;\n}\n```\n\n**Foreground colours - 256 colours**\n\n```cpp\n#include \"include/termstylist.h\"\n#include \u003ciostream\u003e\n\nint main() {\n    std::cout \u003c\u003c termstylist::FG256_170 \u003c\u003c \"I am colour 170/256!\" \u003c\u003c termstylist::FG_Default \u003c\u003c '\\n';\n\n    return 0;\n}\n```\n\n**Background colours - 256 colours**\n\n```cpp \n#include \"include/termstylist.h\"\n#include \u003ciostream\u003e\n\nint main() {\n    std::cout \u003c\u003c termstylist::BG256_172 \u003c\u003c \"I am colour 172/256!\" \u003c\u003c termstylist::BG_Default \u003c\u003c '\\n';\n\n    return 0;\n}\n```\n\n**Accessing via objects (TermStylist syntax)**\n\n```cpp\n#include \"include/termstylist.h\"\n#include \u003ciostream\u003e\n\nint main() {\n    std::cout \u003c\u003c termstylist::EO_FG256.FG256_208 \u003c\u003c \"I am colour 208/256!\" \u003c\u003c termstylist::EO_FG816.FG_Default \u003c\u003c '\\n';\n\n    return 0;\n}\n```\n\n```cpp\n#include \"include/termstylist.h\"\n#include \u003ciostream\u003e\n\nstd::ostream \u0026boldCyan(std::ostream \u0026out) {\n    out \u003c\u003c termstylist::EO_FG816.FG_BoldCyan \u003c\u003c \"I am bold cyan!\" \u003c\u003c termstylist::EO_FG816.FG_Default;\n\n    return out;\n}\n\nint main() {\n    std::cout \u003c\u003c boldCyan \u003c\u003c '\\n';\n\n    return 0;\n}\n```\n\n```cpp\n#include \"include/termstylist.h\"\n#include \u003ciostream\u003e\n#include \u003cstring\u003e\n\nstruct Colour {\n    public:\n        std::string bgLightMagenta = termstylist::EO_BG816.BG_LightMagenta;\n        std::string bgDefault = termstylist::EO_BG816.BG_Default;\n};\n\nint main() {\n    Colour col;\n\n    std::cout \u003c\u003c col.bgLightMagenta \u003c\u003c \"I am light magenta!\" \u003c\u003c col.bgDefault \u003c\u003c '\\n';\n\n    return 0;\n}\n```\n\n**Accessing via objects (Your own created object)**\n\n```cpp\n#include \"include/termstylist.h\"\n#include \u003ciostream\u003e\n\nint main() {\n    termstylist::Attributes atr;\n    termstylist::Reset re;\n\n    std::cout \u003c\u003c atr.ATTRS_Bold \u003c\u003c \"I am bold!\" \u003c\u003c re.RESET_Default \u003c\u003c '\\n';\n\n    return 0;\n}\n```\n\n```cpp\n#include \"include/termstylist.h\"\n#include \u003ciostream\u003e\n\nint main() {\n    termstylist::FGColours816 fg16;\n\n    std::cout \u003c\u003c fg16.FG_Yellow \u003c\u003c \"I am yellow!\" \u003c\u003c f16.FG_Default \u003c\u003c '\\n';\n\n    return 0;\n}\n```\n\n```cpp\n#include \"include/termstylist.h\"\n#include \u003ciostream\u003e\n\nint main() {\n    termstylist::BGColours816 bg16;\n\n    std::cout \u003c\u003c bg16.BG_BoldRed \u003c\u003c \"I am bold red!\" \u003c\u003c bg16.BG_Default \u003c\u003c '\\n';\n\n    return 0;\n}\n```\n\n```cpp\n#include \"include/termstylist.h\"\n#include \u003ciostream\u003e\n\nint main() {\n    termstylist::FGColours256 fg256;\n    termstylist::FGColours816 fg;\n\n    std::cout \u003c\u003c fg256.FG256_2 \u003c\u003c \"2\" \u003c\u003c fg.FG_Default \u003c\u003c '\\n';\n    \n    return 0;\n}\n```\n\n```cpp\n#include \"include/termstylist.h\"\n#include \u003ciostream\u003e\n\nint main() {\n    termstylist::BGColours256 bg256;\n    termstylist::Reset re;\n\n    std::cout \u003c\u003c bg256.BG256_204 \u003c\u003c \"204\" \u003c\u003c re.RESET_Default \u003c\u003c '\\n';\n\n    return 0;\n}\n```\n\n# License \n\n[MIT License](LICENSE).","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexwkleung%2Ftermstylist","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falexwkleung%2Ftermstylist","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexwkleung%2Ftermstylist/lists"}