-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
26 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,41 @@ | ||
using System; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Avalonia.Controls.ApplicationLifetimes; | ||
using Avalonia.Threading; | ||
|
||
namespace Consolonia.Core.Infrastructure; | ||
|
||
public class ConsoloniaLifetime : ClassicDesktopStyleApplicationLifetime | ||
namespace Consolonia.Core.Infrastructure | ||
{ | ||
/// <summary> | ||
/// returned task indicates that console is successfully paused | ||
/// </summary> | ||
public Task DisconnectFromConsoleAsync(CancellationToken cancellationToken) | ||
public class ConsoloniaLifetime : ClassicDesktopStyleApplicationLifetime | ||
{ | ||
var taskToWaitFor = new TaskCompletionSource(); | ||
cancellationToken.Register(() => taskToWaitFor.SetResult()); | ||
/// <summary> | ||
/// returned task indicates that console is successfully paused | ||
/// </summary> | ||
public Task DisconnectFromConsoleAsync(CancellationToken cancellationToken) | ||
{ | ||
var taskToWaitFor = new TaskCompletionSource(); | ||
cancellationToken.Register(() => taskToWaitFor.SetResult()); | ||
|
||
var mainWindowPlatformImpl = (ConsoleWindow)MainWindow.PlatformImpl; | ||
IConsole console = mainWindowPlatformImpl.Console; | ||
var mainWindowPlatformImpl = (ConsoleWindow)MainWindow.PlatformImpl; | ||
IConsole console = mainWindowPlatformImpl.Console; | ||
|
||
Task pauseTask = taskToWaitFor.Task; | ||
Task pauseTask = taskToWaitFor.Task; | ||
|
||
console.PauseIO(pauseTask); | ||
console.PauseIO(pauseTask); | ||
|
||
pauseTask.ContinueWith(_ => | ||
{ | ||
mainWindowPlatformImpl.Console.ClearOutput(); | ||
|
||
Dispatcher.UIThread.Post(() => | ||
pauseTask.ContinueWith(_ => | ||
{ | ||
MainWindow.InvalidateVisual(); | ||
}); | ||
}, CancellationToken.None, TaskContinuationOptions.None, TaskScheduler.Default); | ||
mainWindowPlatformImpl.Console.ClearOutput(); | ||
|
||
return Dispatcher.UIThread.InvokeAsync(() => | ||
{ | ||
Dispatcher.UIThread.Post(() => | ||
{ | ||
MainWindow.InvalidateVisual(); | ||
}); | ||
}, CancellationToken.None, TaskContinuationOptions.None, TaskScheduler.Default); | ||
|
||
return Dispatcher.UIThread.InvokeAsync(() => | ||
{ | ||
|
||
}); | ||
}); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters