Skip to content

Commit a918983

Browse files
authored
maint: handle fmt>=11.2 (#4001)
1 parent 4bbfbc2 commit a918983

File tree

1 file changed

+34
-12
lines changed

1 file changed

+34
-12
lines changed

libmambapy/src/libmambapy/bindings/utils.cpp

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,40 @@
1717

1818
namespace mambapy
1919
{
20-
// NOTE: These fmt "internals" are for internal use only.
21-
// External users should not use them in their projects.
22-
// Instead, rely on the public API or appropriate abstractions.
23-
// (not sure if they exist at the moment for this specific use case though)
24-
// cf. https://github.com/fmtlib/fmt/issues/4466
25-
bool fmt_is_rgb(const fmt::detail::color_type& color_type)
20+
namespace
2621
{
22+
23+
// NOTE: These fmt "internals" are for internal use only.
24+
// External users should not use them in their projects.
25+
// Instead, rely on the public API or appropriate abstractions.
26+
// (not sure if they exist at the moment for this specific use case though)
27+
// cf. https://github.com/fmtlib/fmt/issues/4466
28+
bool fmt_is_rgb(const fmt::detail::color_type& color_type)
29+
{
30+
#if FMT_VERSION >= 110200
31+
return !color_type.is_terminal_color();
32+
#else
33+
return color_type.is_rgb;
34+
#endif
35+
}
36+
37+
auto fmt_color_value(const fmt::detail::color_type& color) -> uint32_t
38+
{
39+
#if FMT_VERSION >= 110200
40+
return color.value();
41+
#else
42+
return color.value.rgb_color;
43+
#endif
44+
}
45+
46+
auto fmt_terminal_color(const fmt::detail::color_type& color) -> uint32_t
47+
{
2748
#if FMT_VERSION >= 110200
28-
return !color_type.is_terminal_color();
49+
return color.value();
2950
#else
30-
return color_type.is_rgb;
51+
return color.value.term_color;
3152
#endif
53+
}
3254
}
3355

3456
void bind_submodule_utils(pybind11::module_ m)
@@ -126,9 +148,9 @@ namespace mambapy
126148
const auto fg = style.get_foreground();
127149
if (fmt_is_rgb(fg))
128150
{
129-
return { { fmt::rgb(fg.value.rgb_color) } };
151+
return { { fmt::rgb(fmt_color_value(fg)) } };
130152
}
131-
return { { static_cast<fmt::terminal_color>(fg.value.term_color) } };
153+
return { { static_cast<fmt::terminal_color>(fmt_terminal_color(fg)) } };
132154
}
133155
)
134156
.def_property_readonly(
@@ -142,9 +164,9 @@ namespace mambapy
142164
const auto bg = style.get_background();
143165
if (fmt_is_rgb(bg))
144166
{
145-
return { { fmt::rgb(bg.value.rgb_color) } };
167+
return { { fmt::rgb(fmt_color_value(bg)) } };
146168
}
147-
return { { static_cast<fmt::terminal_color>(bg.value.term_color) } };
169+
return { { static_cast<fmt::terminal_color>(fmt_terminal_color(bg)) } };
148170
}
149171
)
150172
.def_property_readonly(

0 commit comments

Comments
 (0)