fmt-display-cpp

fmt-display-cpp

A Modern C++ Display Library for effortless formatting and output

Key Features

Customizable Display Traits

Support for custom types via fmt::Display<T>

Standard Container Support

Built-in display for std::vector, std::set, std::map, and more

ANSI Colors

Add color and formatting to your outputs

Compact Large Outputs

Smart printing for large containers

Safe String Formatting

Utility for safe string formatting with fmt::format_string

Runtime Type Safety

Optional compile-time checks for unsupported types

Code Examples

Basic output with colors

example.cpp
fmt::println(ansi::blue, "Hello, ", ansi::green, "World", ansi::reset, "!");

Custom display trait for a struct

example.cpp
struct Point {
    int x, y;
};

template<>
struct fmt::Display<Point> {
    static std::string print(const Point& p) {
        return fmt::format_string("Point(%d, %d)", p.x, p.y);
    }
};

Point p{10, 20};
fmt::println("Point: ", p);  // Output: Point: Point(10, 20)

Printing containers

example.cpp
std::vector<int> numbers = {1, 2, 3, 4, 5};
std::map<std::string, int> scores = {{"Alice", 100}, {"Bob", 85}};
std::set<std::string> names = {"John", "Jane", "Alice"};

fmt::println("Vector: ", numbers);
fmt::println("Map: ", scores);
fmt::println("Set: ", names);

Installation

Clone and run

example.cpp
git clone https://github.com/thefcraft/fmt-display-cpp.git
cd fmt-display-cpp
cp -r fmt {your-project-path}

After installation, include the library in your project:

Include headers

example.cpp
#include "fmt/display.h"
#include "fmt/vector.h"
#include "fmt/set.h"
// ... other headers as needed