colorful Console writing

Posts 1–6 of 6 · Page 1 of 1
colorful Console writing
Code:
    class Write
    {
        public static void Color(String value)
        {
            String _String = String.Empty;
            ConsoleColor _Color = ConsoleColor.White;

            for (int i = 0; i < value.Length; i++)
            {
                if (value[i] == '<' && value[i + 2] == '>')
                {
                    if (_String != String.Empty)
                    {
                        Console.ForegroundColor = _Color;
                        Console.Write(_String);

                        _String = String.Empty;
                    }
                    _Color = getColor(value[i + 1]);
                    i += 2;
                    continue;
                }
                else if (value[i] == '~')
                {

                    _String += "\n";
                    continue;
                }
                _String += value[i];
            }

            if (_String != String.Empty)
            {
                Console.ForegroundColor = _Color;
                Console.Write(_String);
            }
        }

        static ConsoleColor getColor(char input)
        {
            switch (input)
            {

                case 'A': return ConsoleColor.Gray;
                case 'B': return ConsoleColor.DarkGray;
                case 'C': return ConsoleColor.Cyan;
                case 'D': return ConsoleColor.DarkCyan;
                case 'E': return ConsoleColor.DarkGreen;
                case 'F': return ConsoleColor.Green;
                case 'G': return ConsoleColor.Yellow;
                case 'H': return ConsoleColor.DarkYellow;
                case 'I': return ConsoleColor.Magenta;
                case 'J': return ConsoleColor.DarkMagenta;
                case 'K': return ConsoleColor.Black;
                case 'L': return ConsoleColor.Blue;
                case 'M': return ConsoleColor.DarkBlue;
                case 'N': return ConsoleColor.Red;
                case 'O': return ConsoleColor.DarkRed;
                case 'P': return ConsoleColor.White;

            }
            return ConsoleColor.White;
        }

    }

Sample:
Code:
Write.Color("<J>This <N>is <L>a <A>R<B>a<C>i<D>n<E>b<F>o<G>w~<P>This is a new line <C>:<I>)");
Quote Originally Posted by 0x01337 View Post
Code:
    class Write
    {
        public static void Color(String value)
        {
            String _String = String.Empty;
            ConsoleColor _Color = ConsoleColor.White;

            for (int i = 0; i < value.Length; i++)
            {
                if (value[i] == '<' && value[i + 2] == '>')
                {
                    if (_String != String.Empty)
                    {
                        Console.ForegroundColor = _Color;
                        Console.Write(_String);

                        _String = String.Empty;
                    }
                    _Color = getColor(value[i + 1]);
                    i += 2;
                    continue;
                }
                else if (value[i] == '~')
                {

                    _String += "\n";
                    continue;
                }
                _String += value[i];
            }

            if (_String != String.Empty)
            {
                Console.ForegroundColor = _Color;
                Console.Write(_String);
            }
        }

        static ConsoleColor getColor(char input)
        {
            switch (input)
            {

                case 'A': return ConsoleColor.Gray;
                case 'B': return ConsoleColor.DarkGray;
                case 'C': return ConsoleColor.Cyan;
                case 'D': return ConsoleColor.DarkCyan;
                case 'E': return ConsoleColor.DarkGreen;
                case 'F': return ConsoleColor.Green;
                case 'G': return ConsoleColor.Yellow;
                case 'H': return ConsoleColor.DarkYellow;
                case 'I': return ConsoleColor.Magenta;
                case 'J': return ConsoleColor.DarkMagenta;
                case 'K': return ConsoleColor.Black;
                case 'L': return ConsoleColor.Blue;
                case 'M': return ConsoleColor.DarkBlue;
                case 'N': return ConsoleColor.Red;
                case 'O': return ConsoleColor.DarkRed;
                case 'P': return ConsoleColor.White;

            }
            return ConsoleColor.White;
        }

    }

Sample:
Code:
Write.Color("<J>This <N>is <L>a <A>R<B>a<C>i<D>n<E>b<F>o<G>w~<P>This is a new line <C>:<I>)");
What is the point...
Using letters that is not related to the color :S
Try to use some other kind of key-binds.

Also, we have a thread for what you are doing: http://www.mpgh.net/forum/250-c-prog...s-vault-c.html
Post there instead?
Hmm, i like this idea, thansk
Quote Originally Posted by Paul View Post
Hmm, i like this idea, thansk
No problem
Its easier to work with colors an make a colorful consolescreen.

btw.

If someone will change this <A> to this |A| than he must edit this:
Code:
if (value[i] == '<' && value[i + 2] == '>')
Quote Originally Posted by Jorndel View Post
What is the point...
Using letters that is not related to the color :S
Try to use some other kind of key-binds.

Also, we have a thread for what you are doing: http://www.mpgh.net/forum/250-c-prog...s-vault-c.html
Post there instead?
That isn't really a snippet, its a whole class .
The letters for the colors can you edit in what you want, i only wrote them random.
Quote Originally Posted by 0x01337 View Post
No problem
Its easier to work with colors an make a colorful consolescreen.

btw.

If someone will change this <A> to this |A| than he must edit this:
Code:
if (value[i] == '<' && value[i + 2] == '>')


That isn't really a snippet, its a whole class .
The letters for the colors can you edit in what you want, i only wrote them random.
In my eyes.
Snippet

It's small, and have a very small function it performs.
Very easy to do.

Its also a little pointless to me.

But good job I guess
Posts 1–6 of 6 · Page 1 of 1

Post a Reply

Similar Threads

Talk with us