Skip to content

Instantly share code, notes, and snippets.

@afucher
Created September 4, 2017 23:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save afucher/b85a0786a4a45ce9f09669108bc289bd to your computer and use it in GitHub Desktop.
Save afucher/b85a0786a4a45ce9f09669108bc289bd to your computer and use it in GitHub Desktop.
using System;
using System.Threading;
class Program
{
static void Main(string[] args)
{
Loop();
}
public static void ClearConsoleBlockLines(int startLine, int endLine)
{
for(var i = startLine; i <= endLine; i++)
{
Console.SetCursorPosition(0, i);
Console.Write(new String(' ', Console.BufferWidth));
}
}
public static void Loop()
{
ConsoleKeyInfo cki;
Console.WriteLine("Press ESC to stop");
int start_top = Console.CursorTop;
int end_top = start_top;
do
{
while (!Console.KeyAvailable)
{
// Do something
}
cki = Console.ReadKey(true);
ClearConsoleBlockLines(start_top, end_top);
Console.SetCursorPosition(0, start_top);
Console.WriteLine(cki.Key);
end_top = Console.CursorTop;
} while (cki.Key != ConsoleKey.Escape);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment