Exemple #1
0
        public void ConvertPointToRenderDataOffset_ShouldWork()
        {
            InitializeTestData();
            PSConsoleReadLine instance = GetPSConsoleReadLineSingleton();

            foreach (ResizingTestData test in s_resizingTestData)
            {
                RenderData renderData = new()
                {
                    lines       = new RenderedLineData[test.Lines.Count],
                    bufferWidth = test.OldBufferWidth
                };

                for (int i = 0; i < test.Lines.Count; i++)
                {
                    renderData.lines[i] = new RenderedLineData(test.Lines[i], isFirstLogicalLine: i == 0);
                }

                for (int j = 0; j < test.Context.Count; j++)
                {
                    ResizingTestContext context = test.Context[j];
                    renderData.cursorLeft = context.OldCursor.X;
                    renderData.cursorTop  = context.OldCursor.Y;

                    RenderDataOffset offset = instance.ConvertPointToRenderDataOffset(context.OldInitial.X, context.OldInitial.Y, renderData);
                    Assert.True(
                        context.Offset.LineIndex == offset.LogicalLineIndex &&
                        context.Offset.CharIndex == offset.VisibleCharIndex,
                        $"{test.Name}-context_{j}: calculated offset is not what's expected [line: {offset.LogicalLineIndex}, char: {offset.VisibleCharIndex}]");
                }
            }
        }
Exemple #2
0
        private void ForceRender()
        {
            var defaultColor = VTColorUtils.MapColorToEscapeSequence(_console.ForegroundColor, isBackground: false) +
                               VTColorUtils.MapColorToEscapeSequence(_console.BackgroundColor, isBackground: true);

            // Geneate a sequence of logical lines with escape sequences for coloring.
            int logicalLineCount = GenerateRender(defaultColor);

            // Now write that out (and remember what we did so we can clear previous renders
            // and minimize writing more than necessary on the next render.)

            var renderLines = new RenderedLineData[logicalLineCount];
            var renderData  = new RenderData {
                lines = renderLines
            };

            for (var i = 0; i < logicalLineCount; i++)
            {
                var line = _consoleBufferLines[i].ToString();
                renderLines[i].line    = line;
                renderLines[i].columns = LengthInBufferCells(line);
            }

            // And then do the real work of writing to the screen.
            // Rendering data is in reused
            ReallyRender(renderData, defaultColor);

            // Cleanup some excess buffers, saving a few because we know we'll use them.
            var bufferCount   = _consoleBufferLines.Count;
            var excessBuffers = bufferCount - renderLines.Length;

            if (excessBuffers > 5)
            {
                _consoleBufferLines.RemoveRange(renderLines.Length, excessBuffers);
            }
        }
Exemple #3
0
        public void ConvertRenderDataOffsetToPoint_ShouldWork()
        {
            InitializeTestData();
            PSConsoleReadLine instance = GetPSConsoleReadLineSingleton();

            foreach (ResizingTestData test in s_resizingTestData)
            {
                RenderData renderData = new()
                {
                    lines       = new RenderedLineData[test.Lines.Count],
                    bufferWidth = test.OldBufferWidth
                };

                for (int i = 0; i < test.Lines.Count; i++)
                {
                    renderData.lines[i] = new RenderedLineData(test.Lines[i], isFirstLogicalLine: i == 0);
                }

                for (int j = 0; j < test.Context.Count; j++)
                {
                    ResizingTestContext context = test.Context[j];
                    if (context.Offset.LineIndex != -1)
                    {
                        renderData.cursorLeft = context.OldCursor.X;
                        renderData.cursorTop  = context.OldCursor.Y;

                        var   offset    = new RenderDataOffset(context.Offset.LineIndex, context.Offset.CharIndex);
                        Point newCursor = instance.ConvertRenderDataOffsetToPoint(context.NewInitial.X, context.NewInitial.Y, test.NewBufferWidth, renderData, offset);
                        Assert.True(
                            context.NewCursor.X == newCursor.X &&
                            context.NewCursor.Y == newCursor.Y,
                            $"{test.Name}-context_{j}: calculated new cursor is not what's expected [X: {newCursor.X}, Y: {newCursor.Y}]");
                    }
                }
            }
        }