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

Ignore ANSI terminal escape sequences in length calculations #21

Closed
tarleb opened this issue Dec 30, 2022 · 4 comments
Closed

Ignore ANSI terminal escape sequences in length calculations #21

tarleb opened this issue Dec 30, 2022 · 4 comments

Comments

@tarleb
Copy link

tarleb commented Dec 30, 2022

Ignoring ANSI escape sequences would allow to layout marked up text in the terminal. Escape sequences for text markup all follow the pattern \ESC[([0-9;]*m.

Initial discussion: hslua/hslua-module-doclayout#2

@jgm
Copy link
Owner

jgm commented Dec 30, 2022

@Xitian9 - you wrote the fairly complex code for computing real lengths. How hard would it be to have it ignore ANSI escape sequences? I think that for the majority of widely used ones it would suffice to start the match on 'ESC [' and end on any ascii letter.

@Xitian9
Copy link
Contributor

Xitian9 commented Dec 31, 2022

This is an issue I'm fairly familiar with, as we've tried different ways of dealing with it in hledger. Dealing with malformed ANSI escape sequences is what makes this especially tricky.

I currently think that the best approach is to not keep your ANSI markup in the string itself, but keep it separated in a data type and only stick it all together after you're done with any need to measure its length. See for example here: https://github.com/muesli4/table-layout/blob/master/src/Text/Layout/Table/Cell/Formatted.hs. You might be interested in using the Cell typeclass from the table-layout library.

@silby
Copy link
Contributor

silby commented Mar 7, 2024

I believe this can be closed as of #25 and #26.

@jgm jgm closed this as completed Mar 7, 2024
@tarleb
Copy link
Author

tarleb commented Mar 7, 2024

Impressive work, @silby. Thank you!

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

No branches or pull requests

4 participants