Class Application
A static, singleton class providing the main application driver for Terminal.Gui apps.
Inheritance
System.Object
Application
Remarks
Creates a instance of MainLoop to process input events, handle timers and other sources of data. It is accessible via the MainLoop property.
You can hook up to the Iteration event to have your method invoked on each iteration of the MainLoop.
When invoked sets the SynchronizationContext to one that is tied to the mainloop, allowing user code to use async/await.
Examples
// A simple Terminal.Gui app that creates a window with a frame and title with
// 5 rows/columns of padding.
Application.Init();
var win = new Window ("Hello World - CTRL-Q to quit") {
X = 5,
Y = 5,
Width = Dim.Fill (5),
Height = Dim.Fill (5)
};
Application.Top.Add(win);
Application.Run();
Namespace: Terminal.Gui
Assembly: Terminal.Gui.dll
Syntax
public static class Application : Object
Fields
Driver
The current ConsoleDriver in use.
Declaration
public static ConsoleDriver Driver
Field Value
Type | Description |
---|---|
ConsoleDriver |
Iteration
This event is raised on each iteration of the MainLoop
Declaration
public static Action Iteration
Field Value
Type | Description |
---|---|
System.Action |
Resized
Invoked when the terminal was resized. The new size of the terminal is provided.
Declaration
public static Action<Application.ResizedEventArgs> Resized
Field Value
Type | Description |
---|---|
System.Action<Application.ResizedEventArgs> |
RootKeyEvent
Called for new KeyPress events before any processing is performed or views evaluate. Use for global key handling and/or debugging.
Return true to suppress the KeyPress event
Declaration
public static Func<KeyEvent, bool> RootKeyEvent
Field Value
Type | Description |
---|---|
System.Func<KeyEvent, System.Boolean> |
RootMouseEvent
Merely a debugging aid to see the raw mouse events
Declaration
public static Action<MouseEvent> RootMouseEvent
Field Value
Type | Description |
---|---|
System.Action<MouseEvent> |
UseSystemConsole
If set, it forces the use of the System.Console-based driver.
Declaration
public static bool UseSystemConsole
Field Value
Type | Description |
---|---|
System.Boolean |
Properties
AlternateBackwardKey
Alternative key to navigate backwards through all views. Shift+Ctrl+Tab is always used.
Declaration
public static Key AlternateBackwardKey { get; set; }
Property Value
Type | Description |
---|---|
Key |
AlternateForwardKey
Alternative key to navigate forwards through all views. Ctrl+Tab is always used.
Declaration
public static Key AlternateForwardKey { get; set; }
Property Value
Type | Description |
---|---|
Key |
Current
The current Toplevel object. This is updated when Run(Func<Exception, Boolean>) enters and leaves to point to the current Toplevel .
Declaration
public static Toplevel Current { get; }
Property Value
Type | Description |
---|---|
Toplevel | The current. |
ExitRunLoopAfterFirstIteration
Set to true to cause the RunLoop method to exit after the first iterations.
Set to false (the default) to cause the RunLoop to continue running until Application.RequestStop() is called.
Declaration
public static bool ExitRunLoopAfterFirstIteration { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean |
HeightAsBuffer
The current HeightAsBuffer used in the terminal.
Declaration
public static bool HeightAsBuffer { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean |
IsMouseDisabled
Disable or enable the mouse in this Application
Declaration
public static bool IsMouseDisabled { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean |
MainLoop
The MainLoop driver for the application
Declaration
public static MainLoop MainLoop { get; }
Property Value
Type | Description |
---|---|
MainLoop | The main loop. |
MdiChildes
Declaration
public static List<Toplevel> MdiChildes { get; }
Property Value
Type | Description |
---|---|
System.Collections.Generic.List<Toplevel> |
MdiTop
The Toplevel object used for the application on startup which IsMdiContainer is true.
Declaration
public static Toplevel MdiTop { get; }
Property Value
Type | Description |
---|---|
Toplevel |
QuitKey
Gets or sets the key to quit the application.
Declaration
public static Key QuitKey { get; set; }
Property Value
Type | Description |
---|---|
Key |
SupportedCultures
Gets all supported cultures by the application without the invariant language.
Declaration
public static List<CultureInfo> SupportedCultures { get; }
Property Value
Type | Description |
---|---|
System.Collections.Generic.List<System.Globalization.CultureInfo> |
Top
Declaration
public static Toplevel Top { get; }
Property Value
Type | Description |
---|---|
Toplevel | The top. |
WantContinuousButtonPressedView
The current View object that wants continuous mouse button pressed events.
Declaration
public static View WantContinuousButtonPressedView { get; }
Property Value
Type | Description |
---|---|
View |
Methods
Begin(Toplevel)
Building block API: Prepares the provided Toplevel for execution.
Declaration
public static Application.RunState Begin(Toplevel toplevel)
Parameters
Type | Name | Description |
---|---|---|
Toplevel | toplevel | Toplevel to prepare execution for. |
Returns
Type | Description |
---|---|
Application.RunState | The runstate handle that needs to be passed to the End(Application.RunState) method upon completion. |
DoEvents()
Wakes up the mainloop that might be waiting on input, must be thread safe.
Declaration
public static void DoEvents()
End(Application.RunState)
Building block API: completes the execution of a Toplevel that was started with Begin(Toplevel) .
Declaration
public static void End(Application.RunState runState)
Parameters
Type | Name | Description |
---|---|---|
Application.RunState | runState | The runstate returned by the Begin(Toplevel) method. |
EnsuresTopOnFront()
Ensures that the superview of the most focused view is on front.
Declaration
public static void EnsuresTopOnFront()
GrabMouse(View)
Grabs the mouse, forcing all mouse events to be routed to the specified view until UngrabMouse is called.
Declaration
public static void GrabMouse(View view)
Parameters
Type | Name | Description |
---|---|---|
View | view | View that will receive all mouse events until UngrabMouse is invoked. |
Init(ConsoleDriver, IMainLoopDriver)
Initializes a new instance of Terminal.Gui Application.
Declaration
public static void Init(ConsoleDriver driver = null, IMainLoopDriver mainLoopDriver = null)
Parameters
Type | Name | Description |
---|---|---|
ConsoleDriver | driver | |
IMainLoopDriver | mainLoopDriver |
MakeCenteredRect(Size)
Returns a rectangle that is centered in the screen for the provided size.
Declaration
public static Rect MakeCenteredRect(Size size)
Parameters
Type | Name | Description |
---|---|---|
Size | size | Size for the rectangle. |
Returns
Type | Description |
---|---|
Rect | The centered rect. |
MoveNext()
Move to the next Mdi child from the MdiTop.
Declaration
public static void MoveNext()
MovePrevious()
Move to the previous Mdi child from the MdiTop.
Declaration
public static void MovePrevious()
Refresh()
Triggers a refresh of the entire display.
Declaration
public static void Refresh()
RequestStop(Toplevel)
Stops running the most recent Toplevel or the
top
if provided.
Declaration
public static void RequestStop(Toplevel top = null)
Parameters
Type | Name | Description |
---|---|---|
Toplevel | top | The toplevel to request stop. |
Run(Func<Exception, Boolean>)
Runs the application by calling Run(Toplevel, Func<Exception, Boolean>) with the value of Top
Declaration
public static void Run(Func<Exception, bool> errorHandler = null)
Parameters
Type | Name | Description |
---|---|---|
System.Func<System.Exception, System.Boolean> | errorHandler |
Run(Toplevel, Func<Exception, Boolean>)
Runs the main loop on the given Toplevel container.
Declaration
public static void Run(Toplevel view, Func<Exception, bool> errorHandler = null)
Parameters
Type | Name | Description |
---|---|---|
Toplevel | view | The Toplevel to run modally. |
System.Func<System.Exception, System.Boolean> | errorHandler | Handler for any unhandled exceptions (resumes when returns true, rethrows when null). |
Run<T>(Func<Exception, Boolean>)
Runs the application by calling Run(Toplevel, Func<Exception, Boolean>) with a new instance of the specified Toplevel-derived class
Declaration
public static void Run<T>(Func<Exception, bool> errorHandler = null)
where T : Toplevel, new()
Parameters
Type | Name | Description |
---|---|---|
System.Func<System.Exception, System.Boolean> | errorHandler |
Type Parameters
Name | Description |
---|---|
T |
RunLoop(Application.RunState, Boolean)
Building block API: Runs the main loop for the created dialog
Declaration
public static void RunLoop(Application.RunState state, bool wait = true)
Parameters
Type | Name | Description |
---|---|---|
Application.RunState | state | The state returned by the Begin method. |
System.Boolean | wait | By default this is true which will execute the runloop waiting for events, if you pass false, you can use this method to run a single iteration of the events. |
RunMainLoopIteration(ref Application.RunState, Boolean, ref Boolean)
Run one iteration of the MainLoop.
Declaration
public static void RunMainLoopIteration(ref Application.RunState state, bool wait, ref bool firstIteration)
Parameters
Type | Name | Description |
---|---|---|
Application.RunState | state | The state returned by the Begin method. |
System.Boolean | wait | If will execute the runloop waiting for events. |
System.Boolean | firstIteration | If it's the first run loop iteration. |
Shutdown()
Shutdown an application initialized with Init(ConsoleDriver, IMainLoopDriver)
Declaration
public static void Shutdown()
UngrabMouse()
Releases the mouse grab, so mouse events will be routed to the view on which the mouse is.
Declaration
public static void UngrabMouse()
Events
NotifyNewRunState
Notify that a new Application.RunState token was created,
used if ExitRunLoopAfterFirstIteration is true.
Declaration
public static event Action<Application.RunState> NotifyNewRunState
Event Type
Type | Description |
---|---|
System.Action<Application.RunState> |
NotifyStopRunState
Notify that a existent Application.RunState token is stopping,
used if ExitRunLoopAfterFirstIteration is true.
Declaration
public static event Action<Toplevel> NotifyStopRunState
Event Type
Type | Description |
---|---|
System.Action<Toplevel> |