Created
September 4, 2017 23:42
-
-
Save afucher/b85a0786a4a45ce9f09669108bc289bd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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