示例#1
0
 public DirectOutputEntry(ColorTextBuilder textBuilder, int x, int y, DirectOutputMode directOutputMode)
 {
     TextBuilder      = textBuilder;
     X                = x;
     Y                = y;
     DirectOutputMode = directOutputMode;
 }
 public ColorTextBuilder PrependIf(bool condition, ColorTextBuilder builder)
 {
     if (condition)
     {
         Prepend(builder);
     }
     return(this);
 }
        /// <summary>
        /// Write directly at a given position of the screen
        /// </summary>
        /// <param name="textBuilder"></param>
        /// <param name="xPos"></param>
        /// <param name="yPos"></param>
        /// <param name="directOutputMode">The mode which indicates when the text should be cleared</param>
        public void WriteAt(ColorTextBuilder textBuilder, int xPos, int yPos, DirectOutputMode directOutputMode)
        {
            var left = Console.CursorLeft;
            var top  = Console.CursorTop;

            Console.SetCursorPosition(xPos, yPos);
            _historyLock.Wait();
            try
            {
                _directOutputEntries.Add(new DirectOutputEntry(textBuilder, xPos, yPos, directOutputMode));
            }
            finally
            {
                _historyLock.Release();
            }
            Console.SetCursorPosition(left, top);
            _hasLogUpdates = true;
        }
 /// <summary>
 /// Write using the default Figlet font
 /// </summary>
 /// <param name="text"></param>
 public void WriteAscii(ColorTextBuilder textBuilder) => WriteAscii(textBuilder.ToString());
 /// <summary>
 /// Write text
 /// </summary>
 /// <param name="textBuilder"></param>
 /// <param name="xPos"></param>
 /// <param name="yPos"></param>
 /// <param name="directOutputMode">The mode which indicates when the text should be cleared</param>
 public void Write(ColorTextBuilder textBuilder)
 {
     // not yet supported
 }
 public ColorTextBuilder Prepend(ColorTextBuilder builder)
 {
     TextFragments.InsertRange(0, builder.TextFragments);
     return(this);
 }
        /// <summary>
        /// Interlace two builders together on the Y axis
        /// </summary>
        /// <param name="builder2"></param>
        /// <param name="fixedColumnSpacing">Optional amount of spacing between lines on X axis</param>
        /// <param name="fixedColumnWidth">Optional width of fixed columns for the data being interlaced</param>
        /// <returns></returns>
        public ColorTextBuilder Interlace(ColorTextBuilder builder2, int fixedColumnSpacing = 0, int fixedColumnWidth = 0)
        {
            var interlacedBuilder = new ColorTextBuilder();

            var enumerator1 = TextFragments.GetEnumerator();
            var enumerator2 = builder2.TextFragments.GetEnumerator();

            var processedRightCount = 0;
            var currentLineWidth    = 0;

            while (enumerator1.MoveNext())
            {
                var line = enumerator1.Current;
                if (line.Text.Contains(Environment.NewLine))
                {
                    // move to the next builder
                    line.Text = line.Text.Replace(Environment.NewLine, string.Empty);
                    // add spaces to format content in a column if asked
                    if (fixedColumnWidth > 0 && line.Text.Length > fixedColumnWidth)
                    {
                        line.Text = line.Text.Substring(0, fixedColumnWidth);
                    }
                    if (fixedColumnWidth > 0 && (currentLineWidth + line.Text.Length) < fixedColumnWidth)
                    {
                        line.Text = line.Text + new string(' ', fixedColumnWidth - (currentLineWidth + line.Text.Length));
                    }
                    currentLineWidth = 0;
                    interlacedBuilder.TextFragments.Add(line);

                    // add spaces if we are requested to separate the blocks of text
                    if (fixedColumnSpacing > 0)
                    {
                        interlacedBuilder.TextFragments.Add(new ColoredTextFragment(new string(' ', fixedColumnSpacing), line.ForegroundColor, line.BackgroundColor));
                    }

                    // start printing the next builder
                    var hasRightSideLines = false;
                    while (enumerator2.MoveNext())
                    {
                        processedRightCount++;
                        hasRightSideLines = true;
                        var line2 = enumerator2.Current;
                        if (line2.Text.Contains(Environment.NewLine))
                        {
                            if (fixedColumnWidth > 0 && line2.Text.Length > fixedColumnWidth)
                            {
                                line2.Text = line2.Text.Substring(0, fixedColumnWidth) + Environment.NewLine;
                            }
                            interlacedBuilder.TextFragments.Add(line2);

                            // done with this line, move back to parent builder and start the next line
                            break;
                        }
                        else
                        {
                            interlacedBuilder.TextFragments.Add(line2);
                        }
                    }
                    // if we ran out of right side items, add a line break
                    if (!hasRightSideLines)
                    {
                        interlacedBuilder.TextFragments.Add(new ColoredTextFragment(Environment.NewLine));
                    }
                }
                else
                {
                    interlacedBuilder.TextFragments.Add(line);
                    currentLineWidth += line.Text.Length;
                }
            }

            // extra right side data
            if (processedRightCount < builder2.TextFragments.Count)
            {
                var startOfLine = true;
                while (enumerator2.MoveNext())
                {
                    var line2 = enumerator2.Current;
                    if (startOfLine)
                    {
                        var leftPadding = new string(' ', fixedColumnWidth + fixedColumnSpacing);
                        interlacedBuilder.TextFragments.Add(new ColoredTextFragment(leftPadding));
                    }
                    if (line2.Text.Contains(Environment.NewLine))
                    {
                        if (fixedColumnWidth > 0 && line2.Text.Length - Environment.NewLine.Length > fixedColumnWidth)
                        {
                            line2.Text = line2.Text.Replace(Environment.NewLine, string.Empty)
                                         .Substring(0, fixedColumnWidth)
                                         + Environment.NewLine;
                        }
                        interlacedBuilder.TextFragments.Add(line2);
                        startOfLine = true;
                        // done with this line, move back to parent builder and start the next line
                        continue;
                    }
                    else
                    {
                        interlacedBuilder.TextFragments.Add(line2);
                    }
                    startOfLine = false;
                }
            }

            return(interlacedBuilder);
        }
 public ColorTextBuilder AppendLine(ColorTextBuilder builder)
 {
     TextFragments.AddRange(builder.TextFragments);
     TextFragments.Add(new ColoredTextFragment(Environment.NewLine));
     return(this);
 }
 public ColorTextBuilder Append(ColorTextBuilder builder)
 {
     TextFragments.AddRange(builder.TextFragments);
     return(this);
 }
示例#10
0
 public ColorTextBuilder PrependLine(ColorTextBuilder builder)
 {
     TextFragments.Insert(0, new ColoredTextFragment(Environment.NewLine));
     TextFragments.InsertRange(0, builder.TextFragments);
     return(this);
 }