private void PrintSegment(TextSegment segment)
        {
            if (!Hidden)
            {
                Console.ForegroundColor = segment.ForegroundColor;
                Console.BackgroundColor = segment.BackgroundColor;
                Console.SetCursorPosition(Left + CursorLeft, Top + CursorTop);
                Console.Write(segment.Text);
            }

            CursorLeft += segment.Text.Length;

            if (CursorLeft >= Width)
            {
                CursorLeft = 0;
                CursorTop++;

                if (CursorTop >= Height)
                    ShiftLine();
            }
        }
 private void AppendSegment(TextSegment segment)
 {
     lock (Container)
     lock (this)
     {
         PrintSegment(segment);
         _buffer[CursorTop].Add(segment);
     }
 }
        private void PrintSegment(TextSegment segment, ref int cursorLeft, ref int cursorTop)
        {
            if (!Hidden)
            {
                Console.ForegroundColor = segment.ForegroundColor;
                Console.BackgroundColor = segment.BackgroundColor;
                Console.SetCursorPosition(Left + cursorLeft, Top + cursorTop);
                Console.Write(segment.Text);
            }

            cursorLeft += segment.Text.Length;

            if (cursorLeft >= Width)
            {
                cursorLeft = 0;
                cursorTop++;
            }
        }
        public void Write(string text)
        {
            lock (this)
            {
                int segmentLength = Width - CursorLeft;
                TextSegment segment;

                lock (Container)
                {
                    while (segmentLength < text.Length)
                    {
                        segment = new TextSegment
                            {
                                ForegroundColor = ForegroundColor,
                                BackgroundColor = BackgroundColor,
                                Text = text.Substring(0, segmentLength)
                            };
                        AppendSegment(segment);

                        text = text.Substring(segmentLength);
                        segmentLength = Width;
                    }
                    segment = new TextSegment
                        { ForegroundColor = ForegroundColor, BackgroundColor = BackgroundColor, Text = text };
                    AppendSegment(segment);
                }
                Container.PositionCursor();
            }
        }