2
0
Эх сурвалжийг харах

Merge pull request #796 from BDisp/console-size

Fixes #786. Workaround for resizing with Init/Shutdown.
Charlie Kindel 5 жил өмнө
parent
commit
15d66a749b

+ 19 - 2
Terminal.Gui/ConsoleDrivers/WindowsDriver.cs

@@ -495,13 +495,30 @@ namespace Terminal.Gui {
 		public override int Rows => rows;
 
 		public WindowsDriver ()
+		{
+			Initialize ();
+		}
+
+		public WindowsDriver (int cols, int rows)
+		{
+			this.cols = cols;
+			this.rows = rows;
+
+			Initialize ();
+		}
+
+		void Initialize ()
 		{
 			winConsole = new WindowsConsole ();
 
 			SetupColorsAndBorders ();
 
-			cols = Console.WindowWidth;
-			rows = Console.WindowHeight;
+			if (cols == 0 && rows == 0) {
+				cols = Console.WindowWidth;
+				rows = Console.WindowHeight;
+			} else {
+				Console.SetWindowSize (cols, rows);
+			}
 			WindowsConsole.SmallRect.MakeEmpty (ref damageRegion);
 
 			ResizeScreen ();

+ 5 - 2
Terminal.Gui/Core/Application.cs

@@ -161,8 +161,9 @@ namespace Terminal.Gui {
 
 		internal static bool _initialized = false;
 
+		static int cols, rows;
 		static IMainLoopDriver oldMainLoopDriver;
-		static ConsoleDriver oldDriver;		
+		static ConsoleDriver oldDriver;
 
 		/// <summary>
 		/// Initializes the Terminal.Gui application
@@ -188,7 +189,7 @@ namespace Terminal.Gui {
 					mainLoopDriver = new NetMainLoop (() => Console.ReadKey (true));
 					Driver = new NetDriver ();
 				} else if (p == PlatformID.Win32NT || p == PlatformID.Win32S || p == PlatformID.Win32Windows) {
-					var windowsDriver = new WindowsDriver ();
+					var windowsDriver = cols == 0 && rows == 0 ? new WindowsDriver () : new WindowsDriver (cols, rows);
 					mainLoopDriver = windowsDriver;
 					Driver = windowsDriver;
 				} else {
@@ -556,6 +557,8 @@ namespace Terminal.Gui {
 			}
 			last?.PositionCursor ();
 			Driver.Refresh ();
+			cols = Driver.Cols;
+			rows = Driver.Rows;
 		}
 
 		internal static void End (View view, bool closeDriver = true)

+ 1 - 1
UICatalog/Scenario.cs

@@ -198,7 +198,7 @@ namespace UICatalog {
 		public virtual void Run ()
 		{
 			// This method already performs a later automatic shutdown.
-			Application.Run (Top, false);
+			Application.Run (Top);
 		}
 
 		/// <summary>

+ 2 - 2
UICatalog/UICatalog.cs

@@ -127,7 +127,7 @@ namespace UICatalog {
 			Application.UseSystemConsole = false;
 			Application.Init ();
 
-			// Set this here because not initilzied until driver is loaded
+			// Set this here because not initialized until driver is loaded
 			_baseColorScheme = Colors.Base;
 
 			StringBuilder aboutMessage = new StringBuilder ();
@@ -235,7 +235,7 @@ namespace UICatalog {
 				}
 			};
 
-			Application.Run (_top, true);
+			Application.Run (_top);
 			Application.Shutdown ();
 			return _runningScenario;
 		}