Skip to content

Commit

Permalink
This commit introduces support for tab and newline characters in the …
Browse files Browse the repository at this point in the history
…DrawingContextImpl class. The update will handle these characters during draw operations, translating tab characters into a sequence of spaces and newline characters into a 'no-op' (no operation) at this stage.
  • Loading branch information
jinek committed Jan 5, 2024
1 parent 43683fc commit 033d27d
Showing 1 changed file with 36 additions and 5 deletions.
41 changes: 36 additions & 5 deletions src/Consolonia.Core/Drawing/DrawingContextImpl.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

Check warning on line 4 in src/Consolonia.Core/Drawing/DrawingContextImpl.cs

View workflow job for this annotation

GitHub Actions / build

"[RedundantUsingDirective] Using directive is not required by the code and can be safely removed" on /home/runner/work/Consolonia/Consolonia/src/Consolonia.Core/Drawing/DrawingContextImpl.cs(4,67)
using Avalonia;
using Avalonia.Media;
using Avalonia.Platform;
Expand Down Expand Up @@ -381,11 +382,12 @@ void DrawPixelAndMoveHead(int count)
if (!Transform.IsTranslateOnly()) ConsoloniaPlatform.RaiseNotSupported(15);

Point whereToDraw = origin.Transform(Transform);
int currentXPosition = 0;

//todo: support surrogates
for (int i = 0; i < str.Length; i++)
{
Point characterPoint = whereToDraw.Transform(Matrix.CreateTranslation(i, 0));
Point characterPoint = whereToDraw.Transform(Matrix.CreateTranslation(currentXPosition++, 0));
CurrentClip.ExecuteWithClipping(characterPoint, () =>
{
ConsoleColor foregroundColor = consoleColorBrush.Color;
Expand All @@ -411,11 +413,40 @@ void DrawPixelAndMoveHead(int count)
}
}

// ReSharper disable once AccessToModifiedClosure //todo: pass as a parameter
var consolePixel = new Pixel(str[i], foregroundColor);
char character = str[i];

Check warning on line 416 in src/Consolonia.Core/Drawing/DrawingContextImpl.cs

View workflow job for this annotation

GitHub Actions / build

"[AccessToModifiedClosure] Captured variable is modified in the outer scope" on /home/runner/work/Consolonia/Consolonia/src/Consolonia.Core/Drawing/DrawingContextImpl.cs(416,15082)

_pixelBuffer.Set((PixelBufferCoordinate)characterPoint,
(oldPixel, cp) => oldPixel.Blend(cp), consolePixel);
switch (character)
{
case '\t':
{
var consolePixel = new Pixel(' ', foregroundColor);
for (int j = 0; j < 8; j++)
{
_pixelBuffer.Set((PixelBufferCoordinate)characterPoint.WithX(characterPoint.X + j),
(oldPixel, cp) => oldPixel.Blend(cp), consolePixel);
currentXPosition++;

Check warning on line 427 in src/Consolonia.Core/Drawing/DrawingContextImpl.cs

View workflow job for this annotation

GitHub Actions / build

"[AccessToModifiedClosure] Captured variable is modified in the outer scope" on /home/runner/work/Consolonia/Consolonia/src/Consolonia.Core/Drawing/DrawingContextImpl.cs(427,15612)
}

currentXPosition--;
}
break;
case '\n':
{
/*var consolePixel = new Pixel(' ', foregroundColor);
_pixelBuffer.Set((PixelBufferCoordinate)characterPoint,
(oldPixel, cp) => oldPixel.Blend(cp), consolePixel);*/
}
break;
default:
{
var consolePixel = new Pixel(character, foregroundColor);

_pixelBuffer.Set((PixelBufferCoordinate)characterPoint,
(oldPixel, cp) => oldPixel.Blend(cp), consolePixel);
}
break;
}
});
}
}
Expand Down

0 comments on commit 033d27d

Please sign in to comment.