Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/tomlm/consolescreenbuffer

Library to use alternative console screen buffers on Windows with Console class.
https://github.com/tomlm/consolescreenbuffer

Last synced: 5 days ago
JSON representation

Library to use alternative console screen buffers on Windows with Console class.

Awesome Lists containing this project

README

        

# ConsoleScreenBuffer
Class which makes dotnet Console API on windows work with an alternate screen buffer.

# Install

```dotnet add package ConsoleScreenBuffer```

# Usage

The **ConsoleScreenBuffer** class gives you the ability to create console screen buffers, and switch between them easily.

* **To Capture Current Buffer**
* ```ConsoleScreenBuffer.GetCurrent()```
* **To Create an alternate buffer**
* ```ConsoleScreenBuffer.Create()```
* **To Activate a buffer** -
* ```buffer.SetAsActiveBuffer()``` All of the Console API's will use the new screen buffer seamlessly.

![secondaryBuffer](https://github.com/tomlm/ConsoleScreenBuffer/blob/main/assets/secondaryBuffer.gif)

# Example

```csharp
Console.WriteLine("Hello, World!");
// capture the original screen buffer
var originalBuffer = ConsoleScreenBuffer.GetCurrent();

// create an alternate screen buffer
var buffer = ConsoleScreenBuffer.Create(true);

// make it active
buffer.SetAsActiveBuffer();

// use Console API.
Console.SetCursorPosition(10, 2);
Console.ForegroundColor = ConsoleColor.Yellow;
Console.Write("Hello secondary buffer!");
Console.ReadKey(true); // wait for a keypress

// restore original screen
originalBuffer.SetAsActiveBuffer();
Console.WriteLine("All done");

```