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

committed by
Patrik Svensson

parent
913a7b1e37
commit
a23bec4082
29
src/Spectre.Console/Internal/DefaultInput.cs
Normal file
29
src/Spectre.Console/Internal/DefaultInput.cs
Normal file
@ -0,0 +1,29 @@
|
||||
using System;
|
||||
|
||||
namespace Spectre.Console
|
||||
{
|
||||
internal sealed class DefaultInput : IAnsiConsoleInput
|
||||
{
|
||||
private readonly Profile _profile;
|
||||
|
||||
public DefaultInput(Profile profile)
|
||||
{
|
||||
_profile = profile ?? throw new ArgumentNullException(nameof(profile));
|
||||
}
|
||||
|
||||
public ConsoleKeyInfo ReadKey(bool intercept)
|
||||
{
|
||||
if (_profile.Capabilities.Tty)
|
||||
{
|
||||
throw new InvalidOperationException("Cannot read input from a TTY console.");
|
||||
}
|
||||
|
||||
if (!_profile.Capabilities.Interactive)
|
||||
{
|
||||
throw new InvalidOperationException("Failed to read input in non-interactive mode.");
|
||||
}
|
||||
|
||||
return System.Console.ReadKey(intercept);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user