-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
97 lines (84 loc) · 3.2 KB
/
Program.cs
File metadata and controls
97 lines (84 loc) · 3.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
using Spectre.Console;
using NShell.Shell;
using NShell.Shell.Commands;
using NShell.Shell.Plugins;
using NShell.Shell.Readline;
using static NShell.Animation.GlitchOutput;
public class Program
{
public static readonly string VERSION = "0.5.1";
public static readonly string GITHUB = "https://github.com/onihilist/NShell";
public static async Task Main(string[] args)
{
bool noBanner = false;
if (args.Length > 0)
{
switch (args[0])
{
case "--version":
case "-v":
Console.WriteLine($"NShell {VERSION}");
return;
case "--help":
case "-h":
Console.WriteLine("Usage: nshell [--version | --help | --no-banner]");
Console.WriteLine("\nOptions:");
Console.WriteLine(" --version, -v Show version information");
Console.WriteLine(" --help, -h Show this help message");
Console.WriteLine(" --no-banner Start without the welcome banner");
return;
case "--no-banner":
noBanner = true;
break;
}
}
AnsiConsole.Clear();
if (!noBanner)
{
AnsiConsole.Markup($"Welcome {Environment.UserName} to NShell !\n\n");
AnsiConsole.Markup($"\tversion : {VERSION}\n");
AnsiConsole.Markup($"\tgithub : {GITHUB}\n");
AnsiConsole.Markup("\n");
}
AnsiConsole.Markup("[bold cyan][[*]] - Booting NShell...[/]\n");
ShellContext context = new();
AnsiConsole.Markup("[bold cyan][[*]] - Loading command(s)...[/]\n");
CommandParser parser = new();
PluginLoader plugins = new();
AnsiConsole.Markup("[bold cyan][[*]] - Loading plugin(s)...[/]\n");
plugins.LoadPlugins();
parser.LoadCommands();
AppDomain.CurrentDomain.ProcessExit += (_, _) => {
ReadLine.History.Save();
};
if (!noBanner)
{
await GlitchedPrint("[+] - System Online", TimeSpan.FromMilliseconds(20));
}
else
{
AnsiConsole.MarkupLine("[bold green][[+]] - System Online[/]");
}
string inputBuffer;
while (true)
{
Environment.SetEnvironmentVariable("LS_COLORS", context.GetLsColors());
context.SetTheme(context.CurrentTheme);
AnsiConsole.Markup(context.GetPrompt());
ReadLine.History.ResetIndex();
ReadLine.Handler.UpdateInitCursorPos(Console.CursorLeft);
inputBuffer = ReadLine.GetText();
if (string.IsNullOrWhiteSpace(inputBuffer)) continue;
ReadLine.History.Add(inputBuffer);
try
{
parser.TryExecute(inputBuffer, context);
}
catch (Exception ex)
{
AnsiConsole.MarkupLine($"[[[red]-[/]]] - Shell crash: [yellow]{ex.Message}[/]");
}
}
}
}