mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2025-12-26 15:57:56 +01:00
Moved NetDriver's IMainLoopDriver impl to NetDriver.cs
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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.
|
||||
@@ -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 {
|
||||
/// <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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
|
||||
@@ -7,10 +7,78 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using NStack;
|
||||
|
||||
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 {
|
||||
int cols, rows;
|
||||
public override int Cols => cols;
|
||||
|
||||
@@ -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 {
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
/// <summary>
|
||||
/// Public interface to create your own platform specific main loop driver.
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user