コード例 #1
0
        private static void MapToScreen(StyledString styledString, string trailer)
        {
            var oldSystemColor = System.Console.ForegroundColor;
            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++)
                {
                    System.Console.ForegroundColor = colorManager.GetConsoleColor(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]);
                    }
                }
            }

            System.Console.ForegroundColor = oldSystemColor;
        }
コード例 #2
0
        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();
        }
コード例 #3
0
        private static void WriteAsciiInColorStyled(string trailer, StyledString target, StyleSheet styleSheet)
        {
            TextAnnotator annotator = new TextAnnotator(styleSheet);
            List<KeyValuePair<string, Color>> annotationMap = annotator.GetAnnotationMap(target.AbstractValue); // Should eventually be target.AsStyledString() everywhere...?

            PopulateColorGeometry(annotationMap, target);

            MapToScreen(target, trailer);
        }
コード例 #4
0
        public StyledString ToAscii(string value)
        {
            if (value == null)
            {
                throw new ArgumentNullException(nameof(value));
            }

            if (Encoding.UTF8.GetByteCount(value) != value.Length)
            {
                throw new ArgumentException("String contains non-ascii characters");
            }

            StringBuilder stringBuilder = new StringBuilder();

            int stringWidth = GetStringWidth(font, value);

            char[,] characterGeometry     = new char[font.Height + 1, stringWidth];
            int[,] characterIndexGeometry = new int[font.Height + 1, stringWidth];
            Color[,] colorGeometry        = new Color[font.Height + 1, stringWidth];

            for (int line = 1; line <= font.Height; line++)
            {
                int runningWidthTotal = 0;

                for (int c = 0; c < value.Length; c++)
                {
                    char   character = value[c];
                    string fragment  = GetCharacter(font, character, line);

                    stringBuilder.Append(fragment);
                    CalculateCharacterGeometries(fragment, c, runningWidthTotal, line, characterGeometry, characterIndexGeometry);

                    runningWidthTotal += fragment.Length;
                }

                stringBuilder.AppendLine();
            }

            StyledString styledString =
                new StyledString(value, stringBuilder.ToString())
            {
                CharacterGeometry      = characterGeometry,
                CharacterIndexGeometry = characterIndexGeometry,
                ColorGeometry          = colorGeometry
            };

            return(styledString);
        }
コード例 #5
0
        private static void PopulateColorGeometry(IEnumerable<KeyValuePair<string, Color>> annotationMap, StyledString target)
        {
            int abstractCharCount = 0;
            foreach (KeyValuePair<string, Color> fragment in annotationMap)
            {
                for (int i = 0; i < fragment.Key.Length; i++)
                {
                    // This will run O(n^2) times...but with DP, could be O(n).
                    // Just need to keep a third array that keeps track of each abstract char's width, so you never iterate past that.
                    // This third array would be one-dimensional.

                    int rowLength = target.CharacterIndexGeometry.GetLength(0);
                    int columnLength = target.CharacterIndexGeometry.GetLength(1);
                    for (int row = 0; row < rowLength; row++)
                    {
                        for (int column = 0; column < columnLength; column++)
                        {
                            if (target.CharacterIndexGeometry[row, column] == abstractCharCount)
                            {
                                target.ColorGeometry[row, column] = fragment.Value;
                            }
                        }
                    }

                    abstractCharCount++;
                }
            }
        }
コード例 #6
0
ファイル: ColorfulConsoleFront.cs プロジェクト: backlion/xdec
 public static void WriteLineStyled(StyledString value, StyleSheet styleSheet)
 {
     WriteAsciiInColorStyled(WRITELINE_TRAILER, value, styleSheet);
 }