#nullable enable
using System.Collections.Concurrent;
namespace Terminal.Gui.App;
///
/// Implementation of core methods using the modern
/// main loop architecture with component factories for different platforms.
///
public partial class ApplicationImpl : IApplication
{
///
/// Creates a new instance of the Application backend.
///
public ApplicationImpl () { }
///
/// INTERNAL: Creates a new instance of the Application backend.
///
///
internal ApplicationImpl (IComponentFactory componentFactory) { _componentFactory = componentFactory; }
#region Singleton
// Private static readonly Lazy instance of Application
private static Lazy _lazyInstance = new (() => new ApplicationImpl ());
///
/// Change the singleton implementation, should not be called except before application
/// startup. This method lets you provide alternative implementations of core static gateway
/// methods of .
///
///
public static void ChangeInstance (IApplication? newApplication) { _lazyInstance = new (newApplication!); }
///
/// Gets the currently configured backend implementation of gateway methods.
/// Change to your own implementation by using (before init).
///
public static IApplication Instance => _lazyInstance.Value;
#endregion Singleton
private string? _driverName;
#region Input
private IMouse? _mouse;
///
/// Handles mouse event state and processing.
///
public IMouse Mouse
{
get
{
if (_mouse is null)
{
_mouse = new MouseImpl { Application = this };
}
return _mouse;
}
set => _mouse = value ?? throw new ArgumentNullException (nameof (value));
}
private IKeyboard? _keyboard;
///
/// Handles keyboard input and key bindings at the Application level
///
public IKeyboard Keyboard
{
get
{
if (_keyboard is null)
{
_keyboard = new KeyboardImpl { Application = this };
}
return _keyboard;
}
set => _keyboard = value ?? throw new ArgumentNullException (nameof (value));
}
#endregion Input
#region View Management
///
public ApplicationPopover? Popover { get; set; }
///
public ApplicationNavigation? Navigation { get; set; }
///
public Toplevel? Top { get; set; }
// BUGBUG: Technically, this is not the full lst of TopLevels. There be dragons here, e.g. see how Toplevel.Id is used. What
///
public ConcurrentStack TopLevels { get; } = new ();
///
public Toplevel? CachedSessionTokenToplevel { get; set; }
#endregion View Management
}