namespace Terminal.Gui.App;
///
/// Defines a view that can be run as an independent session with .
///
///
///
/// A runnable view can execute as a self-contained session with its own lifecycle,
/// event loop iteration, and focus management.
///
///
/// Implementing does not require any specific view hierarchy
/// (e.g., deriving from Toplevel) or layout mode (e.g., Overlapped).
///
///
/// For exclusive input capture (modal behavior), implement .
///
///
/// This interface follows the Terminal.Gui Cancellable Work Pattern (CWP) for lifecycle events
/// where cancellation makes sense (Stopping, Starting).
///
///
public interface IRunnable
{
///
/// Gets or sets whether this runnable session is currently running.
///
///
/// This property is set by the framework during session lifecycle. Setting this property
/// directly is discouraged. Use instead.
///
bool Running { get; set; }
#region Lifecycle Methods (Called by IApplication)
///
/// Raises the and events.
/// Called by .
///
///
///
/// This method implements the Cancellable Work Pattern for stopping:
/// 1. Calls virtual method (can cancel)
/// 2. Raises event (can cancel)
/// 3. If not canceled, sets = false
/// 4. Calls post-notification virtual method
/// 5. Raises event
///
///
/// Implementations should follow this pattern. See for reference implementation.
///
///
void RaiseStoppingEvent ();
///
/// Raises the event.
/// Called by or when this runnable session is starting.
///
/// if starting was canceled; otherwise .
///
///
/// This method implements the Cancellable Work Pattern for starting:
/// 1. Calls virtual method (can cancel)
/// 2. Raises event (can cancel)
/// 3. If canceled, returns true
/// 4. If not canceled, calls and returns false
///
///
bool RaiseStartingEvent ();
///
/// Raises the event.
/// Called by after starting succeeds.
///
///
/// This is the post-notification phase of starting. Implementations should raise the
/// event.
///
void RaiseStartedEvent ();
#endregion
#region Lifecycle Events
///
/// Raised during before initialization completes.
/// Can be canceled by setting to .
///
///
///
/// This event is from the pattern and is raised by .
/// Subscribe to this event to perform pre-initialization work or to cancel initialization.
///
///
/// This event follows the Terminal.Gui Cancellable Work Pattern.
///
///
event EventHandler? Initializing;
///
/// Raised after the runnable has been initialized (via /).
/// The view is laid out and ready to be drawn.
///
///
///
/// This event is from the pattern and is raised by .
/// Subscribe to this event to perform initialization that requires the view to be fully laid out.
///
///
/// This is the post-notification event in the Cancellable Work Pattern pair with .
///
///
event EventHandler? Initialized;
///
/// Raised when is called on this runnable.
/// Can be canceled by setting to .
///
///
/// Subscribe to this event to prevent the runnable from stopping (e.g., to prompt the user
/// to save changes). If canceled, will remain .
///
event EventHandler? Stopping;
///
/// Raised after the runnable session has stopped ( = ).
///
///
/// This is the post-notification event in the Cancellable Work Pattern pair with .
/// Subscribe to this event for cleanup work that should occur after the session stops.
///
event EventHandler? Stopped;
///
/// Raised when the runnable session is about to start running.
/// Can be canceled by setting to .
///
///
/// Subscribe to this event to prevent starting or to perform pre-start work.
/// This aligns with and .
///
event EventHandler? Starting;
///
/// Raised when the runnable session has started running.
///
///
/// This is the post-notification event in the Cancellable Work Pattern pair with .
/// Subscribe to this event for post-start logic (e.g., setting focus).
/// This aligns with and .
///
event EventHandler? Started;
#endregion
}