|
@@ -1,197 +1,542 @@
|
|
|
#nullable enable
|
|
#nullable enable
|
|
|
|
|
+using System.Collections.Concurrent;
|
|
|
using System.Diagnostics.CodeAnalysis;
|
|
using System.Diagnostics.CodeAnalysis;
|
|
|
|
|
|
|
|
namespace Terminal.Gui.App;
|
|
namespace Terminal.Gui.App;
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
|
-/// Interface for instances that provide backing functionality to static
|
|
|
|
|
-/// gateway class <see cref="Application"/>.
|
|
|
|
|
|
|
+/// Interface for instances that provide backing functionality to static
|
|
|
|
|
+/// gateway class <see cref="Application"/>.
|
|
|
/// </summary>
|
|
/// </summary>
|
|
|
public interface IApplication
|
|
public interface IApplication
|
|
|
{
|
|
{
|
|
|
|
|
+ #region Keyboard
|
|
|
|
|
+
|
|
|
/// <summary>
|
|
/// <summary>
|
|
|
- /// Handles recurring events. These are invoked on the main UI thread - allowing for
|
|
|
|
|
- /// safe updates to <see cref="View"/> instances.
|
|
|
|
|
|
|
+ /// Handles keyboard input and key bindings at the Application level.
|
|
|
/// </summary>
|
|
/// </summary>
|
|
|
- ITimedEvents? TimedEvents { get; }
|
|
|
|
|
|
|
+ /// <remarks>
|
|
|
|
|
+ /// <para>
|
|
|
|
|
+ /// Provides access to keyboard state, key bindings, and keyboard event handling. Set during <see cref="Init"/>.
|
|
|
|
|
+ /// </para>
|
|
|
|
|
+ /// </remarks>
|
|
|
|
|
+ IKeyboard Keyboard { get; set; }
|
|
|
|
|
+
|
|
|
|
|
+ #endregion Keyboard
|
|
|
|
|
+
|
|
|
|
|
+ #region Mouse
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
|
- /// Handles grabbing the mouse (only a single <see cref="View"/> can grab the mouse at once).
|
|
|
|
|
|
|
+ /// Handles mouse event state and processing.
|
|
|
/// </summary>
|
|
/// </summary>
|
|
|
- IMouseGrabHandler MouseGrabHandler { get; set; }
|
|
|
|
|
|
|
+ /// <remarks>
|
|
|
|
|
+ /// <para>
|
|
|
|
|
+ /// Provides access to mouse state, mouse grabbing, and mouse event handling. Set during <see cref="Init"/>.
|
|
|
|
|
+ /// </para>
|
|
|
|
|
+ /// </remarks>
|
|
|
|
|
+ IMouse Mouse { get; set; }
|
|
|
|
|
+
|
|
|
|
|
+ #endregion Mouse
|
|
|
|
|
+
|
|
|
|
|
+ #region Initialization and Shutdown
|
|
|
|
|
|
|
|
/// <summary>Initializes a new instance of <see cref="Terminal.Gui"/> Application.</summary>
|
|
/// <summary>Initializes a new instance of <see cref="Terminal.Gui"/> Application.</summary>
|
|
|
- /// <para>Call this method once per instance (or after <see cref="Shutdown"/> has been called).</para>
|
|
|
|
|
- /// <para>
|
|
|
|
|
- /// This function loads the right <see cref="IConsoleDriver"/> for the platform, Creates a <see cref="Toplevel"/>. and
|
|
|
|
|
- /// assigns it to <see cref="Application.Top"/>
|
|
|
|
|
- /// </para>
|
|
|
|
|
- /// <para>
|
|
|
|
|
- /// <see cref="Shutdown"/> must be called when the application is closing (typically after
|
|
|
|
|
- /// <see cref="Run{T}"/> has returned) to ensure resources are cleaned up and
|
|
|
|
|
- /// terminal settings
|
|
|
|
|
- /// restored.
|
|
|
|
|
- /// </para>
|
|
|
|
|
- /// <para>
|
|
|
|
|
- /// The <see cref="Run{T}"/> function combines
|
|
|
|
|
- /// <see cref="Init(IConsoleDriver,string)"/> and <see cref="Run(Toplevel, Func{Exception, bool})"/>
|
|
|
|
|
- /// into a single
|
|
|
|
|
- /// call. An application cam use <see cref="Run{T}"/> without explicitly calling
|
|
|
|
|
- /// <see cref="Init(IConsoleDriver,string)"/>.
|
|
|
|
|
- /// </para>
|
|
|
|
|
/// <param name="driver">
|
|
/// <param name="driver">
|
|
|
- /// The <see cref="IConsoleDriver"/> to use. If neither <paramref name="driver"/> or
|
|
|
|
|
|
|
+ /// The <see cref="IDriver"/> to use. If neither <paramref name="driver"/> or
|
|
|
/// <paramref name="driverName"/> are specified the default driver for the platform will be used.
|
|
/// <paramref name="driverName"/> are specified the default driver for the platform will be used.
|
|
|
/// </param>
|
|
/// </param>
|
|
|
/// <param name="driverName">
|
|
/// <param name="driverName">
|
|
|
- /// The short name (e.g. "net", "windows", "ansi", "fake", or "curses") of the
|
|
|
|
|
- /// <see cref="IConsoleDriver"/> to use. If neither <paramref name="driver"/> or <paramref name="driverName"/> are
|
|
|
|
|
|
|
+ /// The short name (e.g. "dotnet", "windows", "unix", or "fake") of the
|
|
|
|
|
+ /// <see cref="IDriver"/> to use. If neither <paramref name="driver"/> or <paramref name="driverName"/> are
|
|
|
/// specified the default driver for the platform will be used.
|
|
/// specified the default driver for the platform will be used.
|
|
|
/// </param>
|
|
/// </param>
|
|
|
|
|
+ /// <remarks>
|
|
|
|
|
+ /// <para>Call this method once per instance (or after <see cref="Shutdown"/> has been called).</para>
|
|
|
|
|
+ /// <para>
|
|
|
|
|
+ /// This function loads the right <see cref="IDriver"/> for the platform, creates a main loop coordinator,
|
|
|
|
|
+ /// initializes keyboard and mouse handlers, and subscribes to driver events.
|
|
|
|
|
+ /// </para>
|
|
|
|
|
+ /// <para>
|
|
|
|
|
+ /// <see cref="Shutdown"/> must be called when the application is closing (typically after
|
|
|
|
|
+ /// <see cref="Run{T}"/> has returned) to ensure resources are cleaned up and terminal settings restored.
|
|
|
|
|
+ /// </para>
|
|
|
|
|
+ /// <para>
|
|
|
|
|
+ /// The <see cref="Run{T}"/> function combines <see cref="Init(IDriver,string)"/> and
|
|
|
|
|
+ /// <see cref="Run(Toplevel, Func{Exception, bool})"/> into a single call. An application can use
|
|
|
|
|
+ /// <see cref="Run{T}"/> without explicitly calling <see cref="Init(IDriver,string)"/>.
|
|
|
|
|
+ /// </para>
|
|
|
|
|
+ /// </remarks>
|
|
|
[RequiresUnreferencedCode ("AOT")]
|
|
[RequiresUnreferencedCode ("AOT")]
|
|
|
[RequiresDynamicCode ("AOT")]
|
|
[RequiresDynamicCode ("AOT")]
|
|
|
- public void Init (IConsoleDriver? driver = null, string? driverName = null);
|
|
|
|
|
|
|
+ public void Init (IDriver? driver = null, string? driverName = null);
|
|
|
|
|
+
|
|
|
|
|
+ /// <summary>
|
|
|
|
|
+ /// This event is raised after the <see cref="Init"/> and <see cref="Shutdown"/> methods have been called.
|
|
|
|
|
+ /// </summary>
|
|
|
|
|
+ /// <remarks>
|
|
|
|
|
+ /// Intended to support unit tests that need to know when the application has been initialized.
|
|
|
|
|
+ /// </remarks>
|
|
|
|
|
+ public event EventHandler<EventArgs<bool>>? InitializedChanged;
|
|
|
|
|
+
|
|
|
|
|
+ /// <summary>Gets or sets whether the application has been initialized.</summary>
|
|
|
|
|
+ bool Initialized { get; set; }
|
|
|
|
|
+
|
|
|
|
|
+ /// <summary>Shutdown an application initialized with <see cref="Init"/>.</summary>
|
|
|
|
|
+ /// <remarks>
|
|
|
|
|
+ /// Shutdown must be called for every call to <see cref="Init"/> or
|
|
|
|
|
+ /// <see cref="Application.Run(Toplevel, Func{Exception, bool})"/> to ensure all resources are cleaned
|
|
|
|
|
+ /// up (Disposed) and terminal settings are restored.
|
|
|
|
|
+ /// </remarks>
|
|
|
|
|
+ public void Shutdown ();
|
|
|
|
|
+
|
|
|
|
|
+ /// <summary>
|
|
|
|
|
+ /// Resets the state of this instance.
|
|
|
|
|
+ /// </summary>
|
|
|
|
|
+ /// <param name="ignoreDisposed">If true, ignores disposed state checks during reset.</param>
|
|
|
|
|
+ /// <remarks>
|
|
|
|
|
+ /// <para>
|
|
|
|
|
+ /// Encapsulates all setting of initial state for Application; having this in a function like this ensures we
|
|
|
|
|
+ /// don't make mistakes in guaranteeing that the state of this singleton is deterministic when <see cref="Init"/>
|
|
|
|
|
+ /// starts running and after <see cref="Shutdown"/> returns.
|
|
|
|
|
+ /// </para>
|
|
|
|
|
+ /// <para>
|
|
|
|
|
+ /// IMPORTANT: Ensure all property/fields are reset here. See Init_ResetState_Resets_Properties unit test.
|
|
|
|
|
+ /// </para>
|
|
|
|
|
+ /// </remarks>
|
|
|
|
|
+ public void ResetState (bool ignoreDisposed = false);
|
|
|
|
|
+
|
|
|
|
|
+ #endregion Initialization and Shutdown
|
|
|
|
|
|
|
|
|
|
+ #region Begin->Run->Iteration->Stop->End
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
|
- /// Runs the application by creating a <see cref="Toplevel"/> object and calling
|
|
|
|
|
- /// <see cref="Run(Toplevel, Func{Exception, bool})"/>.
|
|
|
|
|
|
|
+ /// Building block API: Creates a <see cref="SessionToken"/> and prepares the provided <see cref="Toplevel"/> for
|
|
|
|
|
+ /// execution. Not usually called directly by applications. Use <see cref="Run(Toplevel, Func{Exception, bool})"/>
|
|
|
|
|
+ /// instead.
|
|
|
/// </summary>
|
|
/// </summary>
|
|
|
|
|
+ /// <returns>
|
|
|
|
|
+ /// The <see cref="SessionToken"/> that needs to be passed to the <see cref="End(SessionToken)"/> method upon
|
|
|
|
|
+ /// completion.
|
|
|
|
|
+ /// </returns>
|
|
|
|
|
+ /// <param name="toplevel">The <see cref="Toplevel"/> to prepare execution for.</param>
|
|
|
|
|
+ /// <remarks>
|
|
|
|
|
+ /// <para>
|
|
|
|
|
+ /// This method prepares the provided <see cref="Toplevel"/> for running. It adds this to the
|
|
|
|
|
+ /// list of <see cref="Toplevel"/>s, lays out the SubViews, focuses the first element, and draws the
|
|
|
|
|
+ /// <see cref="Toplevel"/> on the screen. This is usually followed by starting the main loop, and then the
|
|
|
|
|
+ /// <see cref="End(SessionToken)"/> method upon termination which will undo these changes.
|
|
|
|
|
+ /// </para>
|
|
|
|
|
+ /// <para>
|
|
|
|
|
+ /// Raises the <see cref="SessionBegun"/> event before returning.
|
|
|
|
|
+ /// </para>
|
|
|
|
|
+ /// </remarks>
|
|
|
|
|
+ public SessionToken Begin (Toplevel toplevel);
|
|
|
|
|
+
|
|
|
|
|
+ /// <summary>
|
|
|
|
|
+ /// Runs a new Session creating a <see cref="Toplevel"/> and calling <see cref="Begin(Toplevel)"/>. When the session is
|
|
|
|
|
+ /// stopped, <see cref="End(SessionToken)"/> will be called.
|
|
|
|
|
+ /// </summary>
|
|
|
|
|
+ /// <param name="errorHandler">Handler for any unhandled exceptions (resumes when returns true, rethrows when null).</param>
|
|
|
|
|
+ /// <param name="driver">
|
|
|
|
|
+ /// The driver name. If not specified the default driver for the platform will be used. Must be
|
|
|
|
|
+ /// <see langword="null"/> if <see cref="Init"/> has already been called.
|
|
|
|
|
+ /// </param>
|
|
|
|
|
+ /// <returns>The created <see cref="Toplevel"/>. The caller is responsible for disposing this object.</returns>
|
|
|
/// <remarks>
|
|
/// <remarks>
|
|
|
/// <para>Calling <see cref="Init"/> first is not needed as this function will initialize the application.</para>
|
|
/// <para>Calling <see cref="Init"/> first is not needed as this function will initialize the application.</para>
|
|
|
/// <para>
|
|
/// <para>
|
|
|
- /// <see cref="Shutdown"/> must be called when the application is closing (typically after Run> has returned) to
|
|
|
|
|
|
|
+ /// <see cref="Shutdown"/> must be called when the application is closing (typically after Run has returned) to
|
|
|
/// ensure resources are cleaned up and terminal settings restored.
|
|
/// ensure resources are cleaned up and terminal settings restored.
|
|
|
/// </para>
|
|
/// </para>
|
|
|
/// <para>
|
|
/// <para>
|
|
|
/// The caller is responsible for disposing the object returned by this method.
|
|
/// The caller is responsible for disposing the object returned by this method.
|
|
|
/// </para>
|
|
/// </para>
|
|
|
/// </remarks>
|
|
/// </remarks>
|
|
|
- /// <returns>The created <see cref="Toplevel"/> object. The caller is responsible for disposing this object.</returns>
|
|
|
|
|
[RequiresUnreferencedCode ("AOT")]
|
|
[RequiresUnreferencedCode ("AOT")]
|
|
|
[RequiresDynamicCode ("AOT")]
|
|
[RequiresDynamicCode ("AOT")]
|
|
|
- public Toplevel Run (Func<Exception, bool>? errorHandler = null, IConsoleDriver? driver = null);
|
|
|
|
|
|
|
+ public Toplevel Run (Func<Exception, bool>? errorHandler = null, string? driver = null);
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
|
- /// Runs the application by creating a <see cref="Toplevel"/>-derived object of type <c>T</c> and calling
|
|
|
|
|
- /// <see cref="Run(Toplevel, Func{Exception, bool})"/>.
|
|
|
|
|
|
|
+ /// Runs a new Session creating a <see cref="Toplevel"/>-derived object of type <typeparamref name="TView"/>
|
|
|
|
|
+ /// and calling <see cref="Run(Toplevel, Func{Exception, bool})"/>. When the session is stopped,
|
|
|
|
|
+ /// <see cref="End(SessionToken)"/> will be called.
|
|
|
/// </summary>
|
|
/// </summary>
|
|
|
|
|
+ /// <typeparam name="TView">The type of <see cref="Toplevel"/> to create and run.</typeparam>
|
|
|
|
|
+ /// <param name="errorHandler">Handler for any unhandled exceptions (resumes when returns true, rethrows when null).</param>
|
|
|
|
|
+ /// <param name="driver">
|
|
|
|
|
+ /// The driver name. If not specified the default driver for the platform will be used. Must be
|
|
|
|
|
+ /// <see langword="null"/> if <see cref="Init"/> has already been called.
|
|
|
|
|
+ /// </param>
|
|
|
|
|
+ /// <returns>The created <typeparamref name="TView"/> object. The caller is responsible for disposing this object.</returns>
|
|
|
/// <remarks>
|
|
/// <remarks>
|
|
|
- /// <para>Calling <see cref="Init"/> first is not needed as this function will initialize the application.</para>
|
|
|
|
|
/// <para>
|
|
/// <para>
|
|
|
- /// <see cref="Shutdown"/> must be called when the application is closing (typically after Run> has returned) to
|
|
|
|
|
|
|
+ /// This method is used to start processing events for the main application, but it is also used to run other
|
|
|
|
|
+ /// modal <see cref="View"/>s such as <see cref="Dialog"/> boxes.
|
|
|
|
|
+ /// </para>
|
|
|
|
|
+ /// <para>
|
|
|
|
|
+ /// To make <see cref="Run(Toplevel, Func{Exception, bool})"/> stop execution, call
|
|
|
|
|
+ /// <see cref="RequestStop()"/> or <see cref="RequestStop(Toplevel)"/>.
|
|
|
|
|
+ /// </para>
|
|
|
|
|
+ /// <para>
|
|
|
|
|
+ /// Calling <see cref="Run(Toplevel, Func{Exception, bool})"/> is equivalent to calling
|
|
|
|
|
+ /// <see cref="Begin(Toplevel)"/>, followed by starting the main loop, and then calling
|
|
|
|
|
+ /// <see cref="End(SessionToken)"/>.
|
|
|
|
|
+ /// </para>
|
|
|
|
|
+ /// <para>
|
|
|
|
|
+ /// When using <see cref="Run{T}"/> or <see cref="Run(Func{Exception, bool}, string)"/>,
|
|
|
|
|
+ /// <see cref="Init"/> will be called automatically.
|
|
|
|
|
+ /// </para>
|
|
|
|
|
+ /// <para>
|
|
|
|
|
+ /// In RELEASE builds: When <paramref name="errorHandler"/> is <see langword="null"/> any exceptions will be
|
|
|
|
|
+ /// rethrown. Otherwise, <paramref name="errorHandler"/> will be called. If <paramref name="errorHandler"/>
|
|
|
|
|
+ /// returns <see langword="true"/> the main loop will resume; otherwise this method will exit.
|
|
|
|
|
+ /// </para>
|
|
|
|
|
+ /// <para>
|
|
|
|
|
+ /// <see cref="Shutdown"/> must be called when the application is closing (typically after Run has returned) to
|
|
|
/// ensure resources are cleaned up and terminal settings restored.
|
|
/// ensure resources are cleaned up and terminal settings restored.
|
|
|
/// </para>
|
|
/// </para>
|
|
|
/// <para>
|
|
/// <para>
|
|
|
|
|
+ /// In RELEASE builds: When <paramref name="errorHandler"/> is <see langword="null"/> any exceptions will be
|
|
|
|
|
+ /// rethrown. Otherwise, <paramref name="errorHandler"/> will be called. If <paramref name="errorHandler"/>
|
|
|
|
|
+ /// returns <see langword="true"/> the main loop will resume; otherwise this method will exit.
|
|
|
|
|
+ /// </para>
|
|
|
|
|
+ /// <para>
|
|
|
/// The caller is responsible for disposing the object returned by this method.
|
|
/// The caller is responsible for disposing the object returned by this method.
|
|
|
/// </para>
|
|
/// </para>
|
|
|
/// </remarks>
|
|
/// </remarks>
|
|
|
- /// <param name="errorHandler"></param>
|
|
|
|
|
- /// <param name="driver">
|
|
|
|
|
- /// The <see cref="IConsoleDriver"/> to use. If not specified the default driver for the platform will
|
|
|
|
|
- /// be used ( <see cref="WindowsDriver"/>, <see cref="CursesDriver"/>, or <see cref="NetDriver"/>). Must be
|
|
|
|
|
- /// <see langword="null"/> if <see cref="Init"/> has already been called.
|
|
|
|
|
- /// </param>
|
|
|
|
|
- /// <returns>The created T object. The caller is responsible for disposing this object.</returns>
|
|
|
|
|
[RequiresUnreferencedCode ("AOT")]
|
|
[RequiresUnreferencedCode ("AOT")]
|
|
|
[RequiresDynamicCode ("AOT")]
|
|
[RequiresDynamicCode ("AOT")]
|
|
|
- public T Run<T> (Func<Exception, bool>? errorHandler = null, IConsoleDriver? driver = null)
|
|
|
|
|
- where T : Toplevel, new ();
|
|
|
|
|
|
|
+ public TView Run<TView> (Func<Exception, bool>? errorHandler = null, string? driver = null)
|
|
|
|
|
+ where TView : Toplevel, new ();
|
|
|
|
|
|
|
|
- /// <summary>Runs the Application using the provided <see cref="Toplevel"/> view.</summary>
|
|
|
|
|
|
|
+ /// <summary>
|
|
|
|
|
+ /// Runs a new Session using the provided <see cref="Toplevel"/> view and calling
|
|
|
|
|
+ /// <see cref="Run(Toplevel, Func{Exception, bool})"/>.
|
|
|
|
|
+ /// When the session is stopped, <see cref="End(SessionToken)"/> will be called..
|
|
|
|
|
+ /// </summary>
|
|
|
|
|
+ /// <param name="view">The <see cref="Toplevel"/> to run as a modal.</param>
|
|
|
|
|
+ /// <param name="errorHandler">Handler for any unhandled exceptions (resumes when returns true, rethrows when null).</param>
|
|
|
/// <remarks>
|
|
/// <remarks>
|
|
|
/// <para>
|
|
/// <para>
|
|
|
/// This method is used to start processing events for the main application, but it is also used to run other
|
|
/// This method is used to start processing events for the main application, but it is also used to run other
|
|
|
/// modal <see cref="View"/>s such as <see cref="Dialog"/> boxes.
|
|
/// modal <see cref="View"/>s such as <see cref="Dialog"/> boxes.
|
|
|
/// </para>
|
|
/// </para>
|
|
|
/// <para>
|
|
/// <para>
|
|
|
- /// To make a <see cref="Run(Toplevel,System.Func{System.Exception,bool})"/> stop execution, call
|
|
|
|
|
- /// <see cref="Application.RequestStop"/>.
|
|
|
|
|
|
|
+ /// To make <see cref="Run(Toplevel, Func{Exception, bool})"/> stop execution, call
|
|
|
|
|
+ /// <see cref="RequestStop()"/> or <see cref="RequestStop(Toplevel)"/>.
|
|
|
/// </para>
|
|
/// </para>
|
|
|
/// <para>
|
|
/// <para>
|
|
|
- /// Calling <see cref="Run(Toplevel,System.Func{System.Exception,bool})"/> is equivalent to calling
|
|
|
|
|
- /// <see cref="Application.Begin(Toplevel)"/>, followed by <see cref="Application.RunLoop(RunState)"/>, and then calling
|
|
|
|
|
- /// <see cref="Application.End(RunState)"/>.
|
|
|
|
|
|
|
+ /// Calling <see cref="Run(Toplevel, Func{Exception, bool})"/> is equivalent to calling
|
|
|
|
|
+ /// <see cref="Begin(Toplevel)"/>, followed by starting the main loop, and then calling
|
|
|
|
|
+ /// <see cref="End(SessionToken)"/>.
|
|
|
/// </para>
|
|
/// </para>
|
|
|
/// <para>
|
|
/// <para>
|
|
|
- /// Alternatively, to have a program control the main loop and process events manually, call
|
|
|
|
|
- /// <see cref="Application.Begin(Toplevel)"/> to set things up manually and then repeatedly call
|
|
|
|
|
- /// <see cref="Application.RunLoop(RunState)"/> with the wait parameter set to false. By doing this the
|
|
|
|
|
- /// <see cref="Application.RunLoop(RunState)"/> method will only process any pending events, timers handlers and then
|
|
|
|
|
- /// return control immediately.
|
|
|
|
|
- /// </para>
|
|
|
|
|
- /// <para>When using <see cref="Run{T}"/> or
|
|
|
|
|
- /// <see cref="Run(System.Func{System.Exception,bool},IConsoleDriver)"/>
|
|
|
|
|
|
|
+ /// When using <see cref="Run{T}"/> or <see cref="Run(Func{Exception, bool}, string)"/>,
|
|
|
/// <see cref="Init"/> will be called automatically.
|
|
/// <see cref="Init"/> will be called automatically.
|
|
|
/// </para>
|
|
/// </para>
|
|
|
/// <para>
|
|
/// <para>
|
|
|
- /// RELEASE builds only: When <paramref name="errorHandler"/> is <see langword="null"/> any exceptions will be
|
|
|
|
|
- /// rethrown. Otherwise, if <paramref name="errorHandler"/> will be called. If <paramref name="errorHandler"/>
|
|
|
|
|
- /// returns <see langword="true"/> the <see cref="Application.RunLoop(RunState)"/> will resume; otherwise this method will
|
|
|
|
|
- /// exit.
|
|
|
|
|
|
|
+ /// <see cref="Shutdown"/> must be called when the application is closing (typically after Run has returned) to
|
|
|
|
|
+ /// ensure resources are cleaned up and terminal settings restored.
|
|
|
|
|
+ /// </para>
|
|
|
|
|
+ /// <para>
|
|
|
|
|
+ /// In RELEASE builds: When <paramref name="errorHandler"/> is <see langword="null"/> any exceptions will be
|
|
|
|
|
+ /// rethrown. Otherwise, <paramref name="errorHandler"/> will be called. If <paramref name="errorHandler"/>
|
|
|
|
|
+ /// returns <see langword="true"/> the main loop will resume; otherwise this method will exit.
|
|
|
|
|
+ /// </para>
|
|
|
|
|
+ /// <para>
|
|
|
|
|
+ /// The caller is responsible for disposing the object returned by this method.
|
|
|
/// </para>
|
|
/// </para>
|
|
|
/// </remarks>
|
|
/// </remarks>
|
|
|
- /// <param name="view">The <see cref="Toplevel"/> to run as a modal.</param>
|
|
|
|
|
- /// <param name="errorHandler">
|
|
|
|
|
- /// RELEASE builds only: Handler for any unhandled exceptions (resumes when returns true,
|
|
|
|
|
- /// rethrows when null).
|
|
|
|
|
- /// </param>
|
|
|
|
|
public void Run (Toplevel view, Func<Exception, bool>? errorHandler = null);
|
|
public void Run (Toplevel view, Func<Exception, bool>? errorHandler = null);
|
|
|
|
|
|
|
|
- /// <summary>Shutdown an application initialized with <see cref="Init"/>.</summary>
|
|
|
|
|
|
|
+ /// <summary>
|
|
|
|
|
+ /// Raises the <see cref="Iteration"/> event.
|
|
|
|
|
+ /// </summary>
|
|
|
/// <remarks>
|
|
/// <remarks>
|
|
|
- /// Shutdown must be called for every call to <see cref="Init"/> or
|
|
|
|
|
- /// <see cref="Application.Run(Toplevel, Func{Exception, bool})"/> to ensure all resources are cleaned
|
|
|
|
|
- /// up (Disposed)
|
|
|
|
|
- /// and terminal settings are restored.
|
|
|
|
|
|
|
+ /// This is called once per main loop iteration, before processing input, timeouts, or rendering.
|
|
|
/// </remarks>
|
|
/// </remarks>
|
|
|
- public void Shutdown ();
|
|
|
|
|
|
|
+ public void RaiseIteration ();
|
|
|
|
|
+
|
|
|
|
|
+ /// <summary>This event is raised on each iteration of the main loop.</summary>
|
|
|
|
|
+ /// <remarks>
|
|
|
|
|
+ /// <para>
|
|
|
|
|
+ /// This event is raised before input processing, timeout callbacks, and rendering occur each iteration.
|
|
|
|
|
+ /// </para>
|
|
|
|
|
+ /// <para>See also <see cref="AddTimeout"/> and <see cref="TimedEvents"/>.</para>
|
|
|
|
|
+ /// </remarks>
|
|
|
|
|
+ public event EventHandler<IterationEventArgs>? Iteration;
|
|
|
|
|
+
|
|
|
|
|
+ /// <summary>Runs <paramref name="action"/> on the main UI loop thread.</summary>
|
|
|
|
|
+ /// <param name="action">The action to be invoked on the main processing thread.</param>
|
|
|
|
|
+ /// <remarks>
|
|
|
|
|
+ /// <para>
|
|
|
|
|
+ /// If called from the main thread, the action is executed immediately. Otherwise, it is queued via
|
|
|
|
|
+ /// <see cref="AddTimeout"/> with <see cref="TimeSpan.Zero"/> and will be executed on the next main loop
|
|
|
|
|
+ /// iteration.
|
|
|
|
|
+ /// </para>
|
|
|
|
|
+ /// </remarks>
|
|
|
|
|
+ void Invoke (Action action);
|
|
|
|
|
+
|
|
|
|
|
+ /// <summary>
|
|
|
|
|
+ /// Building block API: Ends a Session and completes the execution of a <see cref="Toplevel"/> that was started with
|
|
|
|
|
+ /// <see cref="Begin(Toplevel)"/>. Not usually called directly by applications.
|
|
|
|
|
+ /// <see cref="Run(Toplevel, Func{Exception, bool})"/>
|
|
|
|
|
+ /// will automatically call this method when the session is stopped.
|
|
|
|
|
+ /// </summary>
|
|
|
|
|
+ /// <param name="sessionToken">The <see cref="SessionToken"/> returned by the <see cref="Begin(Toplevel)"/> method.</param>
|
|
|
|
|
+ /// <remarks>
|
|
|
|
|
+ /// <para>
|
|
|
|
|
+ /// This method removes the <see cref="Toplevel"/> from the stack, raises the <see cref="SessionEnded"/>
|
|
|
|
|
+ /// event, and disposes the <paramref name="sessionToken"/>.
|
|
|
|
|
+ /// </para>
|
|
|
|
|
+ /// </remarks>
|
|
|
|
|
+ public void End (SessionToken sessionToken);
|
|
|
|
|
|
|
|
- /// <summary>Stops the provided <see cref="Toplevel"/>, causing or the <paramref name="top"/> if provided.</summary>
|
|
|
|
|
- /// <param name="top">The <see cref="Toplevel"/> to stop.</param>
|
|
|
|
|
|
|
+ /// <summary>Requests that the currently running Session stop. The Session will stop after the current iteration completes.</summary>
|
|
|
/// <remarks>
|
|
/// <remarks>
|
|
|
- /// <para>This will cause <see cref="Application.Run(Toplevel, Func{Exception, bool})"/> to return.</para>
|
|
|
|
|
|
|
+ /// <para>This will cause <see cref="Run(Toplevel, Func{Exception, bool})"/> to return.</para>
|
|
|
|
|
+ /// <para>
|
|
|
|
|
+ /// This is equivalent to calling <see cref="RequestStop(Toplevel)"/> with <see cref="Top"/> as the parameter.
|
|
|
|
|
+ /// </para>
|
|
|
|
|
+ /// </remarks>
|
|
|
|
|
+ void RequestStop ();
|
|
|
|
|
+
|
|
|
|
|
+ /// <summary>Requests that the currently running Session stop. The Session will stop after the current iteration completes.</summary>
|
|
|
|
|
+ /// <param name="top">
|
|
|
|
|
+ /// The <see cref="Toplevel"/> to stop. If <see langword="null"/>, stops the currently running <see cref="Top"/>.
|
|
|
|
|
+ /// </param>
|
|
|
|
|
+ /// <remarks>
|
|
|
|
|
+ /// <para>This will cause <see cref="Run(Toplevel, Func{Exception, bool})"/> to return.</para>
|
|
|
/// <para>
|
|
/// <para>
|
|
|
/// Calling <see cref="RequestStop(Toplevel)"/> is equivalent to setting the <see cref="Toplevel.Running"/>
|
|
/// Calling <see cref="RequestStop(Toplevel)"/> is equivalent to setting the <see cref="Toplevel.Running"/>
|
|
|
- /// property on the currently running <see cref="Toplevel"/> to false.
|
|
|
|
|
|
|
+ /// property on the specified <see cref="Toplevel"/> to <see langword="false"/>.
|
|
|
/// </para>
|
|
/// </para>
|
|
|
/// </remarks>
|
|
/// </remarks>
|
|
|
void RequestStop (Toplevel? top);
|
|
void RequestStop (Toplevel? top);
|
|
|
|
|
|
|
|
- /// <summary>Runs <paramref name="action"/> on the main UI loop thread</summary>
|
|
|
|
|
- /// <param name="action">the action to be invoked on the main processing thread.</param>
|
|
|
|
|
- void Invoke (Action action);
|
|
|
|
|
|
|
+ /// <summary>
|
|
|
|
|
+ /// Set to <see langword="true"/> to cause the session to stop running after first iteration.
|
|
|
|
|
+ /// </summary>
|
|
|
|
|
+ /// <remarks>
|
|
|
|
|
+ /// <para>
|
|
|
|
|
+ /// Used primarily for unit testing. When <see langword="true"/>, <see cref="End"/> will be called
|
|
|
|
|
+ /// automatically after the first main loop iteration.
|
|
|
|
|
+ /// </para>
|
|
|
|
|
+ /// </remarks>
|
|
|
|
|
+ bool StopAfterFirstIteration { get; set; }
|
|
|
|
|
+
|
|
|
|
|
+ /// <summary>
|
|
|
|
|
+ /// Raised when <see cref="Begin(Toplevel)"/> has been called and has created a new <see cref="SessionToken"/>.
|
|
|
|
|
+ /// </summary>
|
|
|
|
|
+ /// <remarks>
|
|
|
|
|
+ /// If <see cref="StopAfterFirstIteration"/> is <see langword="true"/>, callers to <see cref="Begin(Toplevel)"/>
|
|
|
|
|
+ /// must also subscribe to <see cref="SessionEnded"/> and manually dispose of the <see cref="SessionToken"/> token
|
|
|
|
|
+ /// when the application is done.
|
|
|
|
|
+ /// </remarks>
|
|
|
|
|
+ public event EventHandler<SessionTokenEventArgs>? SessionBegun;
|
|
|
|
|
+
|
|
|
|
|
+ /// <summary>
|
|
|
|
|
+ /// Raised when <see cref="End(SessionToken)"/> was called and the session is stopping. The event args contain a
|
|
|
|
|
+ /// reference to the <see cref="Toplevel"/>
|
|
|
|
|
+ /// that was active during the session. This can be used to ensure the Toplevel is disposed of properly.
|
|
|
|
|
+ /// </summary>
|
|
|
|
|
+ /// <remarks>
|
|
|
|
|
+ /// If <see cref="StopAfterFirstIteration"/> is <see langword="true"/>, callers to <see cref="Begin(Toplevel)"/>
|
|
|
|
|
+ /// must also subscribe to <see cref="SessionEnded"/> and manually dispose of the <see cref="SessionToken"/> token
|
|
|
|
|
+ /// when the application is done.
|
|
|
|
|
+ /// </remarks>
|
|
|
|
|
+ public event EventHandler<ToplevelEventArgs>? SessionEnded;
|
|
|
|
|
+
|
|
|
|
|
+ #endregion Begin->Run->Iteration->Stop->End
|
|
|
|
|
+
|
|
|
|
|
+ #region Toplevel Management
|
|
|
|
|
+
|
|
|
|
|
+ /// <summary>Gets or sets the current Toplevel.</summary>
|
|
|
|
|
+ /// <remarks>
|
|
|
|
|
+ /// <para>
|
|
|
|
|
+ /// This is set by <see cref="Begin(Toplevel)"/> and cleared by <see cref="End(SessionToken)"/>.
|
|
|
|
|
+ /// </para>
|
|
|
|
|
+ /// </remarks>
|
|
|
|
|
+ Toplevel? Top { get; set; }
|
|
|
|
|
+
|
|
|
|
|
+ /// <summary>Gets the stack of all Toplevels.</summary>
|
|
|
|
|
+ /// <remarks>
|
|
|
|
|
+ /// <para>
|
|
|
|
|
+ /// Toplevels are added to this stack by <see cref="Begin(Toplevel)"/> and removed by
|
|
|
|
|
+ /// <see cref="End(SessionToken)"/>.
|
|
|
|
|
+ /// </para>
|
|
|
|
|
+ /// </remarks>
|
|
|
|
|
+ ConcurrentStack<Toplevel> TopLevels { get; }
|
|
|
|
|
+
|
|
|
|
|
+ /// <summary>
|
|
|
|
|
+ /// Caches the Toplevel associated with the current Session.
|
|
|
|
|
+ /// </summary>
|
|
|
|
|
+ /// <remarks>
|
|
|
|
|
+ /// Used internally to optimize Toplevel state transitions.
|
|
|
|
|
+ /// </remarks>
|
|
|
|
|
+ Toplevel? CachedSessionTokenToplevel { get; set; }
|
|
|
|
|
+
|
|
|
|
|
+ #endregion Toplevel Management
|
|
|
|
|
+
|
|
|
|
|
+ #region Screen and Driver
|
|
|
|
|
+
|
|
|
|
|
+ /// <summary>Gets or sets the console driver being used.</summary>
|
|
|
|
|
+ /// <remarks>
|
|
|
|
|
+ /// <para>
|
|
|
|
|
+ /// Set by <see cref="Init"/> based on the driver parameter or platform default.
|
|
|
|
|
+ /// </para>
|
|
|
|
|
+ /// </remarks>
|
|
|
|
|
+ IDriver? Driver { get; set; }
|
|
|
|
|
+
|
|
|
|
|
+ /// <summary>
|
|
|
|
|
+ /// Gets or sets whether <see cref="Driver"/> will be forced to output only the 16 colors defined in
|
|
|
|
|
+ /// <see cref="ColorName16"/>. The default is <see langword="false"/>, meaning 24-bit (TrueColor) colors will be
|
|
|
|
|
+ /// output as long as the selected <see cref="IDriver"/> supports TrueColor.
|
|
|
|
|
+ /// </summary>
|
|
|
|
|
+ bool Force16Colors { get; set; }
|
|
|
|
|
+
|
|
|
|
|
+ /// <summary>
|
|
|
|
|
+ /// Forces the use of the specified driver (one of "fake", "dotnet", "windows", or "unix"). If not
|
|
|
|
|
+ /// specified, the driver is selected based on the platform.
|
|
|
|
|
+ /// </summary>
|
|
|
|
|
+ string ForceDriver { get; set; }
|
|
|
|
|
+
|
|
|
|
|
+ /// <summary>
|
|
|
|
|
+ /// Gets or sets the size of the screen. By default, this is the size of the screen as reported by the
|
|
|
|
|
+ /// <see cref="IDriver"/>.
|
|
|
|
|
+ /// </summary>
|
|
|
|
|
+ /// <remarks>
|
|
|
|
|
+ /// <para>
|
|
|
|
|
+ /// If the <see cref="IDriver"/> has not been initialized, this will return a default size of 2048x2048; useful
|
|
|
|
|
+ /// for unit tests.
|
|
|
|
|
+ /// </para>
|
|
|
|
|
+ /// </remarks>
|
|
|
|
|
+ Rectangle Screen { get; set; }
|
|
|
|
|
+
|
|
|
|
|
+ /// <summary>Raised when the terminal's size changed. The new size of the terminal is provided.</summary>
|
|
|
|
|
+ /// <remarks>
|
|
|
|
|
+ /// <para>
|
|
|
|
|
+ /// This event is raised when the driver detects a screen size change. The event provides the new screen
|
|
|
|
|
+ /// rectangle.
|
|
|
|
|
+ /// </para>
|
|
|
|
|
+ /// </remarks>
|
|
|
|
|
+ public event EventHandler<EventArgs<Rectangle>>? ScreenChanged;
|
|
|
|
|
+
|
|
|
|
|
+ /// <summary>
|
|
|
|
|
+ /// Gets or sets whether the screen will be cleared, and all Views redrawn, during the next Application iteration.
|
|
|
|
|
+ /// </summary>
|
|
|
|
|
+ /// <remarks>
|
|
|
|
|
+ /// <para>
|
|
|
|
|
+ /// This is typically set to <see langword="true"/> when a View's <see cref="View.Frame"/> changes and that view
|
|
|
|
|
+ /// has no SuperView (e.g. when <see cref="Top"/> is moved or resized).
|
|
|
|
|
+ /// </para>
|
|
|
|
|
+ /// <para>
|
|
|
|
|
+ /// Automatically reset to <see langword="false"/> after <see cref="LayoutAndDraw"/> processes it.
|
|
|
|
|
+ /// </para>
|
|
|
|
|
+ /// </remarks>
|
|
|
|
|
+ bool ClearScreenNextIteration { get; set; }
|
|
|
|
|
+
|
|
|
|
|
+ /// <summary>
|
|
|
|
|
+ /// Collection of sixel images to write out to screen when updating.
|
|
|
|
|
+ /// Only add to this collection if you are sure terminal supports sixel format.
|
|
|
|
|
+ /// </summary>
|
|
|
|
|
+ List<SixelToRender> Sixel { get; }
|
|
|
|
|
+
|
|
|
|
|
+ #endregion Screen and Driver
|
|
|
|
|
+
|
|
|
|
|
+ #region Layout and Drawing
|
|
|
|
|
+
|
|
|
|
|
+ /// <summary>
|
|
|
|
|
+ /// Causes any Toplevels that need layout to be laid out, then draws any Toplevels that need display. Only Views
|
|
|
|
|
+ /// that need to be laid out (see <see cref="View.NeedsLayout"/>) will be laid out. Only Views that need to be drawn
|
|
|
|
|
+ /// (see <see cref="View.NeedsDraw"/>) will be drawn.
|
|
|
|
|
+ /// </summary>
|
|
|
|
|
+ /// <param name="forceRedraw">
|
|
|
|
|
+ /// If <see langword="true"/> the entire View hierarchy will be redrawn. The default is <see langword="false"/> and
|
|
|
|
|
+ /// should only be overridden for testing.
|
|
|
|
|
+ /// </param>
|
|
|
|
|
+ /// <remarks>
|
|
|
|
|
+ /// <para>
|
|
|
|
|
+ /// This method is called automatically each main loop iteration when any views need layout or drawing.
|
|
|
|
|
+ /// </para>
|
|
|
|
|
+ /// <para>
|
|
|
|
|
+ /// If <see cref="ClearScreenNextIteration"/> is <see langword="true"/>, the screen will be cleared before
|
|
|
|
|
+ /// drawing and the flag will be reset to <see langword="false"/>.
|
|
|
|
|
+ /// </para>
|
|
|
|
|
+ /// </remarks>
|
|
|
|
|
+ public void LayoutAndDraw (bool forceRedraw = false);
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
|
- /// <see langword="true"/> if implementation is 'old'. <see langword="false"/> if implementation
|
|
|
|
|
- /// is cutting edge.
|
|
|
|
|
|
|
+ /// Calls <see cref="View.PositionCursor"/> on the most focused view.
|
|
|
/// </summary>
|
|
/// </summary>
|
|
|
- bool IsLegacy { get; }
|
|
|
|
|
-
|
|
|
|
|
|
|
+ /// <remarks>
|
|
|
|
|
+ /// <para>Does nothing if there is no most focused view.</para>
|
|
|
|
|
+ /// <para>
|
|
|
|
|
+ /// If the most focused view is not visible within its superview, the cursor will be hidden.
|
|
|
|
|
+ /// </para>
|
|
|
|
|
+ /// </remarks>
|
|
|
|
|
+ /// <returns><see langword="true"/> if a view positioned the cursor and the position is visible.</returns>
|
|
|
|
|
+ public bool PositionCursor ();
|
|
|
|
|
+
|
|
|
|
|
+ #endregion Layout and Drawing
|
|
|
|
|
+
|
|
|
|
|
+ #region Navigation and Popover
|
|
|
|
|
+
|
|
|
|
|
+ /// <summary>Gets or sets the popover manager.</summary>
|
|
|
|
|
+ /// <remarks>
|
|
|
|
|
+ /// <para>
|
|
|
|
|
+ /// Manages application-level popover views. Initialized during <see cref="Init"/>.
|
|
|
|
|
+ /// </para>
|
|
|
|
|
+ /// </remarks>
|
|
|
|
|
+ ApplicationPopover? Popover { get; set; }
|
|
|
|
|
+
|
|
|
|
|
+ /// <summary>Gets or sets the navigation manager.</summary>
|
|
|
|
|
+ /// <remarks>
|
|
|
|
|
+ /// <para>
|
|
|
|
|
+ /// Manages focus navigation and tracking of the most focused view. Initialized during <see cref="Init"/>.
|
|
|
|
|
+ /// </para>
|
|
|
|
|
+ /// </remarks>
|
|
|
|
|
+ ApplicationNavigation? Navigation { get; set; }
|
|
|
|
|
+
|
|
|
|
|
+ #endregion Navigation and Popover
|
|
|
|
|
+
|
|
|
|
|
+ #region Timeouts
|
|
|
|
|
+
|
|
|
/// <summary>Adds a timeout to the application.</summary>
|
|
/// <summary>Adds a timeout to the application.</summary>
|
|
|
|
|
+ /// <param name="time">The time span to wait before invoking the callback.</param>
|
|
|
|
|
+ /// <param name="callback">
|
|
|
|
|
+ /// The callback to invoke. If it returns <see langword="true"/>, the timeout will be reset and repeat. If it
|
|
|
|
|
+ /// returns <see langword="false"/>, the timeout will stop and be removed.
|
|
|
|
|
+ /// </param>
|
|
|
|
|
+ /// <returns>
|
|
|
|
|
+ /// A token that can be used to stop the timeout by calling <see cref="RemoveTimeout(object)"/>.
|
|
|
|
|
+ /// </returns>
|
|
|
/// <remarks>
|
|
/// <remarks>
|
|
|
- /// When time specified passes, the callback will be invoked. If the callback returns true, the timeout will be
|
|
|
|
|
- /// reset, repeating the invocation. If it returns false, the timeout will stop and be removed. The returned value is a
|
|
|
|
|
- /// token that can be used to stop the timeout by calling <see cref="RemoveTimeout(object)"/>.
|
|
|
|
|
|
|
+ /// <para>
|
|
|
|
|
+ /// When the time specified passes, the callback will be invoked on the main UI thread.
|
|
|
|
|
+ /// </para>
|
|
|
/// </remarks>
|
|
/// </remarks>
|
|
|
object AddTimeout (TimeSpan time, Func<bool> callback);
|
|
object AddTimeout (TimeSpan time, Func<bool> callback);
|
|
|
|
|
|
|
|
- /// <summary>Removes a previously scheduled timeout</summary>
|
|
|
|
|
- /// <remarks>The token parameter is the value returned by <see cref="AddTimeout"/>.</remarks>
|
|
|
|
|
|
|
+ /// <summary>Removes a previously scheduled timeout.</summary>
|
|
|
|
|
+ /// <param name="token">The token returned by <see cref="AddTimeout"/>.</param>
|
|
|
/// <returns>
|
|
/// <returns>
|
|
|
- /// <see langword="true"/>
|
|
|
|
|
- /// if the timeout is successfully removed; otherwise,
|
|
|
|
|
- /// <see langword="false"/>
|
|
|
|
|
- /// .
|
|
|
|
|
- /// This method also returns
|
|
|
|
|
- /// <see langword="false"/>
|
|
|
|
|
- /// if the timeout is not found.</returns>
|
|
|
|
|
|
|
+ /// <see langword="true"/> if the timeout is successfully removed; otherwise, <see langword="false"/>.
|
|
|
|
|
+ /// This method also returns <see langword="false"/> if the timeout is not found.
|
|
|
|
|
+ /// </returns>
|
|
|
bool RemoveTimeout (object token);
|
|
bool RemoveTimeout (object token);
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
|
- /// Causes any Toplevels that need layout to be laid out. Then draws any Toplevels that need display. Only Views that need to be laid out (see <see cref="View.NeedsLayout"/>) will be laid out.
|
|
|
|
|
- /// Only Views that need to be drawn (see <see cref="View.NeedsDraw"/>) will be drawn.
|
|
|
|
|
|
|
+ /// Handles recurring events. These are invoked on the main UI thread - allowing for
|
|
|
|
|
+ /// safe updates to <see cref="View"/> instances.
|
|
|
/// </summary>
|
|
/// </summary>
|
|
|
- /// <param name="forceDraw">If <see langword="true"/> the entire View hierarchy will be redrawn. The default is <see langword="false"/> and should only be overriden for testing.</param>
|
|
|
|
|
- void LayoutAndDraw (bool forceDraw);
|
|
|
|
|
-}
|
|
|
|
|
|
|
+ /// <remarks>
|
|
|
|
|
+ /// <para>
|
|
|
|
|
+ /// Provides low-level access to the timeout management system. Most applications should use
|
|
|
|
|
+ /// <see cref="AddTimeout"/> and <see cref="RemoveTimeout"/> instead.
|
|
|
|
|
+ /// </para>
|
|
|
|
|
+ /// </remarks>
|
|
|
|
|
+ ITimedEvents? TimedEvents { get; }
|
|
|
|
|
+
|
|
|
|
|
+ #endregion Timeouts
|
|
|
|
|
+}
|