我用{fmt}做了一个测试,并且非常容易更改背景色,但是我不能用spdlog获得相同的结果。
我可以通过spdlog获得相同的结果,但这是一个奇怪的代码。
fmt::print( bg( fmt::terminal_color::yellow ) | fg( fmt::terminal_color::black ), " {1:<{0}}\n", 120, "message" );
spdlog::set_pattern( "%v" );
spdlog::info( "\033[43m\033[30m {1:<{0}} \033[m", 120, "message" );发布于 2021-11-17 16:27:48
如果我正确理解了您的问题,您希望使用spdlog来格式化您的fmt输出,而不是自己指定转义序列。为此,您可以使用fmt::format函数并将其输出用作spdlog的变量。
#include <spdlog/spdlog.h>
#include <spdlog/fmt/bundled/color.h>
int main(){
spdlog::info( "Printing a string formatted with fmt: {}",
fmt::format(
fmt::bg( fmt::terminal_color::yellow ) |
fmt::fg( fmt::terminal_color::black ) |
fmt::emphasis::bold,
"message"
)
);
return 0;
}https://stackoverflow.com/questions/69957881
复制相似问题