-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ensure lineout does not mix stderr and stdout (#8)
- Loading branch information
Showing
4 changed files
with
56 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,43 @@ | ||
using System; | ||
|
||
namespace ProcNet.Std | ||
namespace ProcNet.Std; | ||
|
||
public class ConsoleOutColorWriter : ConsoleOutWriter | ||
{ | ||
public class ConsoleOutColorWriter : ConsoleOutWriter | ||
{ | ||
public static ConsoleOutColorWriter Default { get; } = new ConsoleOutColorWriter(); | ||
public static ConsoleOutColorWriter Default { get; } = new(); | ||
|
||
private readonly object _lock = new object(); | ||
public override void Write(ConsoleOut consoleOut) | ||
private readonly object _lock = new(); | ||
public override void Write(ConsoleOut consoleOut) | ||
{ | ||
lock (_lock) | ||
{ | ||
lock (_lock) | ||
Console.ResetColor(); | ||
if (consoleOut.Error) | ||
{ | ||
if (consoleOut.Error) | ||
{ | ||
Console.ForegroundColor = ConsoleColor.Red; | ||
consoleOut.CharsOrString(ErrorCharacters, ErrorLine); | ||
} | ||
else | ||
{ | ||
Console.ResetColor(); | ||
consoleOut.CharsOrString(OutCharacters, OutLine); | ||
} | ||
Console.ResetColor(); | ||
Console.ForegroundColor = ConsoleColor.Yellow; | ||
consoleOut.CharsOrString(ErrorCharacters, ErrorLine); | ||
} | ||
else | ||
consoleOut.CharsOrString(OutCharacters, OutLine); | ||
|
||
Console.ResetColor(); | ||
} | ||
} | ||
|
||
public override void Write(Exception e) | ||
public override void Write(Exception e) | ||
{ | ||
if (!(e is CleanExitExceptionBase ee)) throw e; | ||
lock (_lock) | ||
{ | ||
if (!(e is CleanExitExceptionBase ee)) throw e; | ||
lock (_lock) | ||
Console.ResetColor(); | ||
Console.ForegroundColor = ConsoleColor.Red; | ||
Console.Write(e.Message); | ||
if (!string.IsNullOrEmpty(ee.HelpText)) | ||
{ | ||
Console.ForegroundColor = ConsoleColor.Red; | ||
Console.Write(e.Message); | ||
if (!string.IsNullOrEmpty(ee.HelpText)) | ||
{ | ||
Console.ForegroundColor = ConsoleColor.DarkRed; | ||
Console.Write(ee.HelpText); | ||
} | ||
Console.ResetColor(); | ||
Console.ForegroundColor = ConsoleColor.DarkRed; | ||
Console.Write(ee.HelpText); | ||
} | ||
Console.ResetColor(); | ||
} | ||
} | ||
} |