cleanup console stuff
This commit is contained in:
@@ -19,20 +19,11 @@ public struct ConsoleLine
|
||||
content = line;
|
||||
}
|
||||
|
||||
public static implicit operator string(ConsoleLine line)
|
||||
{
|
||||
return line.content;
|
||||
}
|
||||
public static implicit operator string(ConsoleLine line) => line.content;
|
||||
|
||||
public static explicit operator ConsoleLine(string line)
|
||||
{
|
||||
return new ConsoleLine(line);
|
||||
}
|
||||
public static explicit operator ConsoleLine(string line) => new ConsoleLine(line);
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return content;
|
||||
}
|
||||
public override string ToString() => content;
|
||||
}
|
||||
|
||||
public static class Console
|
||||
@@ -79,7 +70,6 @@ public static class Console
|
||||
|
||||
public static ReadOnlySpan<ConsoleLine> Lines => instance.Lines;
|
||||
|
||||
|
||||
public static void Init()
|
||||
{
|
||||
if (instance != null)
|
||||
@@ -119,101 +109,57 @@ public static class Console
|
||||
}
|
||||
#endif
|
||||
|
||||
public static string GetBufferHistory(int index)
|
||||
{
|
||||
return instance.GetBufferHistory(index);
|
||||
}
|
||||
public static string GetBufferHistory(int index) => instance.GetBufferHistory(index);
|
||||
|
||||
// Echoes text to Console
|
||||
public static void Print(string text)
|
||||
{
|
||||
instance.Print(text);
|
||||
}
|
||||
|
||||
public static void Print(string text) => instance.Print(text);
|
||||
// Echoes warning text to Console
|
||||
public static void PrintWarning(string text)
|
||||
{
|
||||
instance.PrintWarning(text);
|
||||
}
|
||||
public static void PrintWarning(string text) => instance.PrintWarning(text);
|
||||
|
||||
// Echoes error text to Console
|
||||
[DebuggerHidden]
|
||||
public static void PrintError(string text)
|
||||
{
|
||||
instance.PrintError(text);
|
||||
}
|
||||
public static void PrintError(string text) => instance.PrintError(text);
|
||||
|
||||
// Echoes developer/debug text to Console
|
||||
public static void PrintDebug(string text)
|
||||
{
|
||||
instance.PrintDebug(1, false, text);
|
||||
}
|
||||
public static void PrintDebug(string text) => instance.PrintDebug(1, false, text);
|
||||
|
||||
// Echoes developer/debug text to Console
|
||||
public static void PrintDebug(int verbosity, string text)
|
||||
{
|
||||
instance.PrintDebug(verbosity, false, text);
|
||||
}
|
||||
public static void PrintDebug(int verbosity, string text) => instance.PrintDebug(verbosity, false, text);
|
||||
|
||||
// Echoes developer/debug text to Console
|
||||
public static void PrintDebug(int verbosity, bool noRepeat, string text)
|
||||
{
|
||||
instance.PrintDebug(verbosity, noRepeat, text);
|
||||
}
|
||||
public static void PrintDebug(int verbosity, bool noRepeat, string text) => instance.PrintDebug(verbosity, noRepeat, text);
|
||||
|
||||
// Opens the Console
|
||||
public static void Open()
|
||||
{
|
||||
instance.Open();
|
||||
}
|
||||
public static void Open() => instance.Open();
|
||||
|
||||
// Closes the Console
|
||||
public static void Close()
|
||||
{
|
||||
instance.Close();
|
||||
}
|
||||
public static void Close() => instance.Close();
|
||||
|
||||
// Clears the content of the Console
|
||||
public static void Clear()
|
||||
{
|
||||
instance.Clear();
|
||||
}
|
||||
public static void Clear() => instance.Clear();
|
||||
|
||||
public static void Execute(string str, bool bufferInput = false, bool noOutput = false)
|
||||
{
|
||||
instance.Execute(str, bufferInput, noOutput);
|
||||
}
|
||||
public static void Execute(string str, bool bufferInput = false, bool noOutput = false) => instance.Execute(str, bufferInput, noOutput);
|
||||
|
||||
public static string GetVariable(string variableName)
|
||||
{
|
||||
return instance.GetVariable(variableName);
|
||||
}
|
||||
public static string GetVariable(string variableName) => instance.GetVariable(variableName);
|
||||
}
|
||||
|
||||
public class ConsoleInstance : IDisposable
|
||||
{
|
||||
private readonly List<string> consoleBufferHistory = new List<string>();
|
||||
private readonly Dictionary<string, ConsoleCommand> consoleCommands = new Dictionary<string, ConsoleCommand>();
|
||||
|
||||
//private static List<string> consoleLines = new List<string>();
|
||||
private readonly List<ConsoleLine> consoleLines = new List<ConsoleLine>();
|
||||
|
||||
private readonly Dictionary<string, ConsoleVariable> consoleVariables =
|
||||
new Dictionary<string, ConsoleVariable>();
|
||||
|
||||
private readonly Stopwatch stopwatch = Stopwatch.StartNew();
|
||||
private readonly List<string> consoleBufferHistory = new();
|
||||
private readonly Dictionary<string, ConsoleCommand> consoleCommands = new();
|
||||
private readonly List<ConsoleLine> consoleLines = new();
|
||||
private readonly Dictionary<string, ConsoleVariable> consoleVariables = new();
|
||||
private readonly Stopwatch closeThrottleStopwatch = Stopwatch.StartNew();
|
||||
private StreamWriter logStream;
|
||||
|
||||
// Echoes developer/debug text to Console
|
||||
private string debugLastLine = "";
|
||||
public Action OnClose;
|
||||
|
||||
public Action OnClose;
|
||||
public Action OnOpen;
|
||||
public Action<string> OnPrint;
|
||||
|
||||
public bool ShowExecutedLines = true;
|
||||
|
||||
private StreamWriter logStream;
|
||||
|
||||
internal ConsoleInstance()
|
||||
{
|
||||
// Try different filename when running multiple instances
|
||||
@@ -224,7 +170,7 @@ public class ConsoleInstance : IDisposable
|
||||
try
|
||||
{
|
||||
#if FLAX_EDITOR
|
||||
logStream = new StreamWriter(Path.Combine(@"C:\dev\GoakeFlax", logFilename), false);
|
||||
logStream = new StreamWriter(Path.Combine(Globals.ProjectFolder, logFilename), false);
|
||||
#else
|
||||
logStream = new StreamWriter(Path.Combine(Directory.GetCurrentDirectory(), logFilename), false);
|
||||
#endif
|
||||
@@ -239,9 +185,7 @@ public class ConsoleInstance : IDisposable
|
||||
}
|
||||
|
||||
public bool IsOpen { get; internal set; } = true;
|
||||
|
||||
public bool IsSafeToQuit => stopwatch.Elapsed.TotalSeconds > 0.1;
|
||||
|
||||
public bool IsSafeToQuit => closeThrottleStopwatch.Elapsed.TotalSeconds > 0.1;
|
||||
public int DebugVerbosity { get; set; } = 1;
|
||||
public string LinePrefix { get; internal set; } = "]";
|
||||
|
||||
@@ -260,7 +204,6 @@ public class ConsoleInstance : IDisposable
|
||||
// Initializes the Console system.
|
||||
internal void InitConsoleSubsystems()
|
||||
{
|
||||
//AppDomain currentDomain = AppDomain.CurrentDomain;
|
||||
#if USE_NETCORE
|
||||
var assemblies = Utils.GetAssemblies();
|
||||
#else
|
||||
@@ -279,8 +222,13 @@ public class ConsoleInstance : IDisposable
|
||||
assemblyName.StartsWith("FlaxEngine.") ||
|
||||
assemblyName.StartsWith("JetBrains.") ||
|
||||
assemblyName.StartsWith("Microsoft.") ||
|
||||
assemblyName.StartsWith("nunit."))
|
||||
assemblyName.StartsWith("nunit.") ||
|
||||
assemblyName == "Snippets" ||
|
||||
assemblyName == "Anonymously Hosted DynamicMethods Assembly" ||
|
||||
assemblyName == "netstandard")
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach (Type type in assembly.GetTypes())
|
||||
{
|
||||
@@ -296,6 +244,7 @@ public class ConsoleInstance : IDisposable
|
||||
var attributes = Attribute.GetCustomAttributes(method);
|
||||
|
||||
foreach (Attribute attr in attributes)
|
||||
{
|
||||
if (attr is ConsoleCommandAttribute cmdAttribute)
|
||||
{
|
||||
//Console.Print("found cmd '" + cmdAttribute.name + "' bound to field '" + method.Name + "'");
|
||||
@@ -333,6 +282,7 @@ public class ConsoleInstance : IDisposable
|
||||
{
|
||||
cmdInitializer = method;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var kv in cmdParsed)
|
||||
@@ -352,6 +302,7 @@ public class ConsoleInstance : IDisposable
|
||||
var attributes = Attribute.GetCustomAttributes(field);
|
||||
|
||||
foreach (Attribute attr in attributes)
|
||||
{
|
||||
if (attr is ConsoleVariableAttribute cvarAttribute)
|
||||
{
|
||||
//Console.Print("found cvar '" + cvarAttribute.name + "' bound to field '" + field.Name + "'");
|
||||
@@ -362,6 +313,7 @@ public class ConsoleInstance : IDisposable
|
||||
new ConsoleVariable(cvarAttribute.name,
|
||||
cvarAttribute.flags | ConsoleFlags.NoSerialize, field));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach (PropertyInfo prop in type.GetProperties())
|
||||
@@ -374,6 +326,7 @@ public class ConsoleInstance : IDisposable
|
||||
var attributes = Attribute.GetCustomAttributes(prop);
|
||||
|
||||
foreach (Attribute attr in attributes)
|
||||
{
|
||||
if (attr is ConsoleVariableAttribute cvarAttribute)
|
||||
{
|
||||
//Console.Print("found cvar '" + cvarAttribute.name + "' bound to field '" + field.Name + "'");
|
||||
@@ -384,6 +337,7 @@ public class ConsoleInstance : IDisposable
|
||||
new ConsoleVariable(cvarAttribute.name,
|
||||
cvarAttribute.flags | ConsoleFlags.NoSerialize, getter, setter));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (cmdInitializer != null)
|
||||
@@ -410,16 +364,12 @@ public class ConsoleInstance : IDisposable
|
||||
public void Print(string text)
|
||||
{
|
||||
debugLastLine = text;
|
||||
|
||||
PrintLine(text);
|
||||
}
|
||||
|
||||
|
||||
// Echoes warning text to Console
|
||||
public void PrintWarning(string text)
|
||||
{
|
||||
PrintLine(text);
|
||||
}
|
||||
public void PrintWarning(string text) => PrintLine(text);
|
||||
|
||||
// Echoes error text to Console
|
||||
//[DebuggerNonUserCode]
|
||||
@@ -492,7 +442,7 @@ public class ConsoleInstance : IDisposable
|
||||
IsOpen = false;
|
||||
OnClose?.Invoke();
|
||||
|
||||
stopwatch.Restart();
|
||||
closeThrottleStopwatch.Restart();
|
||||
}
|
||||
|
||||
// Clears the content of the Console
|
||||
|
||||
Reference in New Issue
Block a user