Fixed Issue #2 and did some more stuff. #3
@ -5,6 +5,7 @@ global using System;
|
||||
global using System.Collections.Generic;
|
||||
global using System.Diagnostics;
|
||||
global using System.IO;
|
||||
global using System.IO.Compression;
|
||||
global using System.Linq;
|
||||
global using System.Reflection;
|
||||
global using static SrcMod.Shell.Tools;
|
||||
|
||||
@ -1,7 +1,4 @@
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
|
||||
namespace SrcMod.Shell.Modules;
|
||||
namespace SrcMod.Shell.Modules;
|
||||
|
||||
[Module("base", false)]
|
||||
public static class BaseModule
|
||||
|
||||
@ -23,10 +23,10 @@ public static class TypeParsers
|
||||
if (TryParse(msg, out char resChar)) return resChar;
|
||||
if (TryParse(msg, out DateOnly dateOnly)) return dateOnly;
|
||||
if (TryParse(msg, out DateTime dateTime)) return dateTime;
|
||||
if (TryParse(msg, out DateTime dateTimeOffset)) return dateTimeOffset;
|
||||
if (TryParse(msg, out DateTimeOffset dateTimeOffset)) return dateTimeOffset;
|
||||
if (TryParse(msg, out Guid guid)) return guid;
|
||||
if (TryParse(msg, out TimeOnly timeOnly)) return timeOnly;
|
||||
if (TryParse(msg, out TimeOnly timeSpan)) return timeSpan;
|
||||
if (TryParse(msg, out TimeSpan timeSpan)) return timeSpan;
|
||||
|
||||
return msg;
|
||||
}
|
||||
|
||||
@ -44,10 +44,22 @@ public class Shell
|
||||
WorkingDirectory = Directory.GetCurrentDirectory();
|
||||
|
||||
// Load modules and commands.
|
||||
List<Assembly?> possibleAsms = new()
|
||||
{
|
||||
assembly,
|
||||
Assembly.GetEntryAssembly(),
|
||||
Assembly.GetCallingAssembly()
|
||||
};
|
||||
|
||||
LoadedModules = new();
|
||||
LoadedCommands = new();
|
||||
|
||||
Type[] possibleModules = assembly.GetTypes();
|
||||
List<Type> possibleModules = new();
|
||||
foreach (Assembly? a in possibleAsms)
|
||||
{
|
||||
if (a is null) continue;
|
||||
possibleModules.AddRange(a.GetTypes().Where(x => !possibleModules.Contains(x)));
|
||||
}
|
||||
foreach (Type t in possibleModules)
|
||||
{
|
||||
ModuleInfo? module = ModuleInfo.FromModule(t);
|
||||
@ -166,10 +178,12 @@ public class Shell
|
||||
catch (TargetInvocationException ex)
|
||||
{
|
||||
Write($"[ERROR] {ex.InnerException!.Message}", ConsoleColor.Red);
|
||||
if (LoadingBarEnabled) LoadingBarEnd();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Write($"[ERROR] {ex.Message}", ConsoleColor.Red);
|
||||
if (LoadingBarEnabled) LoadingBarEnd();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@ -5,8 +5,10 @@ namespace SrcMod.Shell;
|
||||
public static class Tools
|
||||
{
|
||||
private static int loadingPosition = -1;
|
||||
private static int lastBufferSize = 0;
|
||||
private static int lastValue = -1;
|
||||
private static int lastLoadingBufferSize = 0;
|
||||
private static int lastLoadingValue = -1;
|
||||
|
||||
public static bool LoadingBarEnabled { get; private set; }
|
||||
|
||||
public static void DisplayWithPages(IEnumerable<string> lines, ConsoleColor? color = null)
|
||||
{
|
||||
@ -77,6 +79,7 @@ public static class Tools
|
||||
Console.SetCursorPosition(oldPos.x, oldPos.y);
|
||||
}
|
||||
loadingPosition = -1;
|
||||
LoadingBarEnabled = false;
|
||||
}
|
||||
public static void LoadingBarSet(float value, ConsoleColor? color = null)
|
||||
{
|
||||
@ -85,17 +88,18 @@ public static class Tools
|
||||
int barSize = Console.BufferWidth - left.Length - right.Length,
|
||||
filled = (int)(barSize * value);
|
||||
|
||||
if (filled == lastValue) return;
|
||||
if (filled == lastLoadingValue) return;
|
||||
lastLoadingValue = filled;
|
||||
|
||||
Int2 oldPos = (Console.CursorLeft, Console.CursorTop);
|
||||
|
||||
// Erase last bar.
|
||||
Console.SetCursorPosition(0, loadingPosition);
|
||||
Console.Write(new string(' ', lastBufferSize));
|
||||
Console.Write(new string(' ', lastLoadingBufferSize));
|
||||
Console.CursorLeft = 0;
|
||||
|
||||
// Add new bar.
|
||||
lastBufferSize = Console.BufferWidth;
|
||||
lastLoadingBufferSize = Console.BufferWidth;
|
||||
|
||||
Write(left, newLine: false);
|
||||
ConsoleColor oldFore = Console.ForegroundColor;
|
||||
@ -114,6 +118,7 @@ public static class Tools
|
||||
if (loadingPosition != -1) throw new("The loading bar has already been enabled.");
|
||||
loadingPosition = position ?? Console.CursorTop;
|
||||
LoadingBarSet(value, color);
|
||||
LoadingBarEnabled = true;
|
||||
}
|
||||
|
||||
public static void Write(object? message, ConsoleColor? col = null, bool newLine = true)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user