diff --git a/new/AutoItInterpreter/CommandLineInterface/InteractiveShell.cs b/new/AutoItInterpreter/CommandLineInterface/InteractiveShell.cs index 0d6f375..9d7a642 100644 --- a/new/AutoItInterpreter/CommandLineInterface/InteractiveShell.cs +++ b/new/AutoItInterpreter/CommandLineInterface/InteractiveShell.cs @@ -11,9 +11,11 @@ using Unknown6656.Imaging; using Unknown6656.Common; using Unknown6656.Generics; +using System.Threading.Tasks; namespace Unknown6656.AutoIt3.CLI; + public sealed class InteractiveShell : IDisposable { @@ -46,14 +48,29 @@ [ENTER] Execute current input [ARROW UP/DOWN] Select c private bool _isdisposed; + /// + /// Returns an enumeration of all currently active instances. + /// public static ConcurrentHashSet Instances { get; } = []; + /// + /// Returns the current history of content (represented by s), as well as the corresponding s. + /// public List<(ScriptToken[] Content, InteractiveShellStreamDirection Stream)> History { get; } = []; + /// + /// Returns a list of formatted textual suggestions for the auto-complete functionality of the interactive AutoIt shell. + /// public List<(ScriptToken[] Display, string Content)> Suggestions { get; } = []; + /// + /// Contains the current user-provided input. + /// public string CurrentInput { get; private set; } = ""; + /// + /// The current cursor position in characters from the left-hand bound. + /// public Index CurrentCursorPosition { get => _current_cursor_pos; @@ -65,20 +82,44 @@ private set } } + /// + /// The currently selected zero-based index of auto-completion suggestions. + /// public int CurrentSuggestionIndex { get; private set; } + /// + /// The current zero-based history scroll index. A larger history scroll index suggests a farther scrolling into the past. + /// public int HistoryScrollIndex { get; private set; } + /// + /// The current AutoIt interpreter instance. + /// public Interpreter Interpreter { get; } + /// + /// Indicates whether the current interactive shell is running. + /// public bool IsRunning { get; private set; } = true; + /// + /// Returns the main thread of the current instance of . + /// public AU3Thread Thread { get; } + /// + /// Returns the global associated with this interactive shell instance. + /// public VariableScope Variables { get; } + /// + /// Returns the global stack call frame. + /// public AU3CallFrame CallFrame { get; } + /// + /// Returns the currently typed (or ). + /// public ScriptToken? CurrentlyTypedToken { get @@ -91,6 +132,10 @@ public ScriptToken? CurrentlyTypedToken } + /// + /// Creates a new interactive shell instance using the given AutoIt interpreter. + /// + /// The AutoIt interpreter instance which shall be used by the interactive shell. public InteractiveShell(Interpreter interpreter) { Instances.Add(this); @@ -110,6 +155,7 @@ public void Dispose() GC.SuppressFinalize(this); } + /// private void Dispose(bool disposing) { if (!_isdisposed) @@ -126,6 +172,10 @@ private void Dispose(bool disposing) } } + /// + /// Initializes the interactive shell and returns whether the console is large enough for interactive usage (see ). + /// + /// Indication of successfull initialization. public bool Initialize() { if (WIDTH < MIN_WIDTH) @@ -145,6 +195,11 @@ public bool Initialize() return true; } + /// + /// Starts and runs the current interactive shell in a thread-blocking fashion. + /// + /// Consider using in order to run the interactive shell on an thread model. + /// public void Run() { if (Console.CursorTop > 0) @@ -770,12 +825,18 @@ private void RedrawThreadAndVariableWatchers() } + /// + /// Clears the history of the current interactive shell. + /// public void Clear() { History.Clear(); HistoryScrollIndex = 0; } + /// + /// Requests the interactive shell to be exited. + /// public void Exit() => IsRunning = false; private void ProcessInput() @@ -824,6 +885,9 @@ private void ProcessInput() } } + /// + /// Updates the list of auto-complete suggestions. + /// public void UpdateSuggestions() { OS os = NativeInterop.OperatingSystem; @@ -932,13 +996,29 @@ string to_dbg_str(Variant value) CurrentSuggestionIndex = Math.Min(CurrentSuggestionIndex, Suggestions.Count - 1); } + /// + /// Submits the given to be printed to the history while formatting it as and . + /// + /// The message to be printed to the interactive shell. public void SubmitPrint(string message) => History.Add((new[] { ScriptToken.FromString(message, TokenType.Comment) }, InteractiveShellStreamDirection.Output)); } +/// +/// An enumeration of known interactive shell stream directions. +/// public enum InteractiveShellStreamDirection { + /// + /// Represents the input stream, i.e. what the user enters into the interactive shell. + /// Input, + /// + /// Represents the output stream, e.g. result values of code executions. + /// Output, + /// + /// Represents the error stream, i.e. occurrences of exceptions and parsing errors. + /// Error, }