Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to view terminal color codes as colors in Sublime Text

I have some log files that use color schemes. I would like to be able to view those logs in Sublime Text and still see the colors. Currently when I view the log file I see things like this:

2013-11-20T15:53:02.711Z - [34minfo[39m: Default profiles created 2013-11-20T15:53:02.712Z - [34minfo[39m: Finished server initialization 2013-11-20T15:53:02.712Z - [34minfo[39m: Start collecting garbage 

The text between [34m and [39m is colored. Is anyone aware of a plugin that does this?

like image 599
Thijs Koerselman Avatar asked Dec 04 '13 14:12

Thijs Koerselman


People also ask

Why is my Sublime Text white?

This happens when Sublime Text doesn't know which syntax highlighting to choose. First of all Sublime Text guesses the syntax from the file extension. E.g. if you have a file named my_file_name. php Sublime Text assumes that the PHP syntax highlighting is the best.


2 Answers

Install the SublimeANSI plugin and change the syntax of your log file to ANSI (using the View -> Syntax menu.)

Also available as ANSIescape on Package Control.

like image 70
keheliya Avatar answered Nov 02 '22 09:11

keheliya


@keheliya's answer is correct...but how to install said package?

Install ANSIescape package:

  1. Ctrl + Shift + P --> type "install", select "Package Control: Install Package" --> wait a few seconds, and a new search bar will pop up.
  2. In the new search bar --> search for "ANSIescape" and select it.
  3. Watch the status bar in the very bottom to see when it's done installing. It should just take a few seconds. Done!

Now, to use it, click the current syntax highlighting text in the very bottom right of your Sublime Text 3 window. Choose "ANSI", as shown below.

You may also choose this from the menus: View --> Syntax --> ANSI.

enter image description here

Alternative, command-line option

Instead of Sublime Text 3, you can also try less -r filename and less -R filename, but if your file has mixed color codes it may be easier to look at in Sublime Text 3 anyway. My favorite less command options are -RFX, which produce the effect seen in git diff (and also seen in my thin wrapper program I wrote to show line numbers in git diff: git diffn). For example:

less -RFX filename 

Description:

  • -R to interpret ANSI color codes
  • -F to quit immediately if the output takes up less than one-screen, and:
  • -X to not clear the screen when less exits!

See:

  1. How do I prevent 'git diff' from using a pager?
  2. https://unix.stackexchange.com/questions/38634/is-there-any-way-to-exit-less-without-clearing-the-screen/38638#38638

Other, useful Sublime Text plugins I like:

  1. "Emmet" plugin to find matching HTML tags: Find closing HTML tag in Sublime Text
like image 42
Gabriel Staples Avatar answered Nov 02 '22 10:11

Gabriel Staples