Saturday, January 8, 2011

Text File Syntax Highlighter For Visual Studio 2010

I created an extension for Visual Studio 2010 to display .txt and .log file with colors. Based on a simple rule the line is displayed in full in a specific color.


The colors can be configured by editing a Python file named COLORS_DEFINITION.py. If the line contains the string defined in ColorDefinition or if the line matches the regular expression the color is selected. To get the regular expression to work you will need to install IronPython 2.6 for .NET 4.0. in the default folder (%PROGRAMFILES%\IronPython 2.6 for .NET 4.0).

The rules are evaluated from top to bottom, we stop at the first one that match. You can add as many rules as you want.

COLORS_DEFINITIONS =  { 
     "txt":  [  # Color definition for .txt file 
         ColorDefinition (  "[WARNING]"                ,"DarkGoldenrod"         ), 
         ColorDefinition (  ".*\\[ERROR\\].*Minor.*"   ,"Salmon"        ,  True ),         
         ColorDefinition (  ".*\\[ERROR\\].*"          ,"Red"           ,  True ), 
         ColorDefinition (  "[INFO]"                   ,"Blue"                  ), 
         ColorDefinition (  "[PASSED]"                 ,"Green"                 ), 
         ColorDefinition (  ""                         ,"Black"                 )  # The last item is the default color 
     ] 
 }

Download the extension at http://visualstudiogallery.msdn.microsoft.com/en-us/6706b602-6f10-4fd1-8e14-75840f855569

Once you ran the install, start Visual Studio 2010, click on the menu Tool Extension Manager, selection the extension and click Enable.
Restart Visual Studio 2010.

To change the colors edit the file

%userprofile%\Local Settings\Application Data\Microsoft\VisualStudio\10.0\Extensions\TextHighlighterExtension\COLORS_DEFINITION.py

with Visual Studio. Once done, restart Visual Studio.

To get PYTHON syntax highlighting see IronPython tools for Visual Studio.

No comments:

Post a Comment