mirror of
https://github.com/BepInEx/BepInEx.git
synced 2026-10-20 01:46:13 +00:00
Add ForceBepInExTTYDriver option
This commit is contained in:
1 parent
ca9fa1cce0
commit
e24225f435
1 file changed
+18
-9
@@ -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");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user