Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

This commit introduces support for tab and newline characters in the … #113

Merged
merged 4 commits into from
Jan 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 43 additions & 5 deletions src/Consolonia.Core/Drawing/DrawingContextImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -381,11 +381,13 @@ void DrawPixelAndMoveHead(int count)
if (!Transform.IsTranslateOnly()) ConsoloniaPlatform.RaiseNotSupported(15);

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

//todo: support surrogates
jinek marked this conversation as resolved.
Show resolved Hide resolved
for (int i = 0; i < str.Length; i++)
{
Point characterPoint = whereToDraw.Transform(Matrix.CreateTranslation(i, 0));
Point characterPoint = whereToDraw.Transform(Matrix.CreateTranslation(currentXPosition++, 0));
// ReSharper disable AccessToModifiedClosure
CurrentClip.ExecuteWithClipping(characterPoint, () =>
{
ConsoleColor foregroundColor = consoleColorBrush.Color;
Expand All @@ -411,12 +413,48 @@ void DrawPixelAndMoveHead(int count)
}
}

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

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


currentXPosition += tabSize - 1;
}
break;
case '\n':
{
/* 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);*/
}
break;
default:
{
var consolePixel = new Pixel(character, foregroundColor);

_pixelBuffer.Set((PixelBufferCoordinate)characterPoint,
(oldPixel, cp) => oldPixel.Blend(cp), consolePixel);
}
break;
}
});
// ReSharper restore AccessToModifiedClosure
}
}
}
Expand Down
Loading