276 lines
8.6 KiB
C#
276 lines
8.6 KiB
C#
|
|
using Qrakhen.Qamp.Core;
|
|
using Qrakhen.Qamp.Core.Execution;
|
|
using Qrakhen.Qamp.Core.Logging;
|
|
using System.Diagnostics;
|
|
using System.Linq.Expressions;
|
|
using System.Text;
|
|
/*
|
|
// do args here too, keep console, etc. output with exit, all the spicy things
|
|
// if no file is given for example in args just keep cli live until quit
|
|
|
|
void Init(string[] args)
|
|
{
|
|
Console.WriteLine(string.Join(',', args));
|
|
string command = args.Length > 1 ? args[0] : args.Length == 1 ? "run" : "cli";
|
|
string target = args.Length > 1 ? args[1] : args.Length == 1 ? args[0] : "";
|
|
switch (command) {
|
|
case "run":
|
|
// check wheter .sqi or .sqr file
|
|
break;
|
|
case "cli":
|
|
|
|
break;
|
|
case "read":
|
|
|
|
break;
|
|
case "digest":
|
|
|
|
break;
|
|
case "help":
|
|
|
|
break;
|
|
}
|
|
}
|
|
|
|
Init(args);
|
|
|
|
void git(string path, string cmd)
|
|
{
|
|
Console.WriteLine($" > git {cmd}");
|
|
ProcessStartInfo info = new ProcessStartInfo{
|
|
WorkingDirectory = path,
|
|
FileName = "git",
|
|
Arguments = cmd
|
|
};
|
|
Process.Start(info)?.WaitForExit();
|
|
}
|
|
|
|
void del(string path, string cmd)
|
|
{
|
|
Console.WriteLine($" > git {cmd}");
|
|
ProcessStartInfo info = new ProcessStartInfo{
|
|
WorkingDirectory = path,
|
|
FileName = "del",
|
|
Arguments = $"{cmd} /F /Q /S"
|
|
};
|
|
Process.Start(info)?.WaitForExit();
|
|
}
|
|
|
|
string x = @"C:\Users\filos\projects";
|
|
string[] check = ["node_modules", "bin", "obj", "Library"];
|
|
int scanx(string path)
|
|
{
|
|
foreach (var dir in Directory.EnumerateDirectories(path)) {
|
|
try {
|
|
var name = dir.Replace(path, "").Replace(@"\", "");
|
|
if (!check.Contains(name)) {
|
|
scanx(dir);
|
|
} else {
|
|
Console.WriteLine(dir + " (" + (Directory.GetFiles(dir).Length + Directory.GetDirectories(dir).Length) + " files)");
|
|
if ((Directory.GetFiles(dir).Length + Directory.GetDirectories(dir).Length) == 0) {
|
|
Console.WriteLine(" skipped (0 files)");
|
|
continue;
|
|
}
|
|
if (name == "Library") {
|
|
if (!Directory.Exists(path + "\\Assets")) {
|
|
Console.WriteLine(" skipped (not a definite unity library folder)");
|
|
continue;
|
|
}
|
|
}
|
|
Console.Write(name == "Library" ? " y/n?" : "");
|
|
do {
|
|
char c = name == "Library" ? Console.ReadKey(true).KeyChar : 'y';
|
|
if (c == 'y') {
|
|
Directory.Delete(dir, true);
|
|
break;
|
|
} else if (c == 'n') {
|
|
break;
|
|
} else {
|
|
Console.WriteLine(string.Join("\n", Directory.EnumerateDirectories(dir).Select(_ => $" + {_}")));
|
|
Console.WriteLine(string.Join("\n", Directory.EnumerateFiles(dir).Select(_ => $" - {_}")));
|
|
}
|
|
} while (true);
|
|
}
|
|
} catch(Exception e) { Console.WriteLine("ERROR: " + e.Message); }
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
scanx(x);
|
|
return;
|
|
|
|
|
|
string path = @"C:\Users\filos\projects";
|
|
string[] ignore = ["node_modules", "bin", "obj", "Debug", "Build", ".vs"];
|
|
int scan(string path)
|
|
{
|
|
foreach (var dir in Directory.EnumerateDirectories(path)) {
|
|
var name = dir.Replace(path, "").Replace(@"\", "");
|
|
if (ignore.Contains(name))
|
|
continue;
|
|
if (name == ".git") {
|
|
Console.WriteLine(path);
|
|
git(path, "status");
|
|
Console.Write("y/n? ");
|
|
do {
|
|
char c = (char)Console.Read();
|
|
if (c == 'y') {
|
|
Console.Write(" origin [master]? ");
|
|
string t = Console.ReadLine() ?? "master";
|
|
if (string.IsNullOrEmpty(t))
|
|
t = "master";
|
|
|
|
git(path, "add .");
|
|
git(path, "commit -m \"backup commit\"");
|
|
git(path, "push origin " + t);
|
|
break;
|
|
} else if (c == 'n') {
|
|
break;
|
|
} else if (c > '0' && c < '9') {
|
|
return (48 - c);
|
|
}
|
|
} while (true);
|
|
} else {
|
|
int e = scan(dir);
|
|
if (e < 0)
|
|
return e+1;
|
|
}
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
scan(path);
|
|
return;
|
|
*/
|
|
|
|
List<char> Ignored = [ '\0', '\b' ];
|
|
LoggerService.Default = LogLevel.Error;
|
|
List<byte[]> History = [];
|
|
int historyCursor = -1;
|
|
ConsoleKeyInfo input;
|
|
bool useSyntaxHighlighting = false;
|
|
(int x, int y) cursor = (0, 0);
|
|
ConsoleCode code = ConsoleCode.Error;
|
|
Runner runner = new(new Options());
|
|
do {
|
|
Console.ForegroundColor = ConsoleColor.White;
|
|
MemoryStream stream = new MemoryStream();
|
|
Console.Write(" <: ");
|
|
cursor = Console.GetCursorPosition();
|
|
do {
|
|
if (useSyntaxHighlighting)
|
|
new ConsoleRenderer(stream).Render(cursor);
|
|
input = Console.ReadKey(true);
|
|
|
|
if (input.Modifiers == ConsoleModifiers.Control) {
|
|
if (input.Key == ConsoleKey.H) {
|
|
useSyntaxHighlighting = !useSyntaxHighlighting;
|
|
Console.Write($"\n #: {nameof(useSyntaxHighlighting)} = {useSyntaxHighlighting}\n <: ");
|
|
cursor = Console.GetCursorPosition();
|
|
}
|
|
if (input.Key == ConsoleKey.L) {
|
|
LoggerService.Default = LoggerService.Default < LogLevel.All ? LogLevel.All : LogLevel.Info;
|
|
Console.Write($"\n #: LogLevel = {LoggerService.Default}\n <: ");
|
|
cursor = Console.GetCursorPosition();
|
|
}
|
|
continue;
|
|
}
|
|
|
|
if (input.Key == ConsoleKey.LeftArrow) {
|
|
if (stream.Position > 0) {
|
|
stream.Position--;
|
|
Console.CursorLeft--;
|
|
}
|
|
continue;
|
|
}
|
|
|
|
if (input.Key == ConsoleKey.RightArrow) {
|
|
if (stream.Position < stream.Length) {
|
|
stream.Position++;
|
|
Console.CursorLeft++;
|
|
}
|
|
continue;
|
|
}
|
|
|
|
if (input.Key == ConsoleKey.UpArrow) {
|
|
historyCursor = Math.Min(History.Count - 1, historyCursor + 1);
|
|
byte[] bytes = History[historyCursor];
|
|
continue;
|
|
}
|
|
|
|
if (input.Key == ConsoleKey.DownArrow) {
|
|
historyCursor = Math.Max(0, historyCursor - 1);
|
|
byte[] bytes = History[historyCursor];
|
|
continue;
|
|
}
|
|
|
|
if (input.Key == ConsoleKey.Backspace && stream.Position > 0) {
|
|
Console.CursorLeft -= 1;
|
|
Console.Write(' ');
|
|
if (!useSyntaxHighlighting)
|
|
Console.CursorLeft -= 1;
|
|
//stream.Position--;
|
|
//stream.SetLength(stream.Position);
|
|
stream.Remove(stream.Position - 1, 1);
|
|
} else if (input.Key == ConsoleKey.Enter && input.Modifiers == ConsoleModifiers.Shift) {
|
|
if (!useSyntaxHighlighting)
|
|
Console.Write("\n : ");
|
|
stream.Insert(Encoding.Default.GetBytes(Environment.NewLine));
|
|
} else if (Ignored.IndexOf(input.KeyChar) < 0) {
|
|
if (!useSyntaxHighlighting)
|
|
Console.Write(input.KeyChar);
|
|
stream.Insert(Encoding.Default.GetBytes([input.KeyChar], 0, 1));
|
|
}
|
|
} while (input.Key != ConsoleKey.Enter || input.Modifiers == ConsoleModifiers.Shift);
|
|
try {
|
|
History.Insert(0, stream.GetBuffer());
|
|
Console.WriteLine();
|
|
runner.Run(stream);
|
|
stream.Dispose();
|
|
}
|
|
catch (QampException e) {
|
|
Console.ForegroundColor = ConsoleColor.Yellow;
|
|
Console.WriteLine($" !> {e.Message}");
|
|
if (e.StackTrace != null) {
|
|
Console.Write($" ! ");
|
|
Console.WriteLine(string.Join("\n ! ", e.StackTrace.Split('\n')));
|
|
}
|
|
}
|
|
catch (Exception e) {
|
|
Console.ForegroundColor = ConsoleColor.DarkRed;
|
|
Console.WriteLine($" !? {e.Message}");
|
|
if (e.StackTrace != null) {
|
|
Console.Write($" ! ");
|
|
Console.WriteLine(string.Join("\n ! ", e.StackTrace.Split('\n')));
|
|
}
|
|
}
|
|
} while(code != ConsoleCode.Exit);
|
|
|
|
public class Command
|
|
{
|
|
|
|
public class Parameters
|
|
{
|
|
|
|
}
|
|
|
|
public class Definition
|
|
{
|
|
public string Name { get; init; }
|
|
public string Alias { get; init; }
|
|
|
|
public class Parameter
|
|
{
|
|
public string Name { get; init; }
|
|
public string Alias { get; init; }
|
|
}
|
|
}
|
|
}
|
|
|
|
public class ArgumentAttribute(string name, string alias, string description)
|
|
{
|
|
public string Name { get; } = name;
|
|
public string Alias { get; } = alias;
|
|
public string Description { get; } = description;
|
|
} |