mirror of
https://github.com/ICDSystems/ICD.Common.Utils.git
synced 2026-02-17 05:35:07 +00:00
fix: Replace \n with \r\n for 4series console writes, to help reabibility
This commit is contained in:
@@ -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
|
- 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
|
- 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
|
- 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
|
## [13.0.0] - 2020-09-03
|
||||||
### Added
|
### Added
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
using ICD.Common.Properties;
|
using ICD.Common.Properties;
|
||||||
using ICD.Common.Utils.EventArguments;
|
using ICD.Common.Utils.EventArguments;
|
||||||
using ICD.Common.Utils.Extensions;
|
using ICD.Common.Utils.Extensions;
|
||||||
@@ -13,6 +14,7 @@ namespace ICD.Common.Utils
|
|||||||
{
|
{
|
||||||
public static class IcdConsole
|
public static class IcdConsole
|
||||||
{
|
{
|
||||||
|
private const string NEWLINE = "\r\n";
|
||||||
public enum eAccessLevel
|
public enum eAccessLevel
|
||||||
{
|
{
|
||||||
Operator = 0,
|
Operator = 0,
|
||||||
@@ -24,12 +26,15 @@ namespace ICD.Common.Utils
|
|||||||
|
|
||||||
private static readonly SafeCriticalSection s_Section;
|
private static readonly SafeCriticalSection s_Section;
|
||||||
|
|
||||||
|
private static readonly Regex s_NewLineRegex;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Static constructor.
|
/// Static constructor.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
static IcdConsole()
|
static IcdConsole()
|
||||||
{
|
{
|
||||||
s_Section = new SafeCriticalSection();
|
s_Section = new SafeCriticalSection();
|
||||||
|
s_NewLineRegex = new Regex("(?!<\r)\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -40,7 +45,7 @@ namespace ICD.Common.Utils
|
|||||||
[PublicAPI]
|
[PublicAPI]
|
||||||
public static void ConsoleCommandResponseLine(string message, params object[] args)
|
public static void ConsoleCommandResponseLine(string message, params object[] args)
|
||||||
{
|
{
|
||||||
ConsoleCommandResponse(message + IcdEnvironment.NewLine, args);
|
ConsoleCommandResponse(message + NEWLINE, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -54,8 +59,11 @@ namespace ICD.Common.Utils
|
|||||||
if (args != null && args.Any())
|
if (args != null && args.Any())
|
||||||
message = string.Format(message, args);
|
message = string.Format(message, args);
|
||||||
|
|
||||||
|
message = FixLineEndings(message);
|
||||||
|
|
||||||
#if SIMPLSHARP
|
#if SIMPLSHARP
|
||||||
if (IcdEnvironment.RuntimeEnvironment == IcdEnvironment.eRuntimeEnvironment.SimplSharpPro)
|
if (IcdEnvironment.RuntimeEnvironment == IcdEnvironment.eRuntimeEnvironment.SimplSharpPro ||
|
||||||
|
IcdEnvironment.RuntimeEnvironment == IcdEnvironment.eRuntimeEnvironment.SimplSharpProMono)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -76,13 +84,15 @@ namespace ICD.Common.Utils
|
|||||||
{
|
{
|
||||||
s_Section.Enter();
|
s_Section.Enter();
|
||||||
|
|
||||||
|
string fixedMessage = FixLineEndings(message);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
#if SIMPLSHARP
|
#if SIMPLSHARP
|
||||||
if (IcdEnvironment.RuntimeEnvironment != IcdEnvironment.eRuntimeEnvironment.SimplSharpProServer)
|
if (IcdEnvironment.RuntimeEnvironment != IcdEnvironment.eRuntimeEnvironment.SimplSharpProServer)
|
||||||
CrestronConsole.PrintLine(message);
|
CrestronConsole.PrintLine(fixedMessage);
|
||||||
#else
|
#else
|
||||||
Console.WriteLine(message);
|
Console.WriteLine(fixedMessage);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
@@ -90,7 +100,7 @@ namespace ICD.Common.Utils
|
|||||||
s_Section.Leave();
|
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)
|
public static void PrintLine(string message, params object[] args)
|
||||||
@@ -115,11 +125,13 @@ namespace ICD.Common.Utils
|
|||||||
{
|
{
|
||||||
s_Section.Enter();
|
s_Section.Enter();
|
||||||
|
|
||||||
|
string fixedMessage = FixLineEndings(message);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
#if SIMPLSHARP
|
#if SIMPLSHARP
|
||||||
if (IcdEnvironment.RuntimeEnvironment != IcdEnvironment.eRuntimeEnvironment.SimplSharpProServer)
|
if (IcdEnvironment.RuntimeEnvironment != IcdEnvironment.eRuntimeEnvironment.SimplSharpProServer)
|
||||||
CrestronConsole.Print(message);
|
CrestronConsole.Print(fixedMessage);
|
||||||
#else
|
#else
|
||||||
Console.Write(message);
|
Console.Write(message);
|
||||||
#endif
|
#endif
|
||||||
@@ -129,7 +141,7 @@ namespace ICD.Common.Utils
|
|||||||
s_Section.Leave();
|
s_Section.Leave();
|
||||||
}
|
}
|
||||||
|
|
||||||
OnConsolePrint.Raise(null, new StringEventArgs(message));
|
OnConsolePrint.Raise(null, new StringEventArgs(fixedMessage));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Print(string message, params object[] args)
|
public static void Print(string message, params object[] args)
|
||||||
@@ -180,5 +192,21 @@ namespace ICD.Common.Utils
|
|||||||
return false;
|
return false;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 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.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="input"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
private static string FixLineEndings(string input)
|
||||||
|
{
|
||||||
|
if (IcdEnvironment.RuntimeEnvironment != IcdEnvironment.eRuntimeEnvironment.SimplSharpProMono)
|
||||||
|
return input;
|
||||||
|
|
||||||
|
return s_NewLineRegex.Replace(input, NEWLINE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user