浏览代码

Moved NetDriver's IMainLoopDriver impl to NetDriver.cs

Charlie Kindel 5 年之前
父节点
当前提交
532285db8d

+ 4 - 5
Example/demo.cs

@@ -1,13 +1,12 @@
-using Terminal.Gui;
+using NStack;
 using System;
 using System;
-using System.Linq;
-using System.IO;
 using System.Collections.Generic;
 using System.Collections.Generic;
 using System.Diagnostics;
 using System.Diagnostics;
 using System.Globalization;
 using System.Globalization;
+using System.IO;
+using System.Linq;
 using System.Reflection;
 using System.Reflection;
-using NStack;
-using System.Text;
+using Terminal.Gui;
 
 
 static class Demo {
 static class Demo {
 	//class Box10x : View, IScrollView {
 	//class Box10x : View, IScrollView {

+ 1 - 9
Terminal.Gui/ConsoleDrivers/CursesDriver/README.md

@@ -2,12 +2,4 @@ This directory contains a copy of the MonoCurses binding from:
 
 
 http://github.com/mono/mono-curses
 http://github.com/mono/mono-curses
 
 
-The source code has been exported in a way that the MonoCurses
-API is kept private and does not surface to the user, this is
-done with the command:
-
-```
-	make publish-to-gui
-```
-
-In the MonoCurses package
+The code has diverged from `mono-curses` a it's been leveraged for `Terminal.Gui`'s Curses driver.

+ 1 - 69
Terminal.Gui/ConsoleDrivers/CursesDriver/UnixMainLoop.cs

@@ -25,10 +25,9 @@
 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 //
 //
-using System.Collections.Generic;
 using System;
 using System;
+using System.Collections.Generic;
 using System.Runtime.InteropServices;
 using System.Runtime.InteropServices;
-using System.Threading;
 
 
 namespace Terminal.Gui {
 namespace Terminal.Gui {
 	/// <summary>
 	/// <summary>
@@ -227,71 +226,4 @@ namespace Terminal.Gui {
 			}
 			}
 		}
 		}
 	}
 	}
-
-	/// <summary>
-	/// Mainloop intended to be used with the .NET System.Console API, and can
-	/// be used on Windows and Unix, it is cross platform but lacks things like
-	/// file descriptor monitoring.
-	/// </summary>
-	class NetMainLoop : IMainLoopDriver {
-		AutoResetEvent keyReady = new AutoResetEvent (false);
-		AutoResetEvent waitForProbe = new AutoResetEvent (false);
-		ConsoleKeyInfo? windowsKeyResult = null;
-		public Action<ConsoleKeyInfo> WindowsKeyPressed;
-		MainLoop mainLoop;
-
-		public NetMainLoop ()
-		{
-		}
-
-		void WindowsKeyReader ()
-		{
-			while (true) {
-				waitForProbe.WaitOne ();
-				windowsKeyResult = Console.ReadKey (true);
-				keyReady.Set ();
-			}
-		}
-
-		void IMainLoopDriver.Setup (MainLoop mainLoop)
-		{
-			this.mainLoop = mainLoop;
-			Thread readThread = new Thread (WindowsKeyReader);
-			readThread.Start ();
-		}
-
-		void IMainLoopDriver.Wakeup ()
-		{
-		}
-
-		bool IMainLoopDriver.EventsPending (bool wait)
-		{
-			long now = DateTime.UtcNow.Ticks;
-
-			int waitTimeout;
-			if (mainLoop.timeouts.Count > 0) {
-				waitTimeout = (int)((mainLoop.timeouts.Keys [0] - now) / TimeSpan.TicksPerMillisecond);
-				if (waitTimeout < 0)
-					return true;
-			} else
-				waitTimeout = -1;
-
-			if (!wait)
-				waitTimeout = 0;
-
-			windowsKeyResult = null;
-			waitForProbe.Set ();
-			keyReady.WaitOne (waitTimeout);
-			return windowsKeyResult.HasValue;
-		}
-
-		void IMainLoopDriver.MainIteration ()
-		{
-			if (windowsKeyResult.HasValue) {
-				if (WindowsKeyPressed!= null)
-					WindowsKeyPressed (windowsKeyResult.Value);
-				windowsKeyResult = null;
-			}
-		}
-	}
 }
 }

+ 0 - 1
Terminal.Gui/ConsoleDrivers/CursesDriver/binding.cs

@@ -42,7 +42,6 @@
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 //
 //
 using System;
 using System;
