From d531e2562f14106a81a6bbb2d8726822f8008888 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Tue, 21 Nov 2023 11:16:27 +0000 Subject: [PATCH] Automated JetBrains cleanup Co-authored-by: <+@users.noreply.github.com> --- .../Infrastructure/ConsoleWindow.cs | 2 +- .../Infrastructure/ConsoloniaLifetime.cs | 16 +-- .../InputLessDefaultNetConsole.cs | 24 ++-- .../WindowsConsole.cs | 114 +++++++++--------- .../Consolonia.TestsCore/UnitTestConsole.cs | 22 ++-- 5 files changed, 86 insertions(+), 92 deletions(-) diff --git a/src/Consolonia.Core/Infrastructure/ConsoleWindow.cs b/src/Consolonia.Core/Infrastructure/ConsoleWindow.cs index 2d4d43af..d3c49aed 100644 --- a/src/Consolonia.Core/Infrastructure/ConsoleWindow.cs +++ b/src/Consolonia.Core/Infrastructure/ConsoleWindow.cs @@ -15,8 +15,8 @@ namespace Consolonia.Core.Infrastructure { internal class ConsoleWindow : IWindowImpl { - [NotNull] internal readonly IConsole Console; private readonly IKeyboardDevice _myKeyboardDevice; + [NotNull] internal readonly IConsole Console; internal readonly List InvalidatedRects = new(50); private IInputRoot _inputRoot; diff --git a/src/Consolonia.Core/Infrastructure/ConsoloniaLifetime.cs b/src/Consolonia.Core/Infrastructure/ConsoloniaLifetime.cs index 0954d8d9..a4b800c0 100644 --- a/src/Consolonia.Core/Infrastructure/ConsoloniaLifetime.cs +++ b/src/Consolonia.Core/Infrastructure/ConsoloniaLifetime.cs @@ -8,7 +8,7 @@ namespace Consolonia.Core.Infrastructure public class ConsoloniaLifetime : ClassicDesktopStyleApplicationLifetime { /// - /// returned task indicates that console is successfully paused + /// returned task indicates that console is successfully paused /// public Task DisconnectFromConsoleAsync(CancellationToken cancellationToken) { @@ -17,25 +17,19 @@ public Task DisconnectFromConsoleAsync(CancellationToken cancellationToken) var mainWindowPlatformImpl = (ConsoleWindow)MainWindow.PlatformImpl; IConsole console = mainWindowPlatformImpl.Console; - + Task pauseTask = taskToWaitFor.Task; - + console.PauseIO(pauseTask); pauseTask.ContinueWith(_ => { mainWindowPlatformImpl.Console.ClearOutput(); - Dispatcher.UIThread.Post(() => - { - MainWindow.InvalidateVisual(); - }); + Dispatcher.UIThread.Post(() => { MainWindow.InvalidateVisual(); }); }, CancellationToken.None, TaskContinuationOptions.None, TaskScheduler.Default); - return Dispatcher.UIThread.InvokeAsync(() => - { - - }); + return Dispatcher.UIThread.InvokeAsync(() => { }); } } } \ No newline at end of file diff --git a/src/Consolonia.Core/Infrastructure/InputLessDefaultNetConsole.cs b/src/Consolonia.Core/Infrastructure/InputLessDefaultNetConsole.cs index 6b6bdcd6..7f114fc3 100644 --- a/src/Consolonia.Core/Infrastructure/InputLessDefaultNetConsole.cs +++ b/src/Consolonia.Core/Infrastructure/InputLessDefaultNetConsole.cs @@ -25,6 +25,8 @@ protected InputLessDefaultNetConsole() protected bool Disposed { get; private set; } + protected Task PauseTask { get; private set; } + public bool CaretVisible { get => _caretVisible; @@ -103,21 +105,26 @@ public void Print(PixelBufferCoordinate bufferPoint, ConsoleColor backgroundColo public event Action KeyEvent; public event Action MouseEvent; public event Action FocusEvent; - + public virtual void PauseIO(Task task) { task.ContinueWith(_ => { PauseTask = null; }, TaskScheduler.Default); PauseTask = task; } - protected Task PauseTask { get; private set; } - public void Dispose() { Dispose(true); GC.SuppressFinalize(this); } + public void ClearOutput() + { + // this is hack, but somehow it does not work when just calling ActualizeSize with same size + Size = new PixelBufferSize(1, 1); + Resized?.Invoke(); + } + // ReSharper disable once MemberCanBePrivate.Global protected bool CheckActualizeTheSize() { @@ -132,13 +139,6 @@ protected void ActualizeSize() Resized?.Invoke(); } - public void ClearOutput() - { - // this is hack, but somehow it does not work when just calling ActualizeSize with same size - Size = new PixelBufferSize(1, 1); - Resized?.Invoke(); - } - protected void RaiseMouseEvent(RawPointerEventType eventType, Point point, Vector? wheelDelta, RawInputModifiers modifiers) { @@ -167,9 +167,9 @@ protected void StartSizeCheckTimerAsync(uint slowInterval = 1500) while (!Disposed) { Task pauseTask = PauseTask; - if(pauseTask!=null) + if (pauseTask != null) await pauseTask.ConfigureAwait(false); - + int timeout = (int)(CheckActualizeTheSize() ? 1 : slowInterval); await Task.Delay(timeout).ConfigureAwait(false); } diff --git a/src/Consolonia.PlatformSupport/WindowsConsole.cs b/src/Consolonia.PlatformSupport/WindowsConsole.cs index 65d94a17..5c8f42f5 100644 --- a/src/Consolonia.PlatformSupport/WindowsConsole.cs +++ b/src/Consolonia.PlatformSupport/WindowsConsole.cs @@ -60,66 +60,10 @@ public Win32Console() StartEventLoop(); } - #region chatGPT - - // Resharper disable MemberCanBePrivate.Global - // Resharper disable MemberCanBePrivate.Local - // Resharper disable FieldCanBeMadeReadOnly.Global - // Resharper disable FieldCanBeMadeReadOnly.Local - // ReSharper disable InconsistentNaming - [StructLayout(LayoutKind.Sequential)] - private struct INPUT_RECORD - { - public ushort EventType; - public UnionRecord Event; - - [StructLayout(LayoutKind.Explicit)] - public struct UnionRecord - { - [FieldOffset(0)] - public KEY_EVENT_RECORD KeyEvent; - [FieldOffset(0)] - public FOCUS_EVENT_RECORD FocusEvent; - // Other event types omitted for brevity - } - } - - [StructLayout(LayoutKind.Sequential)] - internal struct KEY_EVENT_RECORD - { -#pragma warning disable IDE1006 - public bool bKeyDown; -#pragma warning restore IDE1006 - // Other fields omitted for brevity - } - - [StructLayout(LayoutKind.Sequential)] - private struct FOCUS_EVENT_RECORD - { -#pragma warning disable IDE1006 - public bool bSetFocus; -#pragma warning restore IDE1006 - } - - [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode)] -#pragma warning disable CA5392 - private static extern bool WriteConsoleInput( -#pragma warning restore CA5392 - IntPtr hConsoleInput, - INPUT_RECORD[] lpBuffer, - uint nLength, - out uint lpNumberOfEventsWritten); - // Resharper restore MemberCanBePrivate.Global - // Resharper restore MemberCanBePrivate.Local - // Resharper restore FieldCanBeMadeReadOnly.Global - // Resharper restore FieldCanBeMadeReadOnly.Local -// ReSharper restore InconsistentNaming - #endregion - public override void PauseIO(Task task) { base.PauseIO(task); - + var inputRecords = new INPUT_RECORD[1]; // Create a focus event @@ -259,5 +203,61 @@ private void HandleKeyInput(WindowsConsole.InputRecord inputRecord) RaiseKeyPress(DefaultNetConsole.ConvertToKey((ConsoleKey)keyEvent.wVirtualKeyCode), character, modifiers, keyEvent.bKeyDown, (ulong)Stopwatch.GetTimestamp()); } + + #region chatGPT + + // Resharper disable MemberCanBePrivate.Global + // Resharper disable MemberCanBePrivate.Local + // Resharper disable FieldCanBeMadeReadOnly.Global + // Resharper disable FieldCanBeMadeReadOnly.Local + // ReSharper disable InconsistentNaming + [StructLayout(LayoutKind.Sequential)] + private struct INPUT_RECORD + { + public ushort EventType; + public UnionRecord Event; + + [StructLayout(LayoutKind.Explicit)] + public struct UnionRecord + { + [FieldOffset(0)] public KEY_EVENT_RECORD KeyEvent; + + [FieldOffset(0)] public FOCUS_EVENT_RECORD FocusEvent; + // Other event types omitted for brevity + } + } + + [StructLayout(LayoutKind.Sequential)] + internal struct KEY_EVENT_RECORD + { +#pragma warning disable IDE1006 + public bool bKeyDown; +#pragma warning restore IDE1006 + // Other fields omitted for brevity + } + + [StructLayout(LayoutKind.Sequential)] + private struct FOCUS_EVENT_RECORD + { +#pragma warning disable IDE1006 + public bool bSetFocus; +#pragma warning restore IDE1006 + } + + [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode)] +#pragma warning disable CA5392 + private static extern bool WriteConsoleInput( +#pragma warning restore CA5392 + IntPtr hConsoleInput, + INPUT_RECORD[] lpBuffer, + uint nLength, + out uint lpNumberOfEventsWritten); + // Resharper restore MemberCanBePrivate.Global + // Resharper restore MemberCanBePrivate.Local + // Resharper restore FieldCanBeMadeReadOnly.Global + // Resharper restore FieldCanBeMadeReadOnly.Local +// ReSharper restore InconsistentNaming + + #endregion } } \ No newline at end of file diff --git a/src/Tests/Consolonia.TestsCore/UnitTestConsole.cs b/src/Tests/Consolonia.TestsCore/UnitTestConsole.cs index 78d8739b..01aaf7c5 100644 --- a/src/Tests/Consolonia.TestsCore/UnitTestConsole.cs +++ b/src/Tests/Consolonia.TestsCore/UnitTestConsole.cs @@ -64,6 +64,17 @@ void IConsole.Print(PixelBufferCoordinate bufferPoint, ConsoleColor backgroundCo new PixelBackground(PixelBackgroundMode.Colored, backgroundColor))); } + public void PauseIO(Task task) + { + throw new NotSupportedException(); + } + + public void ClearOutput() + { + // screen of the unit test console is always clear, we are writing only to the buffer + Resized?.Invoke(); + } + public async Task StringInput(string input) { @@ -146,16 +157,5 @@ public void SetupLifetime(ClassicDesktopStyleApplicationLifetime lifetime) public event Action MouseEvent; public event Action FocusEvent; #pragma warning restore CS0067 - - public void PauseIO(Task task) - { - throw new NotSupportedException(); - } - - public void ClearOutput() - { - // screen of the unit test console is always clear, we are writing only to the buffer - Resized?.Invoke(); - } } } \ No newline at end of file