diff options
author | Jesse Plamondon-Willard <Pathoschild@users.noreply.github.com> | 2022-01-15 12:21:22 -0500 |
---|---|---|
committer | Jesse Plamondon-Willard <Pathoschild@users.noreply.github.com> | 2022-01-15 12:21:22 -0500 |
commit | a8985e122e9ebd3cb1545971474b95d34058f896 (patch) | |
tree | 18cd20a7dacc8023a689f5118a6e42a486c3ca3a /src/SMAPI/Framework/Logging/InterceptingTextWriter.cs | |
parent | e30e42762871af3900c47886b57e8c43287b290a (diff) | |
download | SMAPI-a8985e122e9ebd3cb1545971474b95d34058f896.tar.gz SMAPI-a8985e122e9ebd3cb1545971474b95d34058f896.tar.bz2 SMAPI-a8985e122e9ebd3cb1545971474b95d34058f896.zip |
fix suppressed console output not suppressing newlines
Diffstat (limited to 'src/SMAPI/Framework/Logging/InterceptingTextWriter.cs')
-rw-r--r-- | src/SMAPI/Framework/Logging/InterceptingTextWriter.cs | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/src/SMAPI/Framework/Logging/InterceptingTextWriter.cs b/src/SMAPI/Framework/Logging/InterceptingTextWriter.cs index d99f1dd2..41a3abcb 100644 --- a/src/SMAPI/Framework/Logging/InterceptingTextWriter.cs +++ b/src/SMAPI/Framework/Logging/InterceptingTextWriter.cs @@ -26,6 +26,10 @@ namespace StardewModdingAPI.Framework.Logging /// <summary>The event raised when a message is written to the console directly.</summary> public event Action<string> OnMessageIntercepted; + /// <summary>Whether the text writer should ignore the next input if it's a newline.</summary> + /// <remarks>This is used when log output is suppressed from the console, since <c>Console.WriteLine</c> writes the trailing newline as a separate call.</remarks> + public bool IgnoreNextIfNewline { get; set; } + /********* ** Public methods @@ -42,12 +46,18 @@ namespace StardewModdingAPI.Framework.Logging /// <inheritdoc /> public override void Write(char[] buffer, int index, int count) { + bool ignoreIfNewline = this.IgnoreNextIfNewline; + this.IgnoreNextIfNewline = false; + if (buffer.Length == 0) this.Out.Write(buffer, index, count); else if (buffer[0] == this.IgnoreChar) this.Out.Write(buffer, index + 1, count - 1); else if (this.IsEmptyOrNewline(buffer)) - this.Out.Write(buffer, index, count); + { + if (!ignoreIfNewline) + this.Out.Write(buffer, index, count); + } else this.OnMessageIntercepted?.Invoke(new string(buffer, index, count).TrimEnd('\r', '\n')); } |