Add support for alternate screen buffers

Closes #250
This commit is contained in:
Patrik Svensson
2021-11-30 13:15:17 +01:00
committed by Phil Scott
parent 2e5d18fa78
commit fd4b96944e
17 changed files with 245 additions and 11 deletions

View File

@ -31,7 +31,7 @@ namespace Spectre.Console.Internal
}
}
public async Task<T> Run<T>(Func<Task<T>> func)
public async Task<T> RunAsync<T>(Func<Task<T>> func)
{
// Try acquiring the exclusivity semaphore
if (!await _semaphore.WaitAsync(0).ConfigureAwait(false))

View File

@ -13,6 +13,16 @@ namespace Spectre.Console
_profile = profile ?? throw new ArgumentNullException(nameof(profile));
}
public bool IsKeyAvailable()
{
if (!_profile.Capabilities.Interactive)
{
throw new InvalidOperationException("Failed to read input in non-interactive mode.");
}
return System.Console.KeyAvailable;
}
public ConsoleKeyInfo? ReadKey(bool intercept)
{
if (!_profile.Capabilities.Interactive)
@ -20,16 +30,16 @@ namespace Spectre.Console
throw new InvalidOperationException("Failed to read input in non-interactive mode.");
}
if (!System.Console.KeyAvailable)
{
return null;
}
return System.Console.ReadKey(intercept);
}
public async Task<ConsoleKeyInfo?> ReadKeyAsync(bool intercept, CancellationToken cancellationToken)
{
if (!_profile.Capabilities.Interactive)
{
throw new InvalidOperationException("Failed to read input in non-interactive mode.");
}
while (true)
{
if (cancellationToken.IsCancellationRequested)