diff --git a/Example/demo.cs b/Example/demo.cs index e07764dcb..edae3a77b 100644 --- a/Example/demo.cs +++ b/Example/demo.cs @@ -1,13 +1,12 @@ -using Terminal.Gui; +using NStack; using System; -using System.Linq; -using System.IO; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; +using System.IO; +using System.Linq; using System.Reflection; -using NStack; -using System.Text; +using Terminal.Gui; static class Demo { //class Box10x : View, IScrollView { diff --git a/Terminal.Gui/ConsoleDrivers/CursesDriver/README.md b/Terminal.Gui/ConsoleDrivers/CursesDriver/README.md index 4ea82ddaf..c7254552b 100644 --- a/Terminal.Gui/ConsoleDrivers/CursesDriver/README.md +++ b/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 -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. \ No newline at end of file diff --git a/Terminal.Gui/ConsoleDrivers/CursesDriver/UnixMainLoop.cs b/Terminal.Gui/ConsoleDrivers/CursesDriver/UnixMainLoop.cs index 680ba2937..5d2ead344 100644 --- a/Terminal.Gui/ConsoleDrivers/CursesDriver/UnixMainLoop.cs +++ b/Terminal.Gui/ConsoleDrivers/CursesDriver/UnixMainLoop.cs @@ -25,10 +25,9 @@ // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // -using System.Collections.Generic; using System; +using System.Collections.Generic; using System.Runtime.InteropServices; -using System.Threading; namespace Terminal.Gui { /// @@ -227,71 +226,4 @@ namespace Terminal.Gui { } } } - - /// - /// 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. - /// - class NetMainLoop : IMainLoopDriver { - AutoResetEvent keyReady = new AutoResetEvent (false); - AutoResetEvent waitForProbe = new AutoResetEvent (false); - ConsoleKeyInfo? windowsKeyResult = null; - public Action 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; - } - } - } } diff --git a/Terminal.Gui/ConsoleDrivers/CursesDriver/binding.cs b/Terminal.Gui/ConsoleDrivers/CursesDriver/binding.cs index a8981dbea..ab963b8fc 100644 --- a/Terminal.Gui/ConsoleDrivers/CursesDriver/binding.cs +++ b/Terminal.Gui/ConsoleDrivers/CursesDriver/binding.cs @@ -42,7 +42,6 @@ // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // using System; -using System.IO; using System.Runtime.InteropServices; namespace Unix.Terminal { diff --git a/Terminal.Gui/ConsoleDrivers/CursesDriver/handles.cs b/Terminal.Gui/ConsoleDrivers/CursesDriver/handles.cs index e81528ade..606f7f86d 100644 --- a/Terminal.Gui/ConsoleDrivers/CursesDriver/handles.cs +++ b/Terminal.Gui/ConsoleDrivers/CursesDriver/handles.cs @@ -26,7 +26,6 @@ // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // using System; -using System.Runtime.InteropServices; namespace Unix.Terminal { diff --git a/Terminal.Gui/ConsoleDrivers/NetDriver.cs b/Terminal.Gui/ConsoleDrivers/NetDriver.cs index e224a85d7..04889ec90 100644 --- a/Terminal.Gui/ConsoleDrivers/NetDriver.cs +++ b/Terminal.Gui/ConsoleDrivers/NetDriver.cs @@ -7,10 +7,78 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Threading; using NStack; namespace Terminal.Gui { + /// + /// 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. + /// + class NetMainLoop : IMainLoopDriver { + AutoResetEvent keyReady = new AutoResetEvent (false); + AutoResetEvent waitForProbe = new AutoResetEvent (false); + ConsoleKeyInfo? windowsKeyResult = null; + public Action 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 { int cols, rows; public override int Cols => cols; diff --git a/Terminal.Gui/ConsoleDrivers/WindowsDriver.cs b/Terminal.Gui/ConsoleDrivers/WindowsDriver.cs index 27232279e..920307fee 100644 --- a/Terminal.Gui/ConsoleDrivers/WindowsDriver.cs +++ b/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 // SOFTWARE. // +using NStack; using System; -using System.CodeDom; -using System.Diagnostics; using System.Runtime.InteropServices; using System.Threading; using System.Threading.Tasks; -using NStack; namespace Terminal.Gui { diff --git a/Terminal.Gui/Core/MainLoop.cs b/Terminal.Gui/Core/MainLoop.cs index eaca5f9cb..b87354cc9 100644 --- a/Terminal.Gui/Core/MainLoop.cs +++ b/Terminal.Gui/Core/MainLoop.cs @@ -1,9 +1,13 @@ - +// +// MainLoop.cs: IMainLoopDriver and MainLoop for Terminal.Gui +// +// Authors: +// Miguel de Icaza (miguel@gnome.org) +// using System; using System.Collections.Generic; namespace Terminal.Gui { - /// /// Public interface to create your own platform specific main loop driver. ///