Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

xConsole Project

0.00/5 (No votes)
23 May 2014 1  
Coloring the window console

Introduction

Hi, it`s my project called xConsole, in few words this DLL gives you the ability to color, animate comfortably the console window, parse input, modify fonts and more.

It has been written in C# .NET 4.5.

Using the Library

  1. Add Reference > xConsole.dll
  2. using xConsoleProject;

Example of coloring:

xConsole.WriteLine("^yLorem ipsum dolor sit amet^r, consectetur adipiscing elit. " + 
     "^.Nullam porttitor lectus justo, vel viverra est pellentesque non.^!"); 

^y Set Yellow Color
^r Set Red Color
^. Set a Random Color (different from the background)
^! Restore default font color

*y *r *m Sets Colors
*. Random background Color
*! Restore default bg.

xConsole.CoolWriteLine("I like write like a boss.");
 
// OR

xConsole.CoolWriting = true;
xConsole.WriteLine("^600I like write ^F00like a boss"); // Or 6 digits (^FF00FF)..
xConsole.WriteLine("Yes ^ycolors is ^msupported^!");
xConsole.CoolWriting = false;

[Updated] List of Colors

Using enum (now same of Microsoft):

public enum ConsoleColor
{
    Black = 0,
    DarkBlue = 1,
    DarkGreen = 2,
    DarkCyan = 3,
    DarkRed = 4,
    DarkMagenta = 5,
    DarkYellow = 6,
    Gray = 7,
    DarkGray = 8,
    Blue = 9,
    Green = 10,
    Cyan = 11,
    Red = 12,
    Magenta = 13,
    Yellow = 14,
    White = 15,
} 

HEX to ConsoleColor (the HEX code must be uppercase):

xConsole.WriteLine("^600I like to paint ^F00like a boss");

With letters:

xConsole.WriteLine("^yI like to paint ^rlike a boss");
w:    White
z:    Black
y:    Yellow
g:    Green
r:    Red
b:    Blue
c:    Cyan
m:    Magenta

Read Line

 var args = xConsole.ReadLine();

Will give back a List<string> (never null) contains the arguments parsed, entered by the user, Like:

Hi "this is a string" then 9999

[0] = Hi
[1] = This is a string
[2] = then
[3] = 9999

An empty input: (list size 1, value empty string)

[0] =

So you need to check if its string is Empty. Yeah, i don't like null values..

Spinner

This class allows you to create an animated spinner.

var spinner = new xConsole.Spinner();
                
new Thread(delegate()
{
    //Spin until user interruption
    Console.ReadKey(true);

    spinner.Break();
    xConsole.Write("^11OK!^!");
}).Start();

xConsole.Write("^2STATUS: ^7"); 
// Waiting the thread is done.
while (spinner.Turn());

Move window

SetWindowPos(int x, int y); 

Other

I also added console helper.

xConsole.SetFont(int);  

Set font, list font, change icon...

Next Update

  • Sound management?

History

23/05/2014
  • Now check updates every 30 days (only in debug)
  • No more create registry key in release
  • Removed Stats sending
  • Removed Settings
  • Fixed ClearColorsAtEnd function (restoring previous colors)
  • Added Test program (Both sources)
21/01/2014
  • Released source code (v 0.3)
  • It's not a spywere see above
18/01/2014
  • [NEW] Optional separate-thread writer (default ON)
  • [NEW] Random color always != from background
  • [NEW] Background colors using * tag
  • [NEW] Update Checking (only in debug)
  • [NEW] New Functions like WaitQueue (main program wait until the queue is resolved)
  • [UPDATED] Fixed a bug in the spinning
  • [UPDATED] Spinning now supports colors
  • [???] A lot of emoji in the code
  • [Source Code] will be available, I need to make it beautiful, btw you can reflect it
  • [It would] be nice to do a port to C++
27/07/2013
  • Improved method of color selection
    Now you can use ^RBG colors (3bytes), like ^F00 = red
    ^00F = Blue, ^0F0 = green, ^600 = darkred ...etc... (RBG colors is rounded to ConsoleColors)
    and ^y = yellow
    ^r = red
    ^m = magenta .. etc
  • Random color moved to ^.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here