C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Colored printing for std::print and std::println

From: Henrik Nyhammer <hsn95_at_[hidden]>
Date: Mon, 20 May 2024 19:21:59 +0200
To clearify, I mean that it would be nice to add an API based on the one from fmt, while leaving the implementation of it to the C++ implementors. That way we could have an API that fits nicely together with std::println, but without having to resort to something like ANSI escape sequences on platforms where it doesn't make sense to do so. I think that if we added something like this it would be a huge boost to what you can achieve with the standard library alone. And without it you're left with resorting to 3rd-parties as soon as you want to do something slightly more fancy in your console application, which is a small hassle in itself, and the 3rd-party library may be implemented in a way that does not work well with a lot of consoles out there anyway, like using ANSI escape sequences.
Also, other languages like C# comes with this feature out-of-the-box, so why shouldn't C++ do so?

20. mai 2024 08:09 skrev Jan Schultke <janschultke_at_[hidden]>:

Colored printing is generally useful, but I think it's better done
using third-party libraries.

The link you've posted relies on ANSI escape sequences, and not every
terminal emulator supports them. Older versions of cmd.exe didn't
allow for this, for example. I'm also not sure how consistent various
terminal emulators are in implementing the various ANSI escape codes.
ANSI sequences also aren't something nice that can be abstracted from
easily, like RGB colors. They are made of various palettes and it all
feels a bit arbitrary.

All you need to get some basic ANSI features is to include some header
with a bunch of "inline constexpr string_view" constants for various
ANSI codes, so it's also not like this *needs* to be in the standard
library for a viable implementation. It's quite trivial.


Received on 2024-05-20 17:22:15