Add ForceBepInExTTYDriver option

This commit is contained in:
ghorsington committed 2021-02-23 00:39:28 +02:00
1 parent ca9fa1cce0
commit e24225f435
1 file changed
+18 -9
+18 -9
View File
@@ -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<bool> 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");
}
}
}
}