From db0d2e5137ef9ffaf13bc81a0fcb899f74414197 Mon Sep 17 00:00:00 2001 From: Evgeny Gorbovoy Date: Fri, 5 Jan 2024 17:35:09 +0100 Subject: [PATCH] Refactor drawing context implementation The unused namespace `System.Text` was removed from the `DrawingContextImpl` class. Also, the handling of tab spaces was adjusted; instead of incrementing the current position one by one, we now increment it by the `tabSize` in one go. This also involved creating a constant for the `tabSize`. Additionally, comments related to resharper's handling of closure were added. --- src/Consolonia.Core/Drawing/DrawingContextImpl.cs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/Consolonia.Core/Drawing/DrawingContextImpl.cs b/src/Consolonia.Core/Drawing/DrawingContextImpl.cs index 0ca2fb49..82fa4d79 100644 --- a/src/Consolonia.Core/Drawing/DrawingContextImpl.cs +++ b/src/Consolonia.Core/Drawing/DrawingContextImpl.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Text; using Avalonia; using Avalonia.Media; using Avalonia.Platform; @@ -388,6 +387,7 @@ void DrawPixelAndMoveHead(int count) for (int i = 0; i < str.Length; i++) { Point characterPoint = whereToDraw.Transform(Matrix.CreateTranslation(currentXPosition++, 0)); + // ReSharper disable AccessToModifiedClosure CurrentClip.ExecuteWithClipping(characterPoint, () => { ConsoleColor foregroundColor = consoleColorBrush.Color; @@ -419,20 +419,22 @@ void DrawPixelAndMoveHead(int count) { case '\t': { + const int tabSize = 8; var consolePixel = new Pixel(' ', foregroundColor); - for (int j = 0; j < 8; j++) + for (int j = 0; j < tabSize; j++) { _pixelBuffer.Set((PixelBufferCoordinate)characterPoint.WithX(characterPoint.X + j), (oldPixel, cp) => oldPixel.Blend(cp), consolePixel); - currentXPosition++; } - currentXPosition--; + + currentXPosition+= tabSize - 1; } break; case '\n': { - /*var consolePixel = new Pixel(' ', foregroundColor); + /* it's not clear if we need to draw anything. Cursor can be placed at the end of the line + var consolePixel = new Pixel(' ', foregroundColor); _pixelBuffer.Set((PixelBufferCoordinate)characterPoint, (oldPixel, cp) => oldPixel.Blend(cp), consolePixel);*/ @@ -448,6 +450,7 @@ void DrawPixelAndMoveHead(int count) break; } }); + // ReSharper restore AccessToModifiedClosure } } }