Skip to content

Commit

Permalink
Automated JetBrains cleanup
Browse files Browse the repository at this point in the history
Co-authored-by:  <[email protected]>
  • Loading branch information
github-actions[bot] committed Nov 21, 2023
1 parent 0c676f6 commit d531e25
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 92 deletions.
2 changes: 1 addition & 1 deletion src/Consolonia.Core/Infrastructure/ConsoleWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Rect> InvalidatedRects = new(50);
private IInputRoot _inputRoot;

Expand Down
16 changes: 5 additions & 11 deletions src/Consolonia.Core/Infrastructure/ConsoloniaLifetime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Consolonia.Core.Infrastructure
public class ConsoloniaLifetime : ClassicDesktopStyleApplicationLifetime
{
/// <summary>
/// returned task indicates that console is successfully paused
/// returned task indicates that console is successfully paused
/// </summary>
public Task DisconnectFromConsoleAsync(CancellationToken cancellationToken)
{
Expand All @@ -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(() => { });
}
}
}
24 changes: 12 additions & 12 deletions src/Consolonia.Core/Infrastructure/InputLessDefaultNetConsole.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ protected InputLessDefaultNetConsole()

protected bool Disposed { get; private set; }

protected Task PauseTask { get; private set; }

public bool CaretVisible
{
get => _caretVisible;
Expand Down Expand Up @@ -103,21 +105,26 @@ public void Print(PixelBufferCoordinate bufferPoint, ConsoleColor backgroundColo
public event Action<Key, char, RawInputModifiers, bool, ulong> KeyEvent;
public event Action<RawPointerEventType, Point, Vector?, RawInputModifiers> MouseEvent;
public event Action<bool> 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()
{
Expand All @@ -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)
{
Expand Down Expand Up @@ -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);
}
Expand Down
114 changes: 57 additions & 57 deletions src/Consolonia.PlatformSupport/WindowsConsole.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
}
22 changes: 11 additions & 11 deletions src/Tests/Consolonia.TestsCore/UnitTestConsole.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -146,16 +157,5 @@ public void SetupLifetime(ClassicDesktopStyleApplicationLifetime lifetime)
public event Action<RawPointerEventType, Point, Vector?, RawInputModifiers> MouseEvent;
public event Action<bool> 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();
}
}
}

0 comments on commit d531e25

Please sign in to comment.