16 public string?
Title => platformIdentifier.IsWindows
17 ? global::System.Console.Title
21 public bool Available => Environment.UserInteractive;
50 global::System.Console.CancelKeyPress += (sender, e) =>
71 public Task
PressAnyKeyAsync(CancellationToken cancellationToken) => Task.Factory.StartNew(
75 global::System.Console.Read();
79 TaskScheduler.Current);
82 public Task<string>
ReadLineAsync(
bool usePasswordChar, CancellationToken cancellationToken) => Task.Factory.StartNew(
88 return global::System.Console.ReadLine()
89 ??
throw new InvalidOperationException(
"Console input has been closed!");
91 var passwordBuilder =
new StringBuilder();
94 var keyDescription = global::System.Console.ReadKey(
true);
95 if (keyDescription.Key == ConsoleKey.Enter)
97 else if (keyDescription.Key == ConsoleKey.Backspace)
99 if (passwordBuilder.Length > 0)
101 --passwordBuilder.Length;
102 global::System.Console.Write(
"\b \b");
105 else if (keyDescription.KeyChar !=
'\u0000')
108 passwordBuilder.Append(keyDescription.KeyChar);
109 global::System.Console.Write(
'*');
112 while (!cancellationToken.IsCancellationRequested);
114 cancellationToken.ThrowIfCancellationRequested();
115 global::System.Console.WriteLine();
116 return passwordBuilder.ToString();
120 TaskScheduler.Current)
121 .WaitAsync(cancellationToken);
124 public Task
WriteAsync(
string? text,
bool newLine, CancellationToken cancellationToken) => Task.Factory.StartNew(
131 throw new InvalidOperationException(
"Cannot write null text without a new line!");
132 global::System.Console.WriteLine();
135 global::System.Console.WriteLine(text);
137 global::System.Console.Write(text);
141 TaskScheduler.Current);
146 ArgumentNullException.ThrowIfNull(newTitle);
147 global::System.Console.Title = newTitle;
156 throw new InvalidOperationException(
"Console unavailable");