mirror of
https://github.com/JustArchiNET/ArchiSteamFarm
synced 2024-11-10 15:14:41 +00:00
parent
2e9791faa3
commit
120f7e36d6
1 changed files with 16 additions and 38 deletions
|
@ -46,7 +46,6 @@ internal static class Logging {
|
||||||
private const byte ConsoleResponsivenessDelay = 250; // In milliseconds
|
private const byte ConsoleResponsivenessDelay = 250; // In milliseconds
|
||||||
private const string GeneralLayout = $@"${{date:format=yyyy-MM-dd HH\:mm\:ss}}|${{processname}}-${{processid}}|${{level:uppercase=true}}|{LayoutMessage}";
|
private const string GeneralLayout = $@"${{date:format=yyyy-MM-dd HH\:mm\:ss}}|${{processname}}-${{processid}}|${{level:uppercase=true}}|{LayoutMessage}";
|
||||||
private const string LayoutMessage = @"${logger}|${message}${onexception:inner= ${exception:format=toString,Data}}";
|
private const string LayoutMessage = @"${logger}|${message}${onexception:inner= ${exception:format=toString,Data}}";
|
||||||
private const byte MaxReadFailures = 100; // How many unknown characters we allow before closing STDIN in order to avoid infinite loop
|
|
||||||
|
|
||||||
internal static bool LogFileExists => File.Exists(SharedInfo.LogFile);
|
internal static bool LogFileExists => File.Exists(SharedInfo.LogFile);
|
||||||
|
|
||||||
|
@ -309,28 +308,20 @@ internal static class Logging {
|
||||||
|
|
||||||
StringBuilder result = new();
|
StringBuilder result = new();
|
||||||
|
|
||||||
byte readFailures = 0;
|
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
ConsoleKeyInfo keyInfo = Console.ReadKey(true);
|
ConsoleKeyInfo keyInfo = Console.ReadKey(true);
|
||||||
|
|
||||||
switch (keyInfo.Key) {
|
if (keyInfo.KeyChar == '\u0004') {
|
||||||
case 0 when ++readFailures < MaxReadFailures:
|
// Linux terminal closing STDIN, we're done here
|
||||||
// Likely linux terminal closing STDIN, but we'll check for more
|
return result.ToString();
|
||||||
continue;
|
|
||||||
case 0:
|
|
||||||
// Linux terminal closing STDIN, we're done here
|
|
||||||
ASF.ArchiLogger.LogGenericWarning(string.Format(CultureInfo.CurrentCulture, Strings.WarningFailedWithError, nameof(readFailures)));
|
|
||||||
|
|
||||||
return result.ToString();
|
|
||||||
case ConsoleKey.Enter:
|
|
||||||
// User finishing input, as expected
|
|
||||||
Console.WriteLine();
|
|
||||||
|
|
||||||
return result.ToString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
readFailures = 0;
|
if (keyInfo.Key == ConsoleKey.Enter) {
|
||||||
|
// User finishing input, as expected
|
||||||
|
Console.WriteLine();
|
||||||
|
|
||||||
|
return result.ToString();
|
||||||
|
}
|
||||||
|
|
||||||
// User continues input
|
// User continues input
|
||||||
if (!char.IsControl(keyInfo.KeyChar)) {
|
if (!char.IsControl(keyInfo.KeyChar)) {
|
||||||
|
@ -355,8 +346,6 @@ internal static class Logging {
|
||||||
|
|
||||||
private static async Task HandleConsoleInteractively() {
|
private static async Task HandleConsoleInteractively() {
|
||||||
try {
|
try {
|
||||||
byte readFailures = 0;
|
|
||||||
|
|
||||||
while (!Program.ShutdownSequenceInitialized) {
|
while (!Program.ShutdownSequenceInitialized) {
|
||||||
if (IsWaitingForUserInput || !Console.KeyAvailable) {
|
if (IsWaitingForUserInput || !Console.KeyAvailable) {
|
||||||
await Task.Delay(ConsoleResponsivenessDelay).ConfigureAwait(false);
|
await Task.Delay(ConsoleResponsivenessDelay).ConfigureAwait(false);
|
||||||
|
@ -369,26 +358,15 @@ internal static class Logging {
|
||||||
try {
|
try {
|
||||||
ConsoleKeyInfo keyInfo = Console.ReadKey(true);
|
ConsoleKeyInfo keyInfo = Console.ReadKey(true);
|
||||||
|
|
||||||
switch (keyInfo.Key) {
|
if (keyInfo.KeyChar == '\u0004') {
|
||||||
case 0 when ++readFailures < MaxReadFailures:
|
// Linux terminal closing STDIN, we're done here
|
||||||
// Likely linux terminal closing STDIN, but we'll check for more
|
return;
|
||||||
continue;
|
|
||||||
case 0:
|
|
||||||
// Linux terminal closing STDIN, we're done here
|
|
||||||
ASF.ArchiLogger.LogGenericWarning(string.Format(CultureInfo.CurrentCulture, Strings.WarningFailedWithError, nameof(readFailures)));
|
|
||||||
|
|
||||||
return;
|
|
||||||
case ConsoleKey.C:
|
|
||||||
// User hitting 'c', as expected
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
// Any other input, ignored
|
|
||||||
readFailures = 0;
|
|
||||||
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
readFailures = 0;
|
if (keyInfo.Key != ConsoleKey.C) {
|
||||||
|
// Console input other than 'c', ignored
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
OnUserInputStart();
|
OnUserInputStart();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue