Ver código fonte

Correctly handle stdout when it is redirected

Bepis 4 anos atrás
pai
commit
79ec0b1e4a

+ 9 - 1
BepInEx/Console/Unix/LinuxConsoleDriver.cs

@@ -27,9 +27,11 @@ namespace BepInEx.Unix
 			
 			UseMonoTtyDriver = typeof(Console).Assembly.GetType("System.ConsoleDriver") != null;
 
+			StdoutRedirected = UnixStreamHelper.isatty(1) != 1;
+
 			var duplicateStream = UnixStreamHelper.CreateDuplicateStream(1);
 
-			if (UseMonoTtyDriver)
+			if (UseMonoTtyDriver && !StdoutRedirected)
 			{
 				// Mono implementation handles xterm for us
 
@@ -68,6 +70,9 @@ namespace BepInEx.Unix
 
 		public void SetConsoleColor(ConsoleColor color)
 		{
+			if (StdoutRedirected)
+				return;
+
 			if (UseMonoTtyDriver)
 			{
 				// Use mono's inbuilt terminfo driver to set the foreground color for us
@@ -86,6 +91,9 @@ namespace BepInEx.Unix
 
 		public void SetConsoleTitle(string title)
 		{
+			if (StdoutRedirected)
+				return;
+
 			if (UseMonoTtyDriver)
 			{
 				SafeConsole.Title = title;

+ 4 - 0
BepInEx/Console/Unix/UnixStreamHelper.cs

@@ -31,6 +31,10 @@ namespace BepInEx.Unix
 		[DynDllImport("libc")]
 		public static fflushDelegate fflush;
 
+		public delegate int isattyDelegate(int fd);
+		[DynDllImport("libc")]
+		public static isattyDelegate isatty;
+
 		static UnixStreamHelper()
 		{
 			var libcMapping = new Dictionary<string, List<DynDllMapping>>