colored icon indicating copy to clipboard operation
colored copied to clipboard

Implement `Add` on `ColoredString`

Open hwittenborn opened this issue 2 years ago • 3 comments

It would be nice to be able to add ColoredString instances together, so that something like "blue".blue() + "red".red() could be done. It would also be nice to add normal strings as well (i.e. "blue".blue() + "|" + "red".red()).

I'm not sure how this would work with #139 when mixing different formatter types though.

hwittenborn avatar Jul 03 '23 12:07 hwittenborn

This will be added after #139 gets implemented, and the plan is to only allow it to function when T: impl Display. This is due to some limitations in Rust's trait system which wouldn't allow for multiple impl definitions (Rust wouldn't know what to call for Add if T implemented both Display and Debug).

To support multiple colored strings while still being able to get their sources, a Vec of some sort would have to be kept internally to keep track of all the strings, and it looks like the heapless crate would provide for that need just fine for no_std environments.

hwittenborn avatar Jul 04 '23 04:07 hwittenborn

would this help with #115 ?

I am currently running into a similar issue to #115 and I believe this could be fixed by handling the whole text as a ColoredString

btw. thanks @hwittenborn for bringing this project back to life ❤️

ToBinio avatar Jul 05 '23 16:07 ToBinio

I personally think this would cause more problems. There's a good reason String doesn't implement Add: aside from ergonomics, it hides an allocation.

ClementNerma avatar Dec 02 '23 20:12 ClementNerma