-using System.IO;
 using System.Runtime.InteropServices;
 using System.Runtime.InteropServices;
 
 
 namespace Unix.Terminal {
 namespace Unix.Terminal {

+ 0 - 1
Terminal.Gui/ConsoleDrivers/CursesDriver/handles.cs

@@ -26,7 +26,6 @@
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 //
 //
 using System;
 using System;
-using System.Runtime.InteropServices;
 
 
 namespace Unix.Terminal {
 namespace Unix.Terminal {
 
 

+ 68 - 0
Terminal.Gui/ConsoleDrivers/NetDriver.cs

@@ -7,10 +7,78 @@
 using System;
 using System;
 using System.Collections.Generic;
 using System.Collections.Generic;
 using System.Linq;
 using System.Linq;
+using System.Threading;
 using NStack;
 using NStack;
 
 
 namespace Terminal.Gui {
 namespace Terminal.Gui {
 
 
+	/// <summary>
+	/// Mainloop intended to be used with the .NET System.Console API, and can
+	/// be used on Windows and Unix, it is cross platform but lacks things like
+	/// file descriptor monitoring.
+	/// </summary>
+	class NetMainLoop : IMainLoopDriver {
+		AutoResetEvent keyReady = new AutoResetEvent (false);
+		AutoResetEvent waitForProbe = new AutoResetEvent (false);
+		ConsoleKeyInfo? windowsKeyResult = null;
+		public Action<ConsoleKeyInfo> WindowsKeyPressed;
+		MainLoop mainLoop;
+
+		public NetMainLoop ()
+		{
+		}
+
+		void WindowsKeyReader ()
+		{
+			while (true) {
+				waitForProbe.WaitOne ();
+				windowsKeyResult = Console.ReadKey (true);
+				keyReady.Set ();
+			}
+		}
+
+		void IMainLoopDriver.Setup (MainLoop mainLoop)
+		{
+			this.mainLoop = mainLoop;
+			Thread readThread = new Thread (WindowsKeyReader);
+			readThread.Start ();
+		}
+
+		void IMainLoopDriver.Wakeup ()
+		{
+		}
+
+		bool IMainLoopDriver.EventsPending (bool wait)
+		{
+			long now = DateTime.UtcNow.Ticks;
+
+			int waitTimeout;
+			if (mainLoop.timeouts.Count > 0) {
+				waitTimeout = (int)((mainLoop.timeouts.Keys [0] - now) / TimeSpan.TicksPerMillisecond);
+				if (waitTimeout < 0)
+					return true;
+			} else
+				waitTimeout = -1;
+
+			if (!wait)
+				waitTimeout = 0;
+
+			windowsKeyResult = null;
+			waitForProbe.Set ();
+			keyReady.WaitOne (waitTimeout);
+			return windowsKeyResult.HasValue;
+		}
+
+		void IMainLoopDriver.MainIteration ()
+		{
+			if (windowsKeyResult.HasValue) {
+				if (WindowsKeyPressed != null)
+					WindowsKeyPressed (windowsKeyResult.Value);
+				windowsKeyResult = null;
+			}
+		}
+	}
+
 	internal class NetDriver : ConsoleDriver {
 	internal class NetDriver : ConsoleDriver {
 		int cols, rows;
 		int cols, rows;
 		public override int Cols => cols;
 		public override int Cols => cols;

+ 1 - 3
Terminal.Gui/ConsoleDrivers/WindowsDriver.cs

@@ -25,13 +25,11 @@
 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 // SOFTWARE.
 // SOFTWARE.
 //
 //
+using NStack;
 using System;
 using System;
-using System.CodeDom;
-using System.Diagnostics;
 using System.Runtime.InteropServices;
 using System.Runtime.InteropServices;
 using System.Threading;
 using System.Threading;
 using System.Threading.Tasks;
 using System.Threading.Tasks;
-using NStack;
 
 
 namespace Terminal.Gui {
 namespace Terminal.Gui {
 
 

+ 6 - 2
Terminal.Gui/Core/MainLoop.cs

@@ -1,9 +1,13 @@
-
+//
+// MainLoop.cs: IMainLoopDriver and MainLoop for Terminal.Gui
+//
+// Authors:
+//   Miguel de Icaza ([email protected])
+//
 using System;
 using System;
 using System.Collections.Generic;
 using System.Collections.Generic;
 
 
 namespace Terminal.Gui {
 namespace Terminal.Gui {
-
 	/// <summary>
 	/// <summary>
 	/// Public interface to create your own platform specific main loop driver.
 	/// Public interface to create your own platform specific main loop driver.
 	/// </summary>
 	/// </summary>