Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
719 views
in Technique[技术] by (71.8m points)

Can I display a file with ANSI color escape sequences in Visual Studio Code?

I have a process that writes a log file which includes ANSI color codes. When I view the file on the terminal with cat, the colors are rendered correctly. When I view it with less, by default I see codes like ESC[32m but I can use the -F switch to see the colors (e.g. less -F log.txt).

I would like to be able to view and even possibly edit the file in VSCode, with the colors displayed correctly. How can I do this?

question from:https://stackoverflow.com/questions/48339982/can-i-display-a-file-with-ansi-color-escape-sequences-in-visual-studio-code

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The ANSI Colors extension exists since 2020/10/13:

enter image description here

After installing, the easiest way to use it is to:

  1. Install the ANSI Colors extension.
  2. Open your ANSI file.
  3. Use their custom commands to open the ANSI color preview, just like in this screenshot: enter image description here
    • Press F1 or CTRL/Command + SHIFT + P (to open the VSCode command interface).
    • Type "ansi" or "preview" to find the commands.
    • Select with Up/Down arrow keys.
    • Finally, hit enter.

As you can see, the command interface also shows you the direct keyboard shortcuts, that saves you all that typing.

More usage and configuration options are explained on the extension page.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...