diff --git a/CHANGELOG.md b/CHANGELOG.md index 6b6743e..c74e6e9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Scheduled action callbacks allow a TimeSpan to be returned to delay actions - Handling a Crestron bug where File.Exists throws an exception on 4-Series instead of returning false - Changed ProcessorUtils.ModelVersion to be a string, Crestron pulls model version from CrestronEnvironment + - For 4-series console outputs, replacing \n with \r\n to help console readability ## [13.0.0] - 2020-09-03 ### Added diff --git a/ICD.Common.Utils/IcdConsole.cs b/ICD.Common.Utils/IcdConsole.cs index 23c0a15..5998f83 100644 --- a/ICD.Common.Utils/IcdConsole.cs +++ b/ICD.Common.Utils/IcdConsole.cs @@ -1,5 +1,6 @@ using System; using System.Linq; +using System.Text.RegularExpressions; using ICD.Common.Properties; using ICD.Common.Utils.EventArguments; using ICD.Common.Utils.Extensions; @@ -13,6 +14,7 @@ namespace ICD.Common.Utils { public static class IcdConsole { + private const string NEWLINE = "\r\n"; public enum eAccessLevel { Operator = 0, @@ -24,12 +26,15 @@ namespace ICD.Common.Utils private static readonly SafeCriticalSection s_Section; + private static readonly Regex s_NewLineRegex; + /// /// Static constructor. /// static IcdConsole() { s_Section = new SafeCriticalSection(); + s_NewLineRegex = new Regex("(?!<\r)\n"); } /// @@ -40,7 +45,7 @@ namespace ICD.Common.Utils [PublicAPI] public static void ConsoleCommandResponseLine(string message, params object[] args) { - ConsoleCommandResponse(message + IcdEnvironment.NewLine, args); + ConsoleCommandResponse(message + NEWLINE, args); } /// @@ -54,8 +59,11 @@ namespace ICD.Common.Utils if (args != null && args.Any()) message = string.Format(message, args); + message = FixLineEndings(message); + #if SIMPLSHARP - if (IcdEnvironment.RuntimeEnvironment == IcdEnvironment.eRuntimeEnvironment.SimplSharpPro) + if (IcdEnvironment.RuntimeEnvironment == IcdEnvironment.eRuntimeEnvironment.SimplSharpPro || + IcdEnvironment.RuntimeEnvironment == IcdEnvironment.eRuntimeEnvironment.SimplSharpProMono) { try { @@ -76,13 +84,15 @@ namespace ICD.Common.Utils { s_Section.Enter(); + string fixedMessage = FixLineEndings(message); + try { #if SIMPLSHARP if (IcdEnvironment.RuntimeEnvironment != IcdEnvironment.eRuntimeEnvironment.SimplSharpProServer) - CrestronConsole.PrintLine(message); + CrestronConsole.PrintLine(fixedMessage); #else - Console.WriteLine(message); + Console.WriteLine(fixedMessage); #endif } finally @@ -90,7 +100,7 @@ namespace ICD.Common.Utils s_Section.Leave(); } - OnConsolePrint.Raise(null, new StringEventArgs(message + IcdEnvironment.NewLine)); + OnConsolePrint.Raise(null, new StringEventArgs(message + NEWLINE)); } public static void PrintLine(string message, params object[] args) @@ -115,11 +125,13 @@ namespace ICD.Common.Utils { s_Section.Enter(); + string fixedMessage = FixLineEndings(message); + try { #if SIMPLSHARP if (IcdEnvironment.RuntimeEnvironment != IcdEnvironment.eRuntimeEnvironment.SimplSharpProServer) - CrestronConsole.Print(message); + CrestronConsole.Print(fixedMessage); #else Console.Write(message); #endif @@ -129,7 +141,7 @@ namespace ICD.Common.Utils s_Section.Leave(); } - OnConsolePrint.Raise(null, new StringEventArgs(message)); + OnConsolePrint.Raise(null, new StringEventArgs(fixedMessage)); } public static void Print(string message, params object[] args) @@ -180,5 +192,21 @@ namespace ICD.Common.Utils return false; #endif } + + /// + /// Code running on SimplSharpProMono uses \n for newline (due to linux environment), + /// Which causes console output to be unreadable on most SSH clients. This converts those + /// endings to \r\n, since Crestron's SSH server doesn't do it automatically. + /// This is a hack until Crestron fixes their SSH server. + /// + /// + /// + private static string FixLineEndings(string input) + { + if (IcdEnvironment.RuntimeEnvironment != IcdEnvironment.eRuntimeEnvironment.SimplSharpProMono) + return input; + + return s_NewLineRegex.Replace(input, NEWLINE); + } } }