コード例 #1
0
        /// <summary>
        /// Appends a single line to the scrollback buffer.
        /// </summary>
        /// <param name="screenLine">The line to append.</param>
        public void Append(ScreenLine screenLine)
        {
            List <ScreenLine> currentPartition = this.partitions[0];

            currentPartition.Add(screenLine);

            if (currentPartition.Count >= currentPartition.Capacity)
            {
                if ((this.partitions.Count - 1) * PartitionSize >= this.maximumCount)
                {
                    var oldPartition = this.partitions[this.partitions.Count - 1];
                    this.partitions.RemoveAt(this.partitions.Count - 1);
                    foreach (var line in oldPartition)
                    {
                        ScreenCell.RecycleCells(line);
                    }
                }

                this.partitions.Insert(0, new List <ScreenLine>(PartitionSize));
            }
        }
コード例 #2
0
            /// <summary>
            /// Resizes the specified screen buffer to the specified size.
            /// </summary>
            /// <param name="rows">The new amount of rows.</param>
            /// <param name="columns">The new amount of columns.</param>
            private void Resize(List <ScreenLine> buffer, int rows, int columns)
            {
                while (buffer.Count > rows)
                {
                    if (this.CursorRow < buffer.Count - 1)
                    {
                        buffer.RemoveAt(buffer.Count - 1);
                    }
                    else
                    {
                        this.CursorRow--;
                        buffer.RemoveAt(0);
                    }
                }

                while (buffer.Count < rows)
                {
                    buffer.Add(new ScreenLine(columns));
                }

                foreach (var line in buffer)
                {
                    if (line.Count > columns)
                    {
                        var cells = line.GetRange(line.Count - (line.Count - columns), line.Count - columns);
                        line.RemoveRange(line.Count - (line.Count - columns), line.Count - columns);
                        ScreenCell.RecycleCells(cells);
                    }
                    else if (line.Count < columns)
                    {
                        line.AddRange(ScreenCell.GetFreshCells(columns - line.Count));
                    }
                }

                this.CursorRow    = Math.Min(this.CursorRow, rows - 1);
                this.CursorColumn = Math.Min(this.CursorColumn, columns - 1);

                this.changed = true;
            }