#nullable enable
using System.Diagnostics.CodeAnalysis;
namespace Terminal.Gui;
///
/// Interface for instances that provide backing functionality to static
/// gateway class .
///
public interface IApplication
{
/// Initializes a new instance of Application.
/// Call this method once per instance (or after has been called).
///
/// This function loads the right for the platform, Creates a . and
/// assigns it to
///
///
/// must be called when the application is closing (typically after
/// has returned) to ensure resources are cleaned up and
/// terminal settings
/// restored.
///
///
/// The function combines
/// and
/// into a single
/// call. An application cam use without explicitly calling
/// .
///
///
/// The to use. If neither or
/// are specified the default driver for the platform will be used.
///
///
/// The short name (e.g. "net", "windows", "ansi", "fake", or "curses") of the
/// to use. If neither or are
/// specified the default driver for the platform will be used.
///
[RequiresUnreferencedCode ("AOT")]
[RequiresDynamicCode ("AOT")]
public void Init (IConsoleDriver? driver = null, string? driverName = null);
///
/// Runs the application by creating a object and calling
/// .
///
///
/// Calling first is not needed as this function will initialize the application.
///
/// must be called when the application is closing (typically after Run> has returned) to
/// ensure resources are cleaned up and terminal settings restored.
///
///
/// The caller is responsible for disposing the object returned by this method.
///
///
/// The created object. The caller is responsible for disposing this object.
[RequiresUnreferencedCode ("AOT")]
[RequiresDynamicCode ("AOT")]
public Toplevel Run (Func? errorHandler = null, IConsoleDriver? driver = null);
///
/// Runs the application by creating a -derived object of type T and calling
/// .
///
///
/// Calling first is not needed as this function will initialize the application.
///
/// must be called when the application is closing (typically after Run> has returned) to
/// ensure resources are cleaned up and terminal settings restored.
///
///
/// The caller is responsible for disposing the object returned by this method.
///
///
///
///
/// The to use. If not specified the default driver for the platform will
/// be used ( , , or ). Must be
/// if has already been called.
///
/// The created T object. The caller is responsible for disposing this object.
[RequiresUnreferencedCode ("AOT")]
[RequiresDynamicCode ("AOT")]
public T Run (Func? errorHandler = null, IConsoleDriver? driver = null)
where T : Toplevel, new ();
/// Runs the Application using the provided view.
///
///
/// This method is used to start processing events for the main application, but it is also used to run other
/// modal s such as boxes.
///
///
/// To make a stop execution, call
/// .
///
///
/// Calling is equivalent to calling
/// , followed by , and then calling
/// .
///
///
/// Alternatively, to have a program control the main loop and process events manually, call
/// to set things up manually and then repeatedly call
/// with the wait parameter set to false. By doing this the
/// method will only process any pending events, timers, idle handlers and then
/// return control immediately.
///
/// When using or
///
/// will be called automatically.
///
///
/// RELEASE builds only: When is any exceptions will be
/// rethrown. Otherwise, if will be called. If
/// returns the will resume; otherwise this method will
/// exit.
///
///
/// The to run as a modal.
///
/// RELEASE builds only: Handler for any unhandled exceptions (resumes when returns true,
/// rethrows when null).
///
public void Run (Toplevel view, Func? errorHandler = null);
/// Shutdown an application initialized with .
///
/// Shutdown must be called for every call to or
/// to ensure all resources are cleaned
/// up (Disposed)
/// and terminal settings are restored.
///
public void Shutdown ();
/// Stops the provided , causing or the if provided.
/// The to stop.
///
/// This will cause to return.
///
/// Calling is equivalent to setting the
/// property on the currently running to false.
///
///
void RequestStop (Toplevel? top);
/// Runs on the main UI loop thread
/// the action to be invoked on the main processing thread.
void Invoke (Action action);
///
/// if implementation is 'old'. if implementation
/// is cutting edge.
///
bool IsLegacy { get; }
///
/// Adds specified idle handler function to main iteration processing. The handler function will be called
/// once per iteration of the main loop after other events have been handled.
///
void AddIdle (Func func);
/// Adds a timeout to the application.
///
/// 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 .
///
object AddTimeout (TimeSpan time, Func callback);
/// Removes a previously scheduled timeout
/// The token parameter is the value returned by .
///
///
/// if the timeout is successfully removed; otherwise,
///
/// .
/// This method also returns
///
/// if the timeout is not found.
bool RemoveTimeout (object token);
///
/// 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 ) will be laid out.
/// Only Views that need to be drawn (see ) will be drawn.
///
/// If the entire View hierarchy will be redrawn. The default is and should only be overriden for testing.
void LayoutAndDraw (bool forceDraw);
}