Eugene's profileEugene's spaceBlogLists Tools Help

Blog


June 11

Windows console colorizer

If you are programmer and building you code in console using .bat or.cmd batch files, you might be tired of that gray-on-black symbols mess. This simple app will help you to colorize the building process:

(C#)

using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
 
namespace Colorize
{
    class Program
    {
        static int Main(string[] args)
        {
            TextReader tIn = Console.In;
            TextWriter tOut = Console.Out;
            ConsoleColor defautColor = Console.ForegroundColor;
 
            if (args.Length == 0)
            {
                Console.ForegroundColor = ConsoleColor.Green;
 
                tOut.WriteLine("Invalid command line parameter.");
                tOut.WriteLine("Available parameters:");
 
                foreach (String c in Enum.GetNames(typeof(ConsoleColor)))
                {
                    tOut.WriteLine("    " + c);
                }
 
                Console.ForegroundColor = defautColor;
 
                return 0;
            }
 
            try
            {
                ConsoleColor color = (ConsoleColor) Enum.Parse(typeof(ConsoleColor), args[0], true);
                Console.ForegroundColor = color;
            }
            catch (Exception ex)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                tOut.WriteLine(ex.Message);
                tOut.WriteLine(ex.StackTrace);
                Console.ForegroundColor = defautColor;
                return 2;
            }
 
            return 0;
        }
    }
}

Compiled exe: colorize.zip

How to use

Sample .bat file:

@echo off

colorize White
echo WHITE TEXT
echo.
colorize Yellow
echo YELLOW TEXT
echo.
colorize Magenta
echo MAGENTA TEXT
echo.

pause

Result:
 

Capture

Comments

Please wait...
Sorry, the comment you entered is too long. Please shorten it.
You didn't enter anything. Please try again.
Sorry, we can't add your comment right now. Please try again later.
To add a comment, you need permission from your parent. Ask for permission
Your parent has turned off comments.
Sorry, we can't delete your comment right now. Please try again later.
You've exceeded the maximum number of comments that can be left in one day. Please try again in 24 hours.
Your account has had the ability to leave comments disabled because our systems indicate that you may be spamming other users. If you believe that your account has been disabled in error please contact Windows Live support.
Complete the security check below to finish leaving your comment.
The characters you type in the security check must match the characters in the picture or audio.

To add a comment, sign in with your Windows Live ID (if you use Hotmail, Messenger, or Xbox LIVE, you have a Windows Live ID). Sign in


Don't have a Windows Live ID? Sign up

Trackbacks

The trackback URL for this entry is:
http://loomp.spaces.live.com/blog/cns!2E30A3EADAC5DD8!409.trak
Weblogs that reference this entry
  • None