private static void WriteInColor<T>(Action<T> action, T target, Color color)
 {
     
     VirtualTerminalConsole.SetForegroundColor(color);
     action.Invoke(target);
     VirtualTerminalConsole.RestoreForeground();
 }
        private static void MapToScreen(StyledString styledString, string trailer)
        {
            
            int rowLength = styledString.CharacterGeometry.GetLength(0);
            int columnLength = styledString.CharacterGeometry.GetLength(1);
            for (int row = 0; row < rowLength; row++)
            {
                for (int column = 0; column < columnLength; column++)
                {
                    VirtualTerminalConsole.SetForegroundColor(styledString.ColorGeometry[row, column]);

                    if (row == rowLength - 1 && column == columnLength - 1)
                    {
                        System.Console.Write(styledString.CharacterGeometry[row, column] + trailer);
                    }
                    else if (column == columnLength - 1)
                    {
                        System.Console.Write(styledString.CharacterGeometry[row, column] + "\r\n");
                    }
                    else
                    {
                        System.Console.Write(styledString.CharacterGeometry[row, column]);
                    }
                }
            }

            VirtualTerminalConsole.RestoreForeground();
        }
        private static void MapToScreen(IEnumerable<KeyValuePair<string, Color>> styleMap, string trailer)
        {
#if !NET40
            Queue.Enqueue(() => Task.Factory.StartNew(() =>
            {
#endif
                
                int writeCount = 1;
                foreach (KeyValuePair<string, Color> textChunk in styleMap)
                {
                    VirtualTerminalConsole.SetForegroundColor(textChunk.Value);

                    if (writeCount == styleMap.Count())
                    {
                        System.Console.Write(textChunk.Key + trailer);
                    }
                    else
                    {
                        System.Console.Write(textChunk.Key);
                    }

                    writeCount++;
                }

                VirtualTerminalConsole.RestoreForeground();
#if !NET40
            })).Wait();
#endif
        }
 private static void WriteInColor<T, U>(Action<T, U, U, U> action, T target0, U target1, U target2, U target3, Color color)
 {
     
     VirtualTerminalConsole.SetForegroundColor(color);
     action.Invoke(target0, target1, target2, target3);
     VirtualTerminalConsole.RestoreForeground();
 }
        private static void WriteInColorAlternating<T>(Action<T> action, T target, ColorAlternator alternator)
        {
            Color color = alternator.GetNextColor(target.AsString());

            
            VirtualTerminalConsole.SetForegroundColor(color);
            action.Invoke(target);
            VirtualTerminalConsole.RestoreForeground();
        }
        private static void WriteInColorAlternating<T, U>(Action<T, U, U, U> action, T target0, U target1, U target2, U target3, ColorAlternator alternator)
        {
            string formatted = string.Format(target0.ToString(), target1, target2, target3);
            Color color = alternator.GetNextColor(formatted);

            
            VirtualTerminalConsole.SetForegroundColor(color);
            action.Invoke(target0, target1, target2, target3);
            VirtualTerminalConsole.RestoreForeground();
        }