From e24225f435a246dbb94a914ef97cea55d9e3cb49 Mon Sep 17 00:00:00 2001 From: ghorsington Date: Tue, 23 Feb 2021 00:39:28 +0200 Subject: [PATCH] Add ForceBepInExTTYDriver option --- BepInEx/Console/Unix/LinuxConsoleDriver.cs | 27 ++++++++++++++-------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/BepInEx/Console/Unix/LinuxConsoleDriver.cs b/BepInEx/Console/Unix/LinuxConsoleDriver.cs index 882cc45..e4e95f2 100644 --- a/BepInEx/Console/Unix/LinuxConsoleDriver.cs +++ b/BepInEx/Console/Unix/LinuxConsoleDriver.cs @@ -1,5 +1,6 @@ using System; using System.IO; +using BepInEx.Configuration; using BepInEx.Logging; using HarmonyLib; using UnityInjector.ConsoleUtil; @@ -8,22 +9,30 @@ namespace BepInEx.Unix { internal class LinuxConsoleDriver : IConsoleDriver { + private static readonly ConfigEntry ForceCustomTtyDriverConfig = + ConfigFile.CoreConfig.Bind( + "Logging.Console", + "ForceBepInExTTYDriver", + false, + "If enabled, forces to use custom BepInEx TTY driver for handling terminal output on unix."); + public static bool UseMonoTtyDriver { get; } static LinuxConsoleDriver() { UseMonoTtyDriver = false; + if (ForceCustomTtyDriverConfig.Value) + return; + var consoleDriverType = typeof(Console).Assembly.GetType("System.ConsoleDriver"); if (consoleDriverType != null) - { UseMonoTtyDriver = typeof(Console).Assembly.GetType("System.ParameterizedStrings") != null; - } } public TextWriter StandardOut { get; private set; } - public TextWriter ConsoleOut { get; private set; } + public TextWriter ConsoleOut { get; private set; } public bool ConsoleActive { get; private set; } public bool ConsoleIsExternal => false; @@ -84,21 +93,21 @@ namespace BepInEx.Unix return; if (UseMonoTtyDriver) - { // Use mono's inbuilt terminfo driver to set the foreground color for us SafeConsole.ForegroundColor = color; - } else - { ConsoleOut.Write(TtyInfo.GetAnsiCode(color)); - } } public void SetConsoleTitle(string title) { if (StdoutRedirected) return; - ConsoleOut.Write($"\u001B]2;{title.Replace("\\", "\\\\")}\u0007"); + + if (UseMonoTtyDriver && SafeConsole.TitleExists) + SafeConsole.Title = title; + else + ConsoleOut.Write($"\u001B]2;{title.Replace("\\", "\\\\")}\u0007"); } } -} \ No newline at end of file +}