Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add contents_formatted to InMemoryTerm #531

Merged
merged 1 commit into from May 26, 2023

Conversation

dfaust
Copy link
Contributor

@dfaust dfaust commented Apr 16, 2023

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

image

@djc
Copy link
Collaborator

djc commented Apr 16, 2023

Why do you need this?

@dfaust
Copy link
Contributor Author

dfaust commented Apr 16, 2023

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

@dfaust dfaust force-pushed the contents-formatted branch 2 times, most recently from e0a42eb to 9c6fdaf Compare April 16, 2023 14:36
Copy link
Collaborator

@djc djc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for being so slow to follow up. Adding this API seems reasonable, though I'd prefer to add it in a way that doesn't duplicate as much code. How about we move most of the logic into a new InMemoryTermState::contents() method which can take a formatted: bool argument?

@dfaust
Copy link
Contributor Author

dfaust commented May 23, 2023

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 djc merged commit 9deb9eb into console-rs:main May 26, 2023
9 checks passed
@djc
Copy link
Collaborator

djc commented May 26, 2023

Okay, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants