Skip to content

Instantly share code, notes, and snippets.

@patriksvensson
Last active March 31, 2021 05:28
Show Gist options
  • Save patriksvensson/22791f3b413c313e80d4d77c3ff2a2a2 to your computer and use it in GitHub Desktop.
Save patriksvensson/22791f3b413c313e80d4d77c3ff2a2a2 to your computer and use it in GitHub Desktop.
Double Buffering Console
private static int _bufferHeight;
private static int _bufferY;
public static async Task Main()
{
_bufferWidth = Console.WindowWidth;
_bufferHeight = Console.WindowHeight;
_bufferY = _bufferHeight;
Console.SetBufferSize(_bufferWidth, _bufferHeight * 2);
Draw((() => {
// Do your draw call here.
});
}
private static async Task Draw(Action action)
{
// TODO: Clear the back buffer here with spaces
Console.CursorVisible = false;
Console.CursorLeft = 0;
Console.CursorTop = _bufferY;
action();
Console.MoveBufferArea(0, _bufferHeight, _bufferWidth, _bufferHeight, 0, 0);
Console.CursorLeft = 0;
Console.CursorTop = 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment