-
Notifications
You must be signed in to change notification settings - Fork 0
/
fmttest.cpp
48 lines (38 loc) · 1.21 KB
/
fmttest.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <Arduino.h>
#include <Fmt.h>
#include <fmt/color.h>
#include <fmt/ranges.h>
#include <vector>
Fmt f(&Serial);
// Fmt f(Serial); // works too
// fmtlib library panic handler
extern "C" {
void fmtlib_error(const char *file, int line, const char *message) {
Serial.printf("%s:%d: assertion failed: %s\n", file, line, message);
}
}
void setup() {
delay(3000);
Serial.begin(115200);
while (!Serial) {
yield();
}
// see also:
// https://github.com/fmtlib/fmt
// https://fmt.dev/latest/syntax.html#format-specification-mini-language
std::string s = fmt::format("The answer is {}.", 42);
s = fmt::format("The answer is {}.", 42);
f.fmt("{}{}\n", "foo", 4711);
f.fmtln("with implicit newline {}{}", "bar", 815);
std::vector<int> v = {1, 2, 3};
fmt::print("{}\n", v);
fmt::print(fg(fmt::color::crimson) | fmt::emphasis::bold, "Hello, {}!\n",
"world");
fmt::print(fg(fmt::color::floral_white) | bg(fmt::color::slate_gray) |
fmt::emphasis::underline,
"Hello, {}!\n", "мир");
fmt::print(fg(fmt::color::steel_blue) | fmt::emphasis::italic, "Hello, {}!\n",
"世界");
f.printf("f.printf %f %s\n", 3.14, "foo");
}
void loop() { yield(); }