From 52e7466ef991d43ec7698adc024293618b2349c0 Mon Sep 17 00:00:00 2001 From: Riley Carlson <43221493+rccarlson@users.noreply.github.com> Date: Thu, 30 Nov 2023 14:12:16 -0800 Subject: [PATCH] Make Driver population code more concise (#3024) * Make Driver population code more concise This is effectively a NOP change, just makes it a little more terse * Restore old behavior of null check after populating Driver --------- Co-authored-by: Riley Carlson --- Terminal.Gui/Application.cs | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/Terminal.Gui/Application.cs b/Terminal.Gui/Application.cs index ebc22b71f..34df8b3ef 100644 --- a/Terminal.Gui/Application.cs +++ b/Terminal.Gui/Application.cs @@ -158,22 +158,14 @@ namespace Terminal.Gui { ConfigurationManager.Load (true); ConfigurationManager.Apply (); - if (Driver == null) { - var p = Environment.OSVersion.Platform; - if (_forceFakeConsole) { - // For Unit Testing only - Driver = new FakeDriver (); - } else if (UseSystemConsole) { - Driver = new NetDriver (); - } else if (p == PlatformID.Win32NT || p == PlatformID.Win32S || p == PlatformID.Win32Windows) { - Driver = new WindowsDriver (); - } else { - Driver = new CursesDriver (); - } - if (Driver == null) { - throw new InvalidOperationException ("Init could not determine the ConsoleDriver to use."); - } - } + Driver ??= Environment.OSVersion.Platform switch { + _ when _forceFakeConsole => new FakeDriver (), // for unit testing only + _ when UseSystemConsole => new NetDriver (), + PlatformID.Win32NT or PlatformID.Win32S or PlatformID.Win32Windows => new WindowsDriver (), + _ => new CursesDriver (), + }; + + if (Driver == null) throw new InvalidOperationException ("Init could not determine the ConsoleDriver to use."); try { MainLoop = Driver.Init ();