Пример #1
0
        public void Resize(int cols, int rows)
        {
            Size = new Point(cols, rows);

            int oldRowCount = lines.Length;
            if (rows != oldRowCount)
            {
                var newLines = new TerminalLine[rows];
                if (rows > oldRowCount)
                {
                    Array.Copy(lines, 0, newLines, 0, oldRowCount);
                    for (int i = oldRowCount; i < rows; ++i)
                        newLines[i] = new TerminalLine();
                }
                else if (rows < oldRowCount)
                {
                    int startIndex = 0;
                    int remainingRows = cursorRow - rows + 1;
                    if (remainingRows > 0)
                        startIndex = remainingRows;
                    Array.Copy(lines, startIndex, newLines, 0, rows);
                }

                lines = newLines;
            }

            foreach (var line in lines)
            {
                line.ColCount = cols;
            }

            CursorRow = CursorRow;
        }
Пример #2
0
        void advanceCursorRow()
        {
            cursorRow++;

            if (cursorRow == Size.Row)
            {
                var oldLine = lines[0];
                var newLine = new TerminalLine();
                cursorRow--;
                Array.Copy(lines, 1, lines, 0, lines.Length - 1);
                lines[lines.Length - 1] = newLine;

                LinesMoved?.Invoke(this, new LinesMovedEventArgs(1, 0, Size.Row - 1));
            }
        }
Пример #3
0
		public void DeleteCharactersTest()
		{
			TerminalLine line = new TerminalLine();
			line.SetCharacters(0, new string('0', 4), new TerminalFont() { Foreground = Color.FromRgb(0, 0, 0) });
			line.SetCharacters(4, new string('1', 4), new TerminalFont() { Foreground = Color.FromRgb(1, 1, 1) });
			line.SetCharacters(8, new string('2', 4), new TerminalFont() { Foreground = Color.FromRgb(2, 2, 2) });
			line.SetCharacters(12, new string('3', 4), new TerminalFont() { Foreground = Color.FromRgb(3, 3, 3) });
			line.DeleteCharacters(7, 6);

			TerminalRun[] expectedRuns = new[]
			{
				new TerminalRun(new string('0', 4), new TerminalFont() { Foreground = Color.FromRgb(0, 0, 0) }),
				new TerminalRun(new string('1', 3), new TerminalFont() { Foreground = Color.FromRgb(1, 1, 1) }),
				new TerminalRun(new string('3', 3), new TerminalFont() { Foreground = Color.FromRgb(3, 3, 3) }),
			};

			AssertAreEqual(line.Runs[0], expectedRuns[0]);
			AssertAreEqual(line.Runs[1], expectedRuns[1]);
			AssertAreEqual(line.Runs[2], expectedRuns[2]);
		}
Пример #4
0
        public void Resize(int cols, int rows)
        {
            Size = new Point(cols, rows);

            int oldRowCount = lines.Length;

            if (rows != oldRowCount)
            {
                var newLines = new TerminalLine[rows];
                if (rows > oldRowCount)
                {
                    Array.Copy(lines, 0, newLines, 0, oldRowCount);
                    for (int i = oldRowCount; i < rows; ++i)
                    {
                        newLines[i] = new TerminalLine();
                    }
                }
                else if (rows < oldRowCount)
                {
                    int startIndex    = 0;
                    int remainingRows = cursorRow - rows + 1;
                    if (remainingRows > 0)
                    {
                        startIndex = remainingRows;
                    }
                    Array.Copy(lines, startIndex, newLines, 0, rows);
                }

                lines = newLines;
            }

            foreach (var line in lines)
            {
                line.ColCount = cols;
            }

            CursorRow = CursorRow;
        }
Пример #5
0
        public void MoveLines(int index, int newIndex, int count)
        {
            int addIndex;

            if (newIndex > index)
            {
                addIndex = index;
            }
            else
            {
                addIndex = newIndex + count;
            }

            int addedCount = Math.Abs(index - newIndex);

            Array.Copy(lines, index, lines, newIndex, count);
            for (int i = 0; i < addedCount; ++i)
            {
                lines[addIndex + i] = new TerminalLine();
            }

            LinesMoved?.Invoke(this, new LinesMovedEventArgs(index, newIndex, count));
        }
Пример #6
0
        void advanceCursorRow()
        {
            cursorRow++;

            if (cursorRow == Size.Row)
            {
                var oldLine = lines[0];
                var newLine = new TerminalLine();
                cursorRow--;
                Array.Copy(lines, 1, lines, 0, lines.Length - 1);
                lines[lines.Length - 1] = newLine;

                LinesMoved?.Invoke(this, new LinesMovedEventArgs(1, 0, Size.Row - 1));
            }
        }
Пример #7
0
        public void MoveLines(int index, int newIndex, int count)
        {
            int addIndex;
            if (newIndex > index)
                addIndex = index;
            else
                addIndex = newIndex + count;

            int addedCount = Math.Abs(index - newIndex);
            Array.Copy(lines, index, lines, newIndex, count);
            for (int i = 0; i < addedCount; ++i)
                lines[addIndex + i] = new TerminalLine();

            LinesMoved?.Invoke(this, new LinesMovedEventArgs(index, newIndex, count));
        }
Пример #8
0
 public TerminalLineVisual(TerminalControlCore terminal, TerminalLine line)
 {
     this.Terminal = terminal;
     this.Line = line;
 }
Пример #9
0
 TerminalRun[] CopyLine(TerminalLine line)
 {
     var runs = line.Runs;
     var result = new TerminalRun[runs.Count];
     for (int i = 0; i < runs.Count; ++i)
     {
         var run = runs[i];
         result[i] = new TerminalRun(run.Text, run.Font);
     }
     return result;
 }