Monday, April 29, 2024
8
rated 0 times [  8] [ 0]  / answers: 1 / hits: 14287  / 2 Years ago, wed, september 7, 2022, 6:45:06

Here's what I'm doing: I'm echoing through Php colors like this:



shell colors



php creates output containing ANSI escape sequences that color text when it is displayed through the shell on my terminal. You can find the php class and explanation here.



But if I send my output to a file, and try to read it with vim it's not "colored", I just can see the special characters. Is there a way to display the colors like they are displayed in the shell?


More From » command-line

 Answers
7

The terminal output will be colored if the content of the file will be sent "as-is" to the terminal, without any modifications. However, vim and some other editors will escape meta characters in the text and instead maybe add some other color codes for their syntax highlighting, so this doesn't work.



Try dumping the file to the terminal with cat, this should work. Some simple editors or pagers like less might also work.



Edit:
I have not found a way to let vim "pass-through" all the escape codes, but I have found this answer which links to this vim script, which parses the escape codes and uses the vim syntax highlighting to recreate the color codes in the output. According to its description, it should do exactly what you want (but I have not tested it).


[#36360] Wednesday, September 7, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
darpose

Total Points: 424
Total Questions: 99
Total Answers: 121

Location: Jersey
Member since Fri, Oct 1, 2021
3 Years ago
darpose questions
Sun, Jan 23, 22, 04:32, 2 Years ago
Tue, Apr 25, 23, 23:44, 1 Year ago
Wed, Dec 15, 21, 14:42, 2 Years ago
Wed, Jun 2, 21, 23:41, 3 Years ago
;