Skip to content

Commit 92c546e

Browse files
authored
Merge pull request #3844 from BDisp/v2_3767_restoring-drivers-and-fixes
Restoring drivers with the structural changes.
2 parents 2dd2def + e8e8c59 commit 92c546e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+7469
-5976
lines changed

NativeAot/Program.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ namespace NativeAot;
99

1010
public static class Program
1111
{
12-
[RequiresUnreferencedCode ("Calls Terminal.Gui.Application.Init(ConsoleDriver, String)")]
13-
[RequiresDynamicCode ("Calls Terminal.Gui.Application.Init(ConsoleDriver, String)")]
12+
[RequiresUnreferencedCode ("Calls Terminal.Gui.Application.Init(IConsoleDriver, String)")]
13+
[RequiresDynamicCode ("Calls Terminal.Gui.Application.Init(IConsoleDriver, String)")]
1414
private static void Main (string [] args)
1515
{
1616
Application.Init ();

SelfContained/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace SelfContained;
99

1010
public static class Program
1111
{
12-
[RequiresUnreferencedCode ("Calls Terminal.Gui.Application.Run<T>(Func<Exception, Boolean>, ConsoleDriver)")]
12+
[RequiresUnreferencedCode ("Calls Terminal.Gui.Application.Run<T>(Func<Exception, Boolean>, IConsoleDriver)")]
1313
private static void Main (string [] args)
1414
{
1515
Application.Init ();

Terminal.Gui/Application/Application.Driver.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ public static partial class Application // Driver abstractions
55
{
66
internal static bool _forceFakeConsole;
77

8-
/// <summary>Gets the <see cref="ConsoleDriver"/> that has been selected. See also <see cref="ForceDriver"/>.</summary>
9-
public static ConsoleDriver? Driver { get; internal set; }
8+
/// <summary>Gets the <see cref="IConsoleDriver"/> that has been selected. See also <see cref="ForceDriver"/>.</summary>
9+
public static IConsoleDriver? Driver { get; internal set; }
1010

1111
// BUGBUG: Force16Colors should be nullable.
1212
/// <summary>
1313
/// Gets or sets whether <see cref="Application.Driver"/> will be forced to output only the 16 colors defined in
1414
/// <see cref="ColorName16"/>. The default is <see langword="false"/>, meaning 24-bit (TrueColor) colors will be output
15-
/// as long as the selected <see cref="ConsoleDriver"/> supports TrueColor.
15+
/// as long as the selected <see cref="IConsoleDriver"/> supports TrueColor.
1616
/// </summary>
1717
[SerializableConfigurationProperty (Scope = typeof (SettingsScope))]
1818
public static bool Force16Colors { get; set; }
@@ -23,7 +23,7 @@ public static partial class Application // Driver abstractions
2323
/// specified, the driver is selected based on the platform.
2424
/// </summary>
2525
/// <remarks>
26-
/// Note, <see cref="Application.Init(ConsoleDriver, string)"/> will override this configuration setting if called
26+
/// Note, <see cref="Application.Init(IConsoleDriver, string)"/> will override this configuration setting if called
2727
/// with either `driver` or `driverName` specified.
2828
/// </remarks>
2929
[SerializableConfigurationProperty (Scope = typeof (SettingsScope))]

Terminal.Gui/Application/Application.Initialization.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public static partial class Application // Initialization (Init/Shutdown)
1010
/// <summary>Initializes a new instance of <see cref="Terminal.Gui"/> Application.</summary>
1111
/// <para>Call this method once per instance (or after <see cref="Shutdown"/> has been called).</para>
1212
/// <para>
13-
/// This function loads the right <see cref="ConsoleDriver"/> for the platform, Creates a <see cref="Toplevel"/>. and
13+
/// This function loads the right <see cref="IConsoleDriver"/> for the platform, Creates a <see cref="Toplevel"/>. and
1414
/// assigns it to <see cref="Top"/>
1515
/// </para>
1616
/// <para>
@@ -21,23 +21,23 @@ public static partial class Application // Initialization (Init/Shutdown)
2121
/// </para>
2222
/// <para>
2323
/// The <see cref="Run{T}"/> function combines
24-
/// <see cref="Init(Terminal.Gui.ConsoleDriver,string)"/> and <see cref="Run(Toplevel, Func{Exception, bool})"/>
24+
/// <see cref="Init(Terminal.Gui.IConsoleDriver,string)"/> and <see cref="Run(Toplevel, Func{Exception, bool})"/>
2525
/// into a single
2626
/// call. An application cam use <see cref="Run{T}"/> without explicitly calling
27-
/// <see cref="Init(Terminal.Gui.ConsoleDriver,string)"/>.
27+
/// <see cref="Init(Terminal.Gui.IConsoleDriver,string)"/>.
2828
/// </para>
2929
/// <param name="driver">
30-
/// The <see cref="ConsoleDriver"/> to use. If neither <paramref name="driver"/> or
30+
/// The <see cref="IConsoleDriver"/> to use. If neither <paramref name="driver"/> or
3131
/// <paramref name="driverName"/> are specified the default driver for the platform will be used.
3232
/// </param>
3333
/// <param name="driverName">
3434
/// The short name (e.g. "net", "windows", "ansi", "fake", or "curses") of the
35-
/// <see cref="ConsoleDriver"/> to use. If neither <paramref name="driver"/> or <paramref name="driverName"/> are
35+
/// <see cref="IConsoleDriver"/> to use. If neither <paramref name="driver"/> or <paramref name="driverName"/> are
3636
/// specified the default driver for the platform will be used.
3737
/// </param>
3838
[RequiresUnreferencedCode ("AOT")]
3939
[RequiresDynamicCode ("AOT")]
40-
public static void Init (ConsoleDriver? driver = null, string? driverName = null) { InternalInit (driver, driverName); }
40+
public static void Init (IConsoleDriver? driver = null, string? driverName = null) { InternalInit (driver, driverName); }
4141

4242
internal static int MainThreadId { get; set; } = -1;
4343

@@ -53,7 +53,7 @@ public static partial class Application // Initialization (Init/Shutdown)
5353
[RequiresUnreferencedCode ("AOT")]
5454
[RequiresDynamicCode ("AOT")]
5555
internal static void InternalInit (
56-
ConsoleDriver? driver = null,
56+
IConsoleDriver? driver = null,
5757
string? driverName = null,
5858
bool calledViaRunT = false
5959
)
@@ -136,7 +136,7 @@ internal static void InternalInit (
136136

137137
if (driverType is { })
138138
{
139-
Driver = (ConsoleDriver)Activator.CreateInstance (driverType)!;
139+
Driver = (IConsoleDriver)Activator.CreateInstance (driverType)!;
140140
}
141141
else
142142
{
@@ -181,7 +181,7 @@ internal static void InternalInit (
181181
private static void Driver_KeyUp (object? sender, Key e) { RaiseKeyUpEvent (e); }
182182
private static void Driver_MouseEvent (object? sender, MouseEventArgs e) { RaiseMouseEvent (e); }
183183

184-
/// <summary>Gets of list of <see cref="ConsoleDriver"/> types that are available.</summary>
184+
/// <summary>Gets of list of <see cref="IConsoleDriver"/> types that are available.</summary>
185185
/// <returns></returns>
186186
[RequiresUnreferencedCode ("AOT")]
187187
public static List<Type?> GetDriverTypes ()
@@ -193,7 +193,7 @@ internal static void InternalInit (
193193
{
194194
foreach (Type? type in asm.GetTypes ())
195195
{
196-
if (type.IsSubclassOf (typeof (ConsoleDriver)) && !type.IsAbstract)
196+
if (typeof (IConsoleDriver).IsAssignableFrom (type) && !type.IsAbstract && type.IsClass)
197197
{
198198
driverTypes.Add (type);
199199
}

Terminal.Gui/Application/Application.Keyboard.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ namespace Terminal.Gui;
44
public static partial class Application // Keyboard handling
55
{
66
/// <summary>
7-
/// Called when the user presses a key (by the <see cref="ConsoleDriver"/>). Raises the cancelable
7+
/// Called when the user presses a key (by the <see cref="IConsoleDriver"/>). Raises the cancelable
88
/// <see cref="KeyDown"/> event, then calls <see cref="View.NewKeyDownEvent"/> on all top level views, and finally
99
/// if the key was not handled, invokes any Application-scoped <see cref="KeyBindings"/>.
1010
/// </summary>
@@ -116,7 +116,7 @@ public static bool RaiseKeyDownEvent (Key key)
116116
public static event EventHandler<Key>? KeyDown;
117117

118118
/// <summary>
119-
/// Called when the user releases a key (by the <see cref="ConsoleDriver"/>). Raises the cancelable <see cref="KeyUp"/>
119+
/// Called when the user releases a key (by the <see cref="IConsoleDriver"/>). Raises the cancelable <see cref="KeyUp"/>
120120
/// event
121121
/// then calls <see cref="View.NewKeyUpEvent"/> on all top level views. Called after <see cref="RaiseKeyDownEvent"/>.
122122
/// </summary>

Terminal.Gui/Application/Application.Run.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ internal static bool PositionCursor ()
305305
/// <returns>The created <see cref="Toplevel"/> object. The caller is responsible for disposing this object.</returns>
306306
[RequiresUnreferencedCode ("AOT")]
307307
[RequiresDynamicCode ("AOT")]
308-
public static Toplevel Run (Func<Exception, bool>? errorHandler = null, ConsoleDriver? driver = null) { return Run<Toplevel> (errorHandler, driver); }
308+
public static Toplevel Run (Func<Exception, bool>? errorHandler = null, IConsoleDriver? driver = null) { return Run<Toplevel> (errorHandler, driver); }
309309

310310
/// <summary>
311311
/// Runs the application by creating a <see cref="Toplevel"/>-derived object of type <c>T</c> and calling
@@ -323,14 +323,14 @@ internal static bool PositionCursor ()
323323
/// </remarks>
324324
/// <param name="errorHandler"></param>
325325
/// <param name="driver">
326-
/// The <see cref="ConsoleDriver"/> to use. If not specified the default driver for the platform will
326+
/// The <see cref="IConsoleDriver"/> to use. If not specified the default driver for the platform will
327327
/// be used ( <see cref="WindowsDriver"/>, <see cref="CursesDriver"/>, or <see cref="NetDriver"/>). Must be
328328
/// <see langword="null"/> if <see cref="Init"/> has already been called.
329329
/// </param>
330330
/// <returns>The created T object. The caller is responsible for disposing this object.</returns>
331331
[RequiresUnreferencedCode ("AOT")]
332332
[RequiresDynamicCode ("AOT")]
333-
public static T Run<T> (Func<Exception, bool>? errorHandler = null, ConsoleDriver? driver = null)
333+
public static T Run<T> (Func<Exception, bool>? errorHandler = null, IConsoleDriver? driver = null)
334334
where T : Toplevel, new()
335335
{
336336
if (!Initialized)
@@ -369,7 +369,7 @@ public static T Run<T> (Func<Exception, bool>? errorHandler = null, ConsoleDrive
369369
/// return control immediately.
370370
/// </para>
371371
/// <para>When using <see cref="Run{T}"/> or
372-
/// <see cref="Run(System.Func{System.Exception,bool},Terminal.Gui.ConsoleDriver)"/>
372+
/// <see cref="Run(System.Func{System.Exception,bool},Terminal.Gui.IConsoleDriver)"/>
373373
/// <see cref="Init"/> will be called automatically.
374374
/// </para>
375375
/// <para>

Terminal.Gui/Application/Application.Screen.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ public static partial class Application // Screen related stuff
66
private static Rectangle? _screen;
77

88
/// <summary>
9-
/// Gets or sets the size of the screen. By default, this is the size of the screen as reported by the <see cref="ConsoleDriver"/>.
9+
/// Gets or sets the size of the screen. By default, this is the size of the screen as reported by the <see cref="IConsoleDriver"/>.
1010
/// </summary>
1111
/// <remarks>
1212
/// <para>
13-
/// If the <see cref="ConsoleDriver"/> has not been initialized, this will return a default size of 2048x2048; useful for unit tests.
13+
/// If the <see cref="IConsoleDriver"/> has not been initialized, this will return a default size of 2048x2048; useful for unit tests.
1414
/// </para>
1515
/// </remarks>
1616
public static Rectangle Screen

Terminal.Gui/Application/Application.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public static partial class Application
3232
/// <returns>A string representation of the Application </returns>
3333
public new static string ToString ()
3434
{
35-
ConsoleDriver? driver = Driver;
35+
IConsoleDriver? driver = Driver;
3636

3737
if (driver is null)
3838
{
@@ -43,11 +43,11 @@ public static partial class Application
4343
}
4444

4545
/// <summary>
46-
/// Gets a string representation of the Application rendered by the provided <see cref="ConsoleDriver"/>.
46+
/// Gets a string representation of the Application rendered by the provided <see cref="IConsoleDriver"/>.
4747
/// </summary>
4848
/// <param name="driver">The driver to use to render the contents.</param>
4949
/// <returns>A string representation of the Application </returns>
50-
public static string ToString (ConsoleDriver? driver)
50+
public static string ToString (IConsoleDriver? driver)
5151
{
5252
if (driver is null)
5353
{

Terminal.Gui/Application/MainLoop.cs

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
//
1+
#nullable enable
2+
//
23
// MainLoop.cs: IMainLoopDriver and MainLoop for Terminal.Gui
34
//
45
// Authors:
@@ -36,7 +37,7 @@ internal interface IMainLoopDriver
3637
/// Monitoring of file descriptors is only available on Unix, there does not seem to be a way of supporting this
3738
/// on Windows.
3839
/// </remarks>
39-
internal class MainLoop : IDisposable
40+
public class MainLoop : IDisposable
4041
{
4142
internal List<Func<bool>> _idleHandlers = new ();
4243
internal SortedList<long, Timeout> _timeouts = new ();
@@ -49,7 +50,7 @@ internal class MainLoop : IDisposable
4950
/// <summary>Creates a new MainLoop.</summary>
5051
/// <remarks>Use <see cref="Dispose"/> to release resources.</remarks>
5152
/// <param name="driver">
52-
/// The <see cref="ConsoleDriver"/> instance (one of the implementations FakeMainLoop, UnixMainLoop,
53+
/// The <see cref="IConsoleDriver"/> instance (one of the implementations FakeMainLoop, UnixMainLoop,
5354
/// NetMainLoop or WindowsMainLoop).
5455
/// </param>
5556
internal MainLoop (IMainLoopDriver driver)
@@ -72,7 +73,7 @@ internal ReadOnlyCollection<Func<bool>> IdleHandlers
7273

7374
/// <summary>The current <see cref="IMainLoopDriver"/> in use.</summary>
7475
/// <value>The main loop driver.</value>
75-
internal IMainLoopDriver MainLoopDriver { get; private set; }
76+
internal IMainLoopDriver? MainLoopDriver { get; private set; }
7677

7778
/// <summary>Used for unit tests.</summary>
7879
internal bool Running { get; set; }
@@ -117,7 +118,7 @@ internal Func<bool> AddIdle (Func<bool> idleHandler)
117118
_idleHandlers.Add (idleHandler);
118119
}
119120

120-
MainLoopDriver.Wakeup ();
121+
MainLoopDriver?.Wakeup ();
121122

122123
return idleHandler;
123124
}
@@ -130,10 +131,7 @@ internal Func<bool> AddIdle (Func<bool> idleHandler)
130131
/// </remarks>
131132
internal object AddTimeout (TimeSpan time, Func<bool> callback)
132133
{
133-
if (callback is null)
134-
{
135-
throw new ArgumentNullException (nameof (callback));
136-
}
134+
ArgumentNullException.ThrowIfNull (callback);
137135

138136
var timeout = new Timeout { Span = time, Callback = callback };
139137
AddTimeout (time, timeout);
@@ -156,7 +154,7 @@ internal bool CheckTimersAndIdleHandlers (out int waitTimeout)
156154

157155
waitTimeout = 0;
158156

159-
lock (_timeouts)
157+
lock (_timeoutsLockToken)
160158
{
161159
if (_timeouts.Count > 0)
162160
{
@@ -191,7 +189,7 @@ internal bool CheckTimersAndIdleHandlers (out int waitTimeout)
191189
/// You can use this method if you want to probe if events are pending. Typically used if you need to flush the
192190
/// input queue while still running some of your own code in your main thread.
193191
/// </remarks>
194-
internal bool EventsPending () { return MainLoopDriver.EventsPending (); }
192+
internal bool EventsPending () { return MainLoopDriver!.EventsPending (); }
195193

196194
/// <summary>Removes an idle handler added with <see cref="AddIdle(Func{bool})"/> from processing.</summary>
197195
/// <param name="token">A token returned by <see cref="AddIdle(Func{bool})"/></param>
@@ -225,7 +223,7 @@ internal bool RemoveTimeout (object token)
225223
{
226224
lock (_timeoutsLockToken)
227225
{
228-
int idx = _timeouts.IndexOfValue (token as Timeout);
226+
int idx = _timeouts.IndexOfValue ((token as Timeout)!);
229227

230228
if (idx == -1)
231229
{
@@ -262,17 +260,17 @@ internal void Run ()
262260
/// </remarks>
263261
internal void RunIteration ()
264262
{
265-
lock (_timeouts)
263+
lock (_timeoutsLockToken)
266264
{
267265
if (_timeouts.Count > 0)
268266
{
269267
RunTimers ();
270268
}
271269
}
272270

273-
MainLoopDriver.Iteration ();
271+
MainLoopDriver?.Iteration ();
274272

275-
var runIdle = false;
273+
bool runIdle;
276274

277275
lock (_idleHandlersLock)
278276
{
@@ -296,8 +294,7 @@ internal void Stop ()
296294
/// Invoked when a new timeout is added. To be used in the case when
297295
/// <see cref="Application.EndAfterFirstIteration"/> is <see langword="true"/>.
298296
/// </summary>
299-
[CanBeNull]
300-
internal event EventHandler<TimeoutEventArgs> TimeoutAdded;
297+
internal event EventHandler<TimeoutEventArgs>? TimeoutAdded;
301298

302299
/// <summary>Wakes up the <see cref="MainLoop"/> that might be waiting on input.</summary>
303300
internal void Wakeup () { MainLoopDriver?.Wakeup (); }

Terminal.Gui/Clipboard/Clipboard.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public static bool TrySetClipboardData (string text)
111111

112112
/// <summary>
113113
/// Helper class for console drivers to invoke shell commands to interact with the clipboard. Used primarily by
114-
/// CursesDriver, but also used in Unit tests which is why it is in ConsoleDriver.cs.
114+
/// CursesDriver, but also used in Unit tests which is why it is in IConsoleDriver.cs.
115115
/// </summary>
116116
internal static class ClipboardProcessRunner
117117
{

0 commit comments

Comments
 (0)