1
1
#nullable enable
2
2
using System . Collections . Concurrent ;
3
- using System . Diagnostics ;
4
3
using System . Diagnostics . CodeAnalysis ;
5
4
using Microsoft . Extensions . Logging ;
6
5
@@ -22,8 +21,8 @@ public class ApplicationV2 : ApplicationImpl
22
21
private readonly ITimedEvents _timedEvents = new TimedEvents ( ) ;
23
22
24
23
/// <summary>
25
- /// Creates anew instance of the Application backend. The provided
26
- /// factory methods will be used on Init calls to get things booted.
24
+ /// Creates anew instance of the Application backend. The provided
25
+ /// factory methods will be used on Init calls to get things booted.
27
26
/// </summary>
28
27
public ApplicationV2 ( ) : this (
29
28
( ) => new NetInput ( ) ,
@@ -52,10 +51,10 @@ Func<IConsoleOutput> winOutputFactory
52
51
[ RequiresDynamicCode ( "AOT" ) ]
53
52
public override void Init ( IConsoleDriver ? driver = null , string ? driverName = null )
54
53
{
55
-
56
54
if ( Application . Initialized )
57
55
{
58
56
Logging . Logger . LogError ( "Init called multiple times without shutdown, ignoring." ) ;
57
+
59
58
return ;
60
59
}
61
60
@@ -80,7 +79,6 @@ public override void Init (IConsoleDriver? driver = null, string? driverName = n
80
79
Application . SubscribeDriverEvents ( ) ;
81
80
}
82
81
83
-
84
82
private void CreateDriver ( string ? driverName )
85
83
{
86
84
PlatformID p = Environment . OSVersion . Platform ;
@@ -98,7 +96,7 @@ private void CreateDriver (string? driverName)
98
96
}
99
97
else if ( p == PlatformID . Win32NT || p == PlatformID . Win32S || p == PlatformID . Win32Windows )
100
98
{
101
- _coordinator = CreateWindowsSubcomponents ( ) ;
99
+ _coordinator = CreateWindowsSubcomponents ( ) ;
102
100
}
103
101
else
104
102
{
@@ -115,30 +113,30 @@ private void CreateDriver (string? driverName)
115
113
116
114
private IMainLoopCoordinator CreateWindowsSubcomponents ( )
117
115
{
118
- ConcurrentQueue < WindowsConsole . InputRecord > inputBuffer = new ConcurrentQueue < WindowsConsole . InputRecord > ( ) ;
119
- MainLoop < WindowsConsole . InputRecord > loop = new MainLoop < WindowsConsole . InputRecord > ( ) ;
116
+ ConcurrentQueue < WindowsConsole . InputRecord > inputBuffer = new ( ) ;
117
+ MainLoop < WindowsConsole . InputRecord > loop = new ( ) ;
120
118
121
119
return new MainLoopCoordinator < WindowsConsole . InputRecord > (
122
- _timedEvents ,
123
- _winInputFactory ,
124
- inputBuffer ,
125
- new WindowsInputProcessor ( inputBuffer ) ,
126
- _winOutputFactory ,
127
- loop ) ;
120
+ _timedEvents ,
121
+ _winInputFactory ,
122
+ inputBuffer ,
123
+ new WindowsInputProcessor ( inputBuffer ) ,
124
+ _winOutputFactory ,
125
+ loop ) ;
128
126
}
129
127
130
128
private IMainLoopCoordinator CreateNetSubcomponents ( )
131
129
{
132
- ConcurrentQueue < ConsoleKeyInfo > inputBuffer = new ConcurrentQueue < ConsoleKeyInfo > ( ) ;
133
- MainLoop < ConsoleKeyInfo > loop = new MainLoop < ConsoleKeyInfo > ( ) ;
130
+ ConcurrentQueue < ConsoleKeyInfo > inputBuffer = new ( ) ;
131
+ MainLoop < ConsoleKeyInfo > loop = new ( ) ;
134
132
135
133
return new MainLoopCoordinator < ConsoleKeyInfo > (
136
- _timedEvents ,
137
- _netInputFactory ,
138
- inputBuffer ,
139
- new NetInputProcessor ( inputBuffer ) ,
140
- _netOutputFactory ,
141
- loop ) ;
134
+ _timedEvents ,
135
+ _netInputFactory ,
136
+ inputBuffer ,
137
+ new NetInputProcessor ( inputBuffer ) ,
138
+ _netOutputFactory ,
139
+ loop ) ;
142
140
}
143
141
144
142
/// <inheritdoc/>
@@ -161,7 +159,7 @@ public override void Run (Toplevel view, Func<Exception, bool>? errorHandler = n
161
159
162
160
if ( ! Application . Initialized )
163
161
{
164
- throw new NotInitializedException ( nameof ( Run ) ) ;
162
+ throw new NotInitializedException ( nameof ( Run ) ) ;
165
163
}
166
164
167
165
Application . Top = view ;
@@ -173,8 +171,9 @@ public override void Run (Toplevel view, Func<Exception, bool>? errorHandler = n
173
171
{
174
172
if ( _coordinator is null )
175
173
{
176
- throw new Exception ( $ "{ nameof ( IMainLoopCoordinator ) } inexplicably became null during Run") ;
174
+ throw new ( $ "{ nameof ( IMainLoopCoordinator ) } inexplicably became null during Run") ;
177
175
}
176
+
178
177
_coordinator . RunIteration ( ) ;
179
178
}
180
179
}
@@ -209,27 +208,24 @@ public override void RequestStop (Toplevel? top)
209
208
public override void Invoke ( Action action )
210
209
{
211
210
_timedEvents . AddIdle (
212
- ( ) =>
213
- {
214
- action ( ) ;
211
+ ( ) =>
212
+ {
213
+ action ( ) ;
215
214
216
- return false ;
217
- }
218
- ) ;
215
+ return false ;
216
+ }
217
+ ) ;
219
218
}
220
219
221
220
/// <inheritdoc/>
222
221
public override void AddIdle ( Func < bool > func ) { _timedEvents . AddIdle ( func ) ; }
223
222
224
223
/// <summary>
225
- /// Removes an idle function added by <see cref="AddIdle"/>
224
+ /// Removes an idle function added by <see cref="AddIdle"/>
226
225
/// </summary>
227
226
/// <param name="fnTrue">Function to remove</param>
228
227
/// <returns>True if it was found and removed</returns>
229
- public bool RemoveIdle ( Func < bool > fnTrue )
230
- {
231
- return _timedEvents . RemoveIdle ( fnTrue ) ;
232
- }
228
+ public bool RemoveIdle ( Func < bool > fnTrue ) { return _timedEvents . RemoveIdle ( fnTrue ) ; }
233
229
234
230
/// <inheritdoc/>
235
231
public override object AddTimeout ( TimeSpan time , Func < bool > callback ) { return _timedEvents . AddTimeout ( time , callback ) ; }
0 commit comments