mamba icon indicating copy to clipboard operation
mamba copied to clipboard

Unnecessary termcolor dependency (?)

Open AntoinePrv opened this issue 3 years ago • 5 comments

We use Termcolor for getting a couple colors, but it looks like we could get them from fmt::color, which we also use.

AntoinePrv avatar Sep 06 '22 15:09 AntoinePrv

According to the documentation of those two libraries fmt::color always uses ANSI codes for colors, while Termcolor uses ANSI on most systems, but the windows api on windows.

Windows only started supporting ANSI codes starting with windows 10 and even there it still needs to be manually enabled by the user.

AdrianFreundQC avatar Sep 06 '22 16:09 AdrianFreundQC

I don't know the specifics, but surely we want to be using only one option, not a mix of both, right? (There is even a hard-coded \033[...)

AntoinePrv avatar Sep 07 '22 08:09 AntoinePrv

@AntoinePrv yes, I agree. We started out with termcolor, but later started using fmt. I would be happy if someone wants to refactor mamba to only use fmt :)

wolfv avatar Sep 07 '22 12:09 wolfv

@wolfv I'm looking into it and there is the following limitation: fmt does not support both writing to an std::ostream and using colors. So we would have to do:

Console::stream() << fmt::format(
    fmt::fg(fmt::terminal_color:: "Installing {} packages: {}",
    pkg_mgr, fmt::join(install_instructions, " ")
);

Instead of

Console::stream() << termcolor::cyan << "Installing " << pkg_mgr
                  << " packages: " << join(", ", deps) << termcolor::reset;

Which creates a temporary string.

AntoinePrv avatar Oct 12 '22 13:10 AntoinePrv

I also want to point out that we are explicitly using fmt, while only getting it through spdlog (and that the spdlog conda package does not use the fmt package but vendors it).

#ifdef SPDLOG_FMT_EXTERNAL
#include <fmt/core.h>
#else
#include <spdlog/fmt/bundled/core.h>
#endif

I think we should add an explicit dependency on fmt since we started using it in Mamba.

AntoinePrv avatar Oct 12 '22 13:10 AntoinePrv