Handle further linux terminal edge case

We handled a situation where linux terminal is closing STDIN durng interactive console. This handles even further edge case where linux terminal is closing STDIN during user masked input.
This commit is contained in:
Archi
2023-11-11 14:37:08 +01:00
parent 494b1dfd1b
commit fc13f2c488

View File

@@ -314,9 +314,21 @@ internal static class Logging {
StringBuilder result = new();
ConsoleKeyInfo keyInfo;
while (true) {
ConsoleKeyInfo keyInfo = Console.ReadKey(true);
while ((keyInfo = Console.ReadKey(true)).Key != ConsoleKey.Enter) {
switch (keyInfo.Key) {
case 0:
// Linux terminal closing STDIN, we're done here
return result.ToString();
case ConsoleKey.Enter:
// User finishing input, as expected
Console.WriteLine();
return result.ToString();
}
// User continues input
if (!char.IsControl(keyInfo.KeyChar)) {
result.Append(keyInfo.KeyChar);
Console.Write(mask);
@@ -332,10 +344,6 @@ internal static class Logging {
}
}
}
Console.WriteLine();
return result.ToString();
} finally {
cts.Cancel();
}