diff options
| author | Jesse Plamondon-Willard <github@jplamondonw.com> | 2017-10-07 23:20:36 -0400 |
|---|---|---|
| committer | Jesse Plamondon-Willard <github@jplamondonw.com> | 2017-10-07 23:20:36 -0400 |
| commit | d0dd2f7ba729de6be749d326a2fed78988ba9d7b (patch) | |
| tree | a22127da6a8900e9f29bbb847bfd5d3347f6b952 /src/StardewModdingAPI/Framework/Logging/ConsoleInterceptionManager.cs | |
| parent | 7889676ea24cafc945899bf25608784e3f5bc9e0 (diff) | |
| parent | 5928f5f86c4493ddb6b89bce0b7d0fb73a884c09 (diff) | |
| download | SMAPI-d0dd2f7ba729de6be749d326a2fed78988ba9d7b.tar.gz SMAPI-d0dd2f7ba729de6be749d326a2fed78988ba9d7b.tar.bz2 SMAPI-d0dd2f7ba729de6be749d326a2fed78988ba9d7b.zip | |
Merge branch 'add-mod-build-config' into develop
Diffstat (limited to 'src/StardewModdingAPI/Framework/Logging/ConsoleInterceptionManager.cs')
| -rw-r--r-- | src/StardewModdingAPI/Framework/Logging/ConsoleInterceptionManager.cs | 86 |
1 files changed, 0 insertions, 86 deletions
diff --git a/src/StardewModdingAPI/Framework/Logging/ConsoleInterceptionManager.cs b/src/StardewModdingAPI/Framework/Logging/ConsoleInterceptionManager.cs deleted file mode 100644 index b8f2c34e..00000000 --- a/src/StardewModdingAPI/Framework/Logging/ConsoleInterceptionManager.cs +++ /dev/null @@ -1,86 +0,0 @@ -using System; - -namespace StardewModdingAPI.Framework.Logging -{ - /// <summary>Manages console output interception.</summary> - internal class ConsoleInterceptionManager : IDisposable - { - /********* - ** Properties - *********/ - /// <summary>The intercepting console writer.</summary> - private readonly InterceptingTextWriter Output; - - - /********* - ** Accessors - *********/ - /// <summary>Whether the current console supports color formatting.</summary> - public bool SupportsColor { get; } - - /// <summary>The event raised when a message is written to the console directly.</summary> - public event Action<string> OnMessageIntercepted; - - - /********* - ** Public methods - *********/ - /// <summary>Construct an instance.</summary> - public ConsoleInterceptionManager() - { - // redirect output through interceptor - this.Output = new InterceptingTextWriter(Console.Out); - this.Output.OnMessageIntercepted += line => this.OnMessageIntercepted?.Invoke(line); - Console.SetOut(this.Output); - - // test color support - this.SupportsColor = this.TestColorSupport(); - } - - /// <summary>Get an exclusive lock and write to the console output without interception.</summary> - /// <param name="action">The action to perform within the exclusive write block.</param> - public void ExclusiveWriteWithoutInterception(Action action) - { - lock (Console.Out) - { - try - { - this.Output.ShouldIntercept = false; - action(); - } - finally - { - this.Output.ShouldIntercept = true; - } - } - } - - /// <summary>Release all resources.</summary> - public void Dispose() - { - Console.SetOut(this.Output.Out); - this.Output.Dispose(); - } - - - /********* - ** private methods - *********/ - /// <summary>Test whether the current console supports color formatting.</summary> - private bool TestColorSupport() - { - try - { - this.ExclusiveWriteWithoutInterception(() => - { - Console.ForegroundColor = Console.ForegroundColor; - }); - return true; - } - catch (Exception) - { - return false; // Mono bug - } - } - } -} |
