Skip to content

Commit

Permalink
Support specify v2net or v2win
Browse files Browse the repository at this point in the history
  • Loading branch information
tznind committed Dec 14, 2024
1 parent 293fe4e commit f0a5e04
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 22 deletions.
65 changes: 45 additions & 20 deletions Terminal.Gui/ConsoleDrivers/V2/ApplicationV2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ namespace Terminal.Gui.ConsoleDrivers.V2;

public class ApplicationV2 : ApplicationImpl
{
private readonly string _driver;
private IMainLoopCoordinator _coordinator;
public ITimedEvents TimedEvents { get; } = new TimedEvents ();
public ApplicationV2 ()
public ApplicationV2 (string driver = null)
{
_driver = driver;
IsLegacy = false;
}

Expand All @@ -19,39 +21,38 @@ public override void Init (IConsoleDriver driver = null, string driverName = nul

Application.AddKeyBindings ();

CreateDriver ();
CreateDriver (_driver ?? driverName);

Application.Initialized = true;

Application.SubscribeDriverEvents ();
}

private void CreateDriver ()
private void CreateDriver (string driverName)
{

PlatformID p = Environment.OSVersion.Platform;

if ( p == PlatformID.Win32NT || p == PlatformID.Win32S || p == PlatformID.Win32Windows)
var definetlyWin = driverName?.Contains ("win") ?? false;
var definetlyNet = driverName?.Contains ("net") ?? false;

if (definetlyWin)
{
CreateWindowsSubcomponents ();

}
else if (definetlyNet)
{
CreateNetSubcomponents ();
}
else
if (p == PlatformID.Win32NT || p == PlatformID.Win32S || p == PlatformID.Win32Windows)
{
var inputBuffer = new ConcurrentQueue<WindowsConsole.InputRecord> ();
var loop = new MainLoop<WindowsConsole.InputRecord> ();
_coordinator = new MainLoopCoordinator<WindowsConsole.InputRecord> (TimedEvents,
() => new WindowsInput (),
inputBuffer,
new WindowsInputProcessor (inputBuffer),
() => new WindowsOutput (),
loop);
CreateWindowsSubcomponents ();
}
else
{
var inputBuffer = new ConcurrentQueue<ConsoleKeyInfo> ();
var loop = new MainLoop<ConsoleKeyInfo> ();
_coordinator = new MainLoopCoordinator<ConsoleKeyInfo> (TimedEvents,
() => new NetInput (),
inputBuffer,
new NetInputProcessor (inputBuffer),
() => new NetOutput (),
loop);
CreateNetSubcomponents ();
}

_coordinator.StartAsync ();
Expand All @@ -67,6 +68,30 @@ private void CreateDriver ()
}
}


private void CreateWindowsSubcomponents ()
{
var inputBuffer = new ConcurrentQueue<WindowsConsole.InputRecord> ();
var loop = new MainLoop<WindowsConsole.InputRecord> ();
_coordinator = new MainLoopCoordinator<WindowsConsole.InputRecord> (TimedEvents,
() => new WindowsInput (),
inputBuffer,
new WindowsInputProcessor (inputBuffer),
() => new WindowsOutput (),
loop);
}
private void CreateNetSubcomponents ()
{
var inputBuffer = new ConcurrentQueue<ConsoleKeyInfo> ();
var loop = new MainLoop<ConsoleKeyInfo> ();
_coordinator = new MainLoopCoordinator<ConsoleKeyInfo> (TimedEvents,
() => new NetInput (),
inputBuffer,
new NetInputProcessor (inputBuffer),
() => new NetOutput (),
loop);
}

/// <inheritdoc />
public override T Run<T> (Func<Exception, bool> errorHandler = null, IConsoleDriver driver = null)
{
Expand Down
4 changes: 2 additions & 2 deletions UICatalog/UICatalog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -336,9 +336,9 @@ private static void UICatalogMain (Options options)
{
StartConfigFileWatcher ();

if (options.Driver == "v2")
if (options.Driver?.StartsWith ("v2")??false)
{
ApplicationImpl.ChangeInstance (new ApplicationV2 ());
ApplicationImpl.ChangeInstance (new ApplicationV2 (options.Driver));
options.Driver = string.Empty;
}

Expand Down

0 comments on commit f0a5e04

Please sign in to comment.