/// <summary> /// Reads a key from the Terminal. This is the closest equivalent to Console.ReadKey /// </summary> /// <param name="intercept">if set to <c>true</c> the pressed key will not be rendered to the output.</param> /// <param name="disableLocking">if set to <c>true</c> the output will continue to be shown. /// This is useful for services and daemons that are running as console applications and wait for a key to exit the program.</param> /// <returns>The console key information</returns> public static ConsoleKeyInfo ReadKey(bool intercept, bool disableLocking = false) { if (IsConsolePresent == false) { return(default(ConsoleKeyInfo)); } if (disableLocking) { return(Console.ReadKey(intercept)); } lock (SyncLock) { Flush(); InputDone.Reset(); try { Console.CursorVisible = true; return(Console.ReadKey(intercept)); } finally { Console.CursorVisible = false; InputDone.Set(); } } }
/// <summary> /// Reads a line of text from the console /// </summary> /// <returns>The read line</returns> public static string ReadLine() { if (IsConsolePresent == false) { return(default(string)); } lock (SyncLock) { Flush(); InputDone.Reset(); try { Console.CursorVisible = true; return(Console.ReadLine()); } finally { Console.CursorVisible = false; InputDone.Set(); } } }