mirror of
https://github.com/nsnail/spectre.console.git
synced 2025-06-19 13:28:16 +08:00

committed by
Phil Scott

parent
2e5d18fa78
commit
fd4b96944e
@ -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))
|
||||
|
@ -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)
|
||||
|
Reference in New Issue
Block a user