using Qrakhen.Qamp.Core; using Qrakhen.Qamp.Core.Execution; using Qrakhen.Qamp.Core.Logging; using System.Text; List Ignored = [ '\0', '\b' ]; LoggerService.Default = LogLevel.Error; List 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; if (e.InnerException != null) Console.WriteLine($" !? {e.InnerException.Message}"); 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; }