private 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++)
                {
                    Console.ForegroundColor = colorManager.GetConsoleColor(styledString.ColorGeometry[row, column]);

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

            Console.ResetColor();
        }
        private 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);
        }
示例#3
0
        public StyledString ToAscii(string value)
        {
            if (value == null)
            {
                throw new ArgumentNullException(nameof(value));
            }

            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());

            styledString.CharacterGeometry      = characterGeometry;
            styledString.CharacterIndexGeometry = characterIndexGeometry;
            styledString.ColorGeometry          = colorGeometry;

            return(styledString);
        }
示例#4
0
 public void WriteLineStyled(StyledString value, StyleSheet styleSheet)
 {
     WriteAsciiInColorStyled(WRITELINE_TRAILER, value, styleSheet);
 }
        private 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++;
                }
            }
        }