#nullable enable
using System.Collections.Concurrent;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
namespace Terminal.Gui.App;
///
/// Interface for instances that provide backing functionality to static
/// gateway class .
///
public interface IApplication
{
/// 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);
///
/// Gets or sets whether the screen will be cleared, and all Views redrawn, during the next Application iteration.
///
bool ClearScreenNextIteration { get; set; }
/// Gets or sets the console driver being used.
IConsoleDriver? Driver { get; set; }
///
/// Gets or sets whether will be forced to output only the 16 colors defined in
/// . The default is , meaning 24-bit (TrueColor) colors will be output
/// as long as the selected supports TrueColor.
///
bool Force16Colors { get; set; }
///
/// 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.
///
string ForceDriver { get; set; }
/// 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 driver name (e.g. "dotnet", "windows", "fake", or "unix") 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);
/// Gets or sets whether the application has been initialized.
bool Initialized { get; set; }
/// 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; }
///
/// Handles keyboard input and key bindings at the Application level.
///
IKeyboard Keyboard { get; set; }
///
/// 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.
///
public void LayoutAndDraw (bool forceRedraw = false);
///
/// Maximum number of iterations of the main loop (and hence draws)
/// to allow to occur per second. Defaults to which is
/// a 40ms sleep
/// after iteration (factoring in how long iteration took to run).
///
/// Note that not every iteration draws (see ).
/// Only affects v2 drivers.
///
///
ushort MaximumIterationsPerSecond { get; set; }
///
/// Handles mouse event state and processing.
///
IMouse Mouse { get; set; }
/// Gets or sets the navigation manager.
ApplicationNavigation? Navigation { get; set; }
/// Gets or sets the popover manager.
ApplicationPopover? Popover { get; set; }
/// 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);
/// Requests that the application stop running.
void RequestStop ();
/// 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);
///
/// Resets the application state to defaults. This is called by .
///
/// If true, will not assert that views are disposed.
void ResetState (bool ignoreDisposed = false);
///
/// 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. 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 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);
///
/// Gets or sets the size of the screen. By default, this is the size of the screen as reported by the
/// .
/// Setting the position is not supported and may throw . The size may be set
/// but will not persist if the terminal is resized and will not impact the actual terminal size.
///
Rectangle Screen { get; set; }
/// 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 ();
///
/// Collection of sixel images to write out to screen when updating.
/// Only add to this collection if you are sure terminal supports sixel format.
///
List Sixel { get; }
/// Gets all cultures supported by the application without the invariant language.
List? SupportedCultures { get; }
///
/// Handles recurring events. These are invoked on the main UI thread - allowing for
/// safe updates to instances.
///
ITimedEvents? TimedEvents { get; }
/// Gets the currently active Toplevel.
Toplevel? Top { get; set; }
/// Gets the stack of all Toplevels.
ConcurrentStack TopLevels { get; }
}