console-rs / indicatif

A command line progress reporting library for Rust
MIT License
4.22k stars 238 forks source link

Add `contents_formatted` to `InMemoryTerm` #531

Closed dfaust closed 1 year ago

dfaust commented 1 year ago

This method is almost identical to contents, but it includes VT-100 codes.

image

djc commented 1 year ago

Why do you need this?

dfaust commented 1 year ago

For testing. This allows seeing the colored output directly in the tests.

dfaust commented 1 year ago

I just pushed an updated version, which adds a reset code at the end of each line. This is necessary because rows_formatted returns each line in an "undefined state".

Yes, there is some code duplication, the problem is, that contents returns a String, while contents_formatted returns a Vec. And this starts basically with the first call, since rows returns a String and rows_formatted returns a Vec.

One way would be for the contents method to turn the strings into vecs, process them and at the end turn the result vec back into a string.

djc commented 1 year ago

Okay, thanks!