Exemplo n.º 1
0
        private static void MapToScreen(StyledString styledString, string trailer)
        {
            ConsoleColor 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 = Console.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;
        }
Exemplo n.º 2
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...?

            Console.PopulateColorGeometry(annotationMap, target);

            Console.MapToScreen(target, trailer);
        }
Exemplo n.º 3
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 = Figlet.GetStringWidth(this.font, value);

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

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

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

                    stringBuilder.Append(fragment);
                    Figlet.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);
        }
Exemplo n.º 4
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++;
                }
            }
        }
Exemplo n.º 5
0
 public static void WriteLineStyled(StyledString value, StyleSheet styleSheet)
 {
     Console.WriteAsciiInColorStyled(Console.WRITELINE_TRAILER, value, styleSheet);
 }