Skip to content

Commit e020f42

Browse files
committed
Code cleanup on all v2 classes
1 parent 52caf29 commit e020f42

28 files changed

+245
-240
lines changed

Terminal.Gui/ConsoleDrivers/V2/ApplicationV2.cs

+31-35
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#nullable enable
22
using System.Collections.Concurrent;
3-
using System.Diagnostics;
43
using System.Diagnostics.CodeAnalysis;
54
using Microsoft.Extensions.Logging;
65

@@ -22,8 +21,8 @@ public class ApplicationV2 : ApplicationImpl
2221
private readonly ITimedEvents _timedEvents = new TimedEvents ();
2322

2423
/// <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.
2726
/// </summary>
2827
public ApplicationV2 () : this (
2928
() => new NetInput (),
@@ -52,10 +51,10 @@ Func<IConsoleOutput> winOutputFactory
5251
[RequiresDynamicCode ("AOT")]
5352
public override void Init (IConsoleDriver? driver = null, string? driverName = null)
5453
{
55-
5654
if (Application.Initialized)
5755
{
5856
Logging.Logger.LogError ("Init called multiple times without shutdown, ignoring.");
57+
5958
return;
6059
}
6160

@@ -80,7 +79,6 @@ public override void Init (IConsoleDriver? driver = null, string? driverName = n
8079
Application.SubscribeDriverEvents ();
8180
}
8281

83-
8482
private void CreateDriver (string? driverName)
8583
{
8684
PlatformID p = Environment.OSVersion.Platform;
@@ -98,7 +96,7 @@ private void CreateDriver (string? driverName)
9896
}
9997
else if (p == PlatformID.Win32NT || p == PlatformID.Win32S || p == PlatformID.Win32Windows)
10098
{
101-
_coordinator = CreateWindowsSubcomponents();
99+
_coordinator = CreateWindowsSubcomponents ();
102100
}
103101
else
104102
{
@@ -115,30 +113,30 @@ private void CreateDriver (string? driverName)
115113

116114
private IMainLoopCoordinator CreateWindowsSubcomponents ()
117115
{
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 ();
120118

121119
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);
128126
}
129127

130128
private IMainLoopCoordinator CreateNetSubcomponents ()
131129
{
132-
ConcurrentQueue<ConsoleKeyInfo> inputBuffer = new ConcurrentQueue<ConsoleKeyInfo> ();
133-
MainLoop<ConsoleKeyInfo> loop = new MainLoop<ConsoleKeyInfo> ();
130+
ConcurrentQueue<ConsoleKeyInfo> inputBuffer = new ();
131+
MainLoop<ConsoleKeyInfo> loop = new ();
134132

135133
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);
142140
}
143141

144142
/// <inheritdoc/>
@@ -161,7 +159,7 @@ public override void Run (Toplevel view, Func<Exception, bool>? errorHandler = n
161159

162160
if (!Application.Initialized)
163161
{
164-
throw new NotInitializedException (nameof(Run));
162+
throw new NotInitializedException (nameof (Run));
165163
}
166164

167165
Application.Top = view;
@@ -173,8 +171,9 @@ public override void Run (Toplevel view, Func<Exception, bool>? errorHandler = n
173171
{
174172
if (_coordinator is null)
175173
{
176-
throw new Exception ($"{nameof (IMainLoopCoordinator)}inexplicably became null during Run");
174+
throw new ($"{nameof (IMainLoopCoordinator)}inexplicably became null during Run");
177175
}
176+
178177
_coordinator.RunIteration ();
179178
}
180179
}
@@ -209,27 +208,24 @@ public override void RequestStop (Toplevel? top)
209208
public override void Invoke (Action action)
210209
{
211210
_timedEvents.AddIdle (
212-
() =>
213-
{
214-
action ();
211+
() =>
212+
{
213+
action ();
215214

216-
return false;
217-
}
218-
);
215+
return false;
216+
}
217+
);
219218
}
220219

221220
/// <inheritdoc/>
222221
public override void AddIdle (Func<bool> func) { _timedEvents.AddIdle (func); }
223222

224223
/// <summary>
225-
/// Removes an idle function added by <see cref="AddIdle"/>
224+
/// Removes an idle function added by <see cref="AddIdle"/>
226225
/// </summary>
227226
/// <param name="fnTrue">Function to remove</param>
228227
/// <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); }
233229

234230
/// <inheritdoc/>
235231
public override object AddTimeout (TimeSpan time, Func<bool> callback) { return _timedEvents.AddTimeout (time, callback); }

Terminal.Gui/ConsoleDrivers/V2/ConsoleDriverFacade.cs

+12-11
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,16 @@ namespace Terminal.Gui;
44

55
internal class ConsoleDriverFacade<T> : IConsoleDriver, IConsoleDriverFacade
66
{
7-
private readonly IInputProcessor _inputProcessor;
87
private readonly IConsoleOutput _output;
98
private readonly IOutputBuffer _outputBuffer;
109
private readonly AnsiRequestScheduler _ansiRequestScheduler;
1110
private CursorVisibility _lastCursor = CursorVisibility.Default;
1211

1312
/// <summary>The event fired when the terminal is resized.</summary>
1413
public event EventHandler<SizeChangedEventArgs> SizeChanged;
15-
public IInputProcessor InputProcessor => _inputProcessor;
14+
15+
public IInputProcessor InputProcessor { get; }
16+
1617
public ConsoleDriverFacade (
1718
IInputProcessor inputProcessor,
1819
IOutputBuffer outputBuffer,
@@ -21,14 +22,14 @@ public ConsoleDriverFacade (
2122
IWindowSizeMonitor windowSizeMonitor
2223
)
2324
{
24-
_inputProcessor = inputProcessor;
25+
InputProcessor = inputProcessor;
2526
_output = output;
2627
_outputBuffer = outputBuffer;
2728
_ansiRequestScheduler = ansiRequestScheduler;
2829

29-
_inputProcessor.KeyDown += (s, e) => KeyDown?.Invoke (s, e);
30-
_inputProcessor.KeyUp += (s, e) => KeyUp?.Invoke (s, e);
31-
_inputProcessor.MouseEvent += (s, e) => MouseEvent?.Invoke (s, e);
30+
InputProcessor.KeyDown += (s, e) => KeyDown?.Invoke (s, e);
31+
InputProcessor.KeyUp += (s, e) => KeyUp?.Invoke (s, e);
32+
InputProcessor.MouseEvent += (s, e) => MouseEvent?.Invoke (s, e);
3233

3334
windowSizeMonitor.SizeChanging += (_, e) => SizeChanged?.Invoke (this, e);
3435

@@ -226,18 +227,18 @@ public void ClearContents ()
226227
/// <inheritdoc/>
227228
public virtual string GetVersionInfo ()
228229
{
229-
string type = "";
230+
var type = "";
230231

231-
if (_inputProcessor is WindowsInputProcessor)
232+
if (InputProcessor is WindowsInputProcessor)
232233
{
233234
type = "(win)";
234235
}
235-
else if (_inputProcessor is NetInputProcessor)
236+
else if (InputProcessor is NetInputProcessor)
236237
{
237238
type = "(net)";
238239
}
239240

240-
return GetType().Name.TrimEnd('`','1') + type;
241+
return GetType ().Name.TrimEnd ('`', '1') + type;
241242
}
242243

243244
/// <summary>Tests if the specified rune is supported by the driver.</summary>
@@ -384,4 +385,4 @@ public void Refresh ()
384385
{
385386
// No need we will always draw when dirty
386387
}
387-
}
388+
}

Terminal.Gui/ConsoleDrivers/V2/ConsoleInput.cs

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
#nullable enable
22
using System.Collections.Concurrent;
3-
using System.Diagnostics.Metrics;
43

54
namespace Terminal.Gui;
65

76
/// <summary>
8-
/// Base class for reading console input in perpetual loop
7+
/// Base class for reading console input in perpetual loop
98
/// </summary>
109
/// <typeparam name="T"></typeparam>
1110
public abstract class ConsoleInput<T> : IConsoleInput<T>
@@ -18,7 +17,6 @@ public abstract class ConsoleInput<T> : IConsoleInput<T>
1817
/// </summary>
1918
public Func<DateTime> Now { get; set; } = () => DateTime.Now;
2019

21-
2220
/// <inheritdoc/>
2321
public virtual void Dispose () { }
2422

Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
namespace Terminal.Gui;
22

33
/// <summary>
4-
/// Interface for v2 driver abstraction layer
4+
/// Interface for v2 driver abstraction layer
55
/// </summary>
66
public interface IConsoleDriverFacade
77
{
88
/// <summary>
9-
/// Class responsible for processing native driver input objects
10-
/// e.g. <see cref="ConsoleKeyInfo"/> into <see cref="Key"/> events
11-
/// and detecting and processing ansi escape sequences.
9+
/// Class responsible for processing native driver input objects
10+
/// e.g. <see cref="ConsoleKeyInfo"/> into <see cref="Key"/> events
11+
/// and detecting and processing ansi escape sequences.
1212
/// </summary>
1313
public IInputProcessor InputProcessor { get; }
1414
}

Terminal.Gui/ConsoleDrivers/V2/IConsoleInput.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
namespace Terminal.Gui;
44

55
/// <summary>
6-
/// Interface for reading console input indefinitely -
7-
/// i.e. in an infinite loop. The class is responsible only
8-
/// for reading and storing the input in a thread safe input buffer
9-
/// which is then processed downstream e.g. on main UI thread.
6+
/// Interface for reading console input indefinitely -
7+
/// i.e. in an infinite loop. The class is responsible only
8+
/// for reading and storing the input in a thread safe input buffer
9+
/// which is then processed downstream e.g. on main UI thread.
1010
/// </summary>
1111
/// <typeparam name="T"></typeparam>
1212
public interface IConsoleInput<T> : IDisposable

Terminal.Gui/ConsoleDrivers/V2/IConsoleOutput.cs

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,40 @@
11
namespace Terminal.Gui;
22

33
/// <summary>
4-
/// Interface for writing console output
4+
/// Interface for writing console output
55
/// </summary>
66
public interface IConsoleOutput : IDisposable
77
{
88
/// <summary>
9-
/// Writes the given text directly to the console. Use to send
10-
/// ansi escape codes etc. Regular screen output should use the
11-
/// <see cref="IOutputBuffer"/> overload.
9+
/// Writes the given text directly to the console. Use to send
10+
/// ansi escape codes etc. Regular screen output should use the
11+
/// <see cref="IOutputBuffer"/> overload.
1212
/// </summary>
1313
/// <param name="text"></param>
1414
void Write (string text);
1515

1616
/// <summary>
17-
/// Write the contents of the <paramref name="buffer"/> to the console
17+
/// Write the contents of the <paramref name="buffer"/> to the console
1818
/// </summary>
1919
/// <param name="buffer"></param>
2020
void Write (IOutputBuffer buffer);
2121

2222
/// <summary>
23-
/// Returns the current size of the console window in rows/columns (i.e.
24-
/// of characters not pixels).
23+
/// Returns the current size of the console window in rows/columns (i.e.
24+
/// of characters not pixels).
2525
/// </summary>
2626
/// <returns></returns>
2727
public Size GetWindowSize ();
2828

2929
/// <summary>
30-
/// Updates the console cursor (the blinking underscore) to be hidden,
31-
/// visible etc.
30+
/// Updates the console cursor (the blinking underscore) to be hidden,
31+
/// visible etc.
3232
/// </summary>
3333
/// <param name="visibility"></param>
3434
void SetCursorVisibility (CursorVisibility visibility);
3535

3636
/// <summary>
37-
/// Moves the console cursor to the given location.
37+
/// Moves the console cursor to the given location.
3838
/// </summary>
3939
/// <param name="col"></param>
4040
/// <param name="row"></param>

Terminal.Gui/ConsoleDrivers/V2/IInputProcessor.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
namespace Terminal.Gui;
33

44
/// <summary>
5-
/// Interface for main loop class that will process the queued input buffer contents.
6-
/// Is responsible for <see cref="ProcessQueue"/> and translating into common Terminal.Gui
7-
/// events and data models.
5+
/// Interface for main loop class that will process the queued input buffer contents.
6+
/// Is responsible for <see cref="ProcessQueue"/> and translating into common Terminal.Gui
7+
/// events and data models.
88
/// </summary>
99
public interface IInputProcessor
1010
{
@@ -53,7 +53,7 @@ public interface IInputProcessor
5353
void ProcessQueue ();
5454

5555
/// <summary>
56-
/// Gets the response parser currently configured on this input processor.
56+
/// Gets the response parser currently configured on this input processor.
5757
/// </summary>
5858
/// <returns></returns>
5959
public IAnsiResponseParser GetParser ();
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
namespace Terminal.Gui;
22

33
/// <summary>
4-
/// Interface for subcomponent of a <see cref="InputProcessor{T}"/> which
5-
/// can translate the raw console input type T (which typically varies by
6-
/// driver) to the shared Terminal.Gui <see cref="Key"/> class.
4+
/// Interface for subcomponent of a <see cref="InputProcessor{T}"/> which
5+
/// can translate the raw console input type T (which typically varies by
6+
/// driver) to the shared Terminal.Gui <see cref="Key"/> class.
77
/// </summary>
88
/// <typeparam name="T"></typeparam>
99
public interface IKeyConverter<in T>
1010
{
1111
/// <summary>
12-
/// Converts the native keyboard class read from console into
13-
/// the shared <see cref="Key"/> class used by Terminal.Gui views.
12+
/// Converts the native keyboard class read from console into
13+
/// the shared <see cref="Key"/> class used by Terminal.Gui views.
1414
/// </summary>
1515
/// <param name="value"></param>
1616
/// <returns></returns>
17-
Key ToKey(T value);
18-
}
17+
Key ToKey (T value);
18+
}

0 commit comments

Comments
 (0)