Skip to content

Commit

Permalink
Refactor drawing context implementation
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jinek committed Jan 5, 2024
1 parent 033d27d commit db0d2e5
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/Consolonia.Core/Drawing/DrawingContextImpl.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Avalonia;
using Avalonia.Media;
using Avalonia.Platform;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);*/
Expand All @@ -448,6 +450,7 @@ void DrawPixelAndMoveHead(int count)
break;
}
});
// ReSharper restore AccessToModifiedClosure
}
}
}
Expand Down

0 comments on commit db0d2e5

Please sign in to comment.