{"id":19963831,"url":"https://github.com/thefcraft/fmt-display-cpp","last_synced_at":"2026-04-09T08:54:28.856Z","repository":{"id":254414756,"uuid":"846465642","full_name":"thefcraft/fmt-display-cpp","owner":"thefcraft","description":"A lightweight C++ library for custom formatted output using templates, featuring type-based printing and support for standard and custom types.","archived":false,"fork":false,"pushed_at":"2025-01-25T17:16:58.000Z","size":280,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-25T18:20:50.943Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://fmt-display-cpp.thefcraft.site/","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/thefcraft.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2024-08-23T09:13:02.000Z","updated_at":"2025-01-25T17:17:02.000Z","dependencies_parsed_at":"2024-12-07T18:19:24.049Z","dependency_job_id":"8e0d5244-5c41-4a64-83a1-82dac087aa16","html_url":"https://github.com/thefcraft/fmt-display-cpp","commit_stats":null,"previous_names":["thefcraft/fmt-display-cpp"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thefcraft%2Ffmt-display-cpp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thefcraft%2Ffmt-display-cpp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thefcraft%2Ffmt-display-cpp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thefcraft%2Ffmt-display-cpp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/thefcraft","download_url":"https://codeload.github.com/thefcraft/fmt-display-cpp/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241396777,"owners_count":19956408,"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":[],"created_at":"2024-11-13T02:17:36.698Z","updated_at":"2026-04-09T08:54:28.845Z","avatar_url":"https://github.com/thefcraft.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# fmt::display - A Flexible C++ Formatting and Testing Library\n\n[![Ask DeepWiki](https://devin.ai/assets/askdeepwiki.png)](https://deepwiki.com/thefcraft/fmt-display-cpp)\n\n`fmt::display` is a header-only C++ library that provides a flexible and extensible way to format and display various data types. Additionally, the library now includes a simple testing framework (`test::assert.h`) that allows for easy creation and execution of unit tests within your C++ project.\n\n## Features\n\n- **Custom display implementations** for user-defined types.\n- **ANSI color support** for terminal output.\n- **Built-in support for standard containers** like `vector`, `map`, and `set`.\n- **Support for C++17 features** like `std::optional` and `std::variant`.\n- **Simple testing framework** for creating and running unit tests.\n- **Compile-time type checking** for printable types.\n- **String-building capabilities** with the `fmtout` class.\n- **Variadic template functions** for flexible printing.\n\n## Requirements\n\n- C++11 compatible compiler.\n- Header-only library (no compilation needed).\n\n## Installation\n\n1. Clone this repository or download the `fmt.display.h` and `test.assert.h` files.\n2. Include the headers in your C++ project:\n\n```cpp\n#include \"fmt.display.h\"\n#include \"test.assert.h\"\n```\n\n## Usage\n\n### Basic Printing\n\n```cpp\n#include \"fmt.display.h\"\n\nint main() {\n    fmt::println(\"Hello, world!\");\n    fmt::print(\"Value: \", 42, \"\\n\");\n    return 0;\n}\n```\n\nOutput:\n```\nHello, world!\nValue: 42\n```\n\n### Custom Types\n\nDefine a `Display` specialization for your custom types:\n\n```cpp\nstruct Point {\n    int x, y;\n};\n\ntemplate\u003c\u003e\nstruct fmt::Display\u003cPoint\u003e {\n    static std::string print(const Point\u0026 p) {\n        return fmt::sprint(\"(\", p.x, \", \", p.y, \")\");\n    }\n};\n\nint main() {\n    Point p{10, 20};\n    fmt::println(\"Point: \", p);\n    return 0;\n}\n```\n\nOutput:\n```\nPoint: (10, 20)\n```\n\n### Container Support\n\nThe library provides built-in support for standard containers:\n\n```cpp\n#include \u003cvector\u003e\n#include \u003cmap\u003e\n#include \u003cset\u003e\n\nint main() {\n    std::vector\u003cint\u003e vec = {1, 2, 3, 4, 5};\n    std::map\u003cstd::string, int\u003e map = {{\"one\", 1}, {\"two\", 2}};\n    std::set\u003cchar\u003e set = {'a', 'b', 'c'};\n\n    fmt::println(\"Vector: \", vec);\n    fmt::println(\"Map: \", map);\n    fmt::println(\"Set: \", set);\n\n    return 0;\n}\n```\n\nOutput:\n```\nVector: [1, 2, 3, 4, 5]\nMap: {one: 1, two: 2}\nSet: {a, b, c}\n```\n\n### ANSI Colors\n\nUse ANSI color codes for terminal output:\n\n```cpp\nfmt::println(ansi::red, \"Error: \", ansi::reset, \"Something went wrong!\");\n```\n\nOutput (colors may not be visible here):\n```\nError: Something went wrong!\n```\n(The word \"Error:\" would appear in red in a terminal that supports ANSI colors)\n\n### String Building\n\nUse the `fmtout` class for building complex strings:\n\n```cpp\nfmt::fmtout out;\nout \u003c\u003c \"Hello, \" \u003c\u003c ansi::blue \u003c\u003c \"world\" \u003c\u003c ansi::reset \u003c\u003c \"!\";\nfmt::println(out);\n```\n\nOutput (colors may not be visible here):\n```\nHello, world!\n```\n(The word \"world\" would appear in blue in a terminal that supports ANSI colors)\n\n### Advanced Usage\n\nThe library also supports C++17 features like `std::optional` and `std::variant`:\n\n```cpp\n#include \u003coptional\u003e\n#include \u003cvariant\u003e\n\nint main() {\n    std::optional\u003cint\u003e opt1 = 42;\n    std::optional\u003cint\u003e opt2;\n    fmt::println(\"Optional with value: \", opt1);\n    fmt::println(\"Optional without value: \", opt2);\n\n    std::variant\u003cint, float, std::string\u003e var1 = 10;\n    std::variant\u003cint, float, std::string\u003e var2 = 3.14f;\n    std::variant\u003cint, float, std::string\u003e var3 = \"Hello\";\n    fmt::println(\"Variant with int: \", var1);\n    fmt::println(\"Variant with float: \", var2);\n    fmt::println(\"Variant with string: \", var3);\n\n    return 0;\n}\n```\n\nOutput:\n```\nOptional with value: Some(42)\nOptional without value: None\nVariant with int: Variant(10)\nVariant with float: Variant(3.14)\nVariant with string: Variant(Hello)\n```\n\n### Testing Framework\n\nThe `test::assert.h` file adds a simple and intuitive way to write unit tests for your C++ code. It includes assertion functions and a testing runner.\n\n#### Writing Tests\n\n```cpp\n#include \"test.assert.h\"\n\nint main() {\n    RUN_TESTS;\n    return 0;\n}\n\nMAKE_TESTS{\n    It(divide by zero){\n        asserteq(1 / 1, 1);\n    }\n    It(simple equality test){\n        asserteq(\"test\", \"test\");\n    }\n    {\n        assert(42 \u003e 0);\n    }\n}\n```\n\n#### Output Example\n\n```\ntest 1 passed...   [1 / 1:`1` == 1:`1`]      It(divide by zero)\ntest 2 passed...   [\"test\":`test` == \"test\":`test`]      It(simple equality test)\ntest 3 passed...   [42 \u003e 0:`True` == True]      It(test case 3)\nResult : \n        3 tests passed\n        0 tests failed\n```\n\nThis framework allows you to structure and run your tests efficiently with clear output indicating which tests passed or failed.\n\n## Contributing\n\nContributions are welcome! Please feel free to submit a Pull Request.\n\n## License\n\nThis project is open source and available under the [MIT License](LICENSE).\n\n## Future Improvements\n\nWe're always looking to improve `fmt::display` and the testing framework. Here are some areas we're considering for future development:\n\n1. Performance optimizations.\n2. Support for more complex formatting options (padding, alignment, etc.).\n3. Integration with existing logging libraries.\n4. More extensive testing suite.\n5. Additional specializations for other standard library types.\n6. Expanded functionality for the testing framework.\n\nIf you have any suggestions or would like to contribute to these efforts, please open an issue or submit a pull request!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthefcraft%2Ffmt-display-cpp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthefcraft%2Ffmt-display-cpp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthefcraft%2Ffmt-display-cpp/lists"}