klogg icon indicating copy to clipboard operation
klogg copied to clipboard

Support for ANSI color sequences

Open Shadow505 opened this issue 4 years ago • 8 comments

Hey there,

it would be awesome if there was an option to enable rendering on ANSI color sequences.

If a file contains such sequences, the corresponding sections become pretty much unreadable if the color sequences are being displayed in their raw form.

I have attached a demo file with ANSI color sequences and a screenshot of how it looks rendered (created via a text editor with ansi color support). The right part in the image is the same one as the left one but everything has been selected, so that black text is visible.

Best regards

Example text file with ANSI color sequences

Rendered ANSI color sequences:

ExampleRendered

Shadow505 avatar Jun 13 '21 16:06 Shadow505

That is an interesting feature. However, implementing this will require to "hide" parts of text (the color change sequences), which will break things like selection and scrolling. Looks like something similar could be achieved with current highlighters with additional option to continue the same highlight until new matching highlight rule is found.

variar avatar Jun 16 '21 11:06 variar

Hey,

I am not sure if this should be implemented via the current highlighters, if that would mean, that the color sequences are not being hidden. Because even if the color sequence is applied to the text after it, we would definitely have to hide the color sequence itself, otherwise it won't really solve the issue that the text becomes unreadable.

A more advanced example would be a colored stracktrace, that visually shows, well, the stack. If the color sequences are only applied but not removed, the result would still be unreadable.

I think, the best solution would be an option, such as, File -> "Render ANSI color sequences". After clicking on it, it would apply the color sequences and fully remove them from the rendered output. Then there should be no issues with scrolling, selecting, etc.. Then you can also easily copy the text. And depending on how in-depth you would go with this, maybe there could be an option in the right-click context menu, that allows you to copy the selected text with the original escape sequences for the selected part. That would obviously would mean that you would have to keep track of them, even after removing them from the document. But just copying the selected text in the default color (black) should be sufficient. The idea above is just an idea :)

A possible workaround might be to replace each part of the color sequence with an empty character after it has been applied. But that's something that would have to be tested. If this feature is something that you consider (I would be happy, if you do consider it), let me know if you need help with testing.

Shadow505 avatar Jun 16 '21 13:06 Shadow505

Supporting ANSI colors would be perfect, but in the meantime it would help to have an option to filter out any escape sequences right when loading a file.

pohlt avatar Jul 13 '21 14:07 pohlt

@pohlt thanks for the idea. I've added a check box in view settings to remove ansi color sequences from displayed text. However, at least for now enabling this feature will result in severe performance loss for regular expression search. Search performance will be at the level of klogg 20.12 release which is 2-3 times slower than current dev builds. Can be tested in 21.07.0.1093+

variar avatar Aug 11 '21 16:08 variar

Originally posted by @sysescool in https://github.com/nickbnf/glogg/issues/69#issuecomment-1512336462

the android log format is:"\033[38;5;196m Error Level \033[0m". this format log works well and shows red color in linux terminal. you can get it by adb logcat -v color

Shoud extend this feature to hide such cases

variar avatar Apr 21 '23 21:04 variar

Thanks to @nowhszh now more types of ANSI escape codes can be hidden

variar avatar Jul 06 '23 05:07 variar

I've implemented the display of colors in this feature, download it from here and experience it before merging it https://github.com/variar/klogg/actions/runs/5716685296?pr=655#artifacts

nowhszh avatar Aug 05 '23 11:08 nowhszh