mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2025-12-26 15:57:56 +01:00
* key down/up support * line endings? * line endings * KeyDown/Up support * line endings * line endings * Revert "Drop NuGet restore" This reverts commit5c7a0d05f0. * Revert "Revert "Drop NuGet restore"" This reverts commit2dc5fce865. * updated demo * defined styles * Smarter StatusBar bottom tracking. * Prepping for https://github.com/migueldeicaza/gui.cs/issues/376 * Oops. * Fixed StatusBar 'snap to bottom' * line endings * Revert "Fixed StatusBar 'snap to bottom'" This reverts commit9a91c957e2. * started UICatalog project * Initial working POC. * Fix newlines * merge * textalignment demo tweaks * textalignment demo tweaks * Unicode Menu Scenario * not sure why this keeps changing * re-added project to .sln file * re-enabled status bar * moved scenarios to dir * building a dim and pos demo * terminal.sln * progress...barely * fixed exit * progress with some underlying fixes to Label * added readme * fixes build issue * launch * made default colors readable on Windows * major UI Catalog upgrade * added more demos and updated readme * refactored and added more tests * added ref to Issue #437 * added OnKeyUp support to Curses and Net drivers * more tweaks - grab PR #438 first * Added a OpenSelectedItem event to the ListView #429 * updates * moved KeyUpHandler out of special ESC stuff * more tweaks & improvements * testing top window bug * supported OpenSelectedItem * lots of updates * fixed regression, fixed #444 * better button scenario * tweaks * add Ready event to Toplevel * dotfx .gitignroe * ready for ready * updated colors based on feedback; consolodated config code * tweaked readme * readme * Added Editor demonstrating TextView * Added Editor demonstrating TextView * added hexeditor scenario Co-authored-by: Miguel de Icaza <miguel@gnome.org> Co-authored-by: BDisp <bd.bdisp@gmail.com>
509 lines
17 KiB
C#
509 lines
17 KiB
C#
//
|
|
// Driver.cs: Curses-based Driver
|
|
//
|
|
// Authors:
|
|
// Miguel de Icaza (miguel@gnome.org)
|
|
//
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Runtime.InteropServices;
|
|
using Mono.Terminal;
|
|
using NStack;
|
|
using Unix.Terminal;
|
|
|
|
namespace Terminal.Gui {
|
|
|
|
/// <summary>
|
|
/// This is the Curses driver for the gui.cs/Terminal framework.
|
|
/// </summary>
|
|
public class CursesDriver : ConsoleDriver {
|
|
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
|
|
public override int Cols => Curses.Cols;
|
|
public override int Rows => Curses.Lines;
|
|
|
|
// Current row, and current col, tracked by Move/AddRune only
|
|
int ccol, crow;
|
|
bool needMove;
|
|
public override void Move (int col, int row)
|
|
{
|
|
ccol = col;
|
|
crow = row;
|
|
|
|
if (Clip.Contains (col, row)) {
|
|
Curses.move (row, col);
|
|
needMove = false;
|
|
} else {
|
|
Curses.move (Clip.Y, Clip.X);
|
|
needMove = true;
|
|
}
|
|
}
|
|
|
|
static bool sync = false;
|
|
public override void AddRune (Rune rune)
|
|
{
|
|
if (Clip.Contains (ccol, crow)) {
|
|
if (needMove) {
|
|
Curses.move (crow, ccol);
|
|
needMove = false;
|
|
}
|
|
Curses.addch ((int)(uint)rune);
|
|
} else
|
|
needMove = true;
|
|
if (sync)
|
|
Application.Driver.Refresh ();
|
|
ccol++;
|
|
var runeWidth = Rune.ColumnWidth (rune);
|
|
if (runeWidth > 1) {
|
|
for (int i = 1; i < runeWidth; i++) {
|
|
ccol++;
|
|
}
|
|
}
|
|
}
|
|
|
|
public override void AddStr (ustring str)
|
|
{
|
|
// TODO; optimize this to determine if the str fits in the clip region, and if so, use Curses.addstr directly
|
|
foreach (var rune in str)
|
|
AddRune (rune);
|
|
}
|
|
|
|
public override void Refresh () {
|
|
Curses.refresh ();
|
|
if (Curses.CheckWinChange ()) {
|
|
TerminalResized?.Invoke ();
|
|
}
|
|
}
|
|
public override void UpdateCursor () => Refresh ();
|
|
public override void End () => Curses.endwin ();
|
|
public override void UpdateScreen () => window.redrawwin ();
|
|
public override void SetAttribute (Attribute c) => Curses.attrset (c.value);
|
|
public Curses.Window window;
|
|
|
|
static short last_color_pair = 16;
|
|
|
|
/// <summary>
|
|
/// Creates a curses color from the provided foreground and background colors
|
|
/// </summary>
|
|
/// <param name="foreground">Contains the curses attributes for the foreground (color, plus any attributes)</param>
|
|
/// <param name="background">Contains the curses attributes for the background (color, plus any attributes)</param>
|
|
/// <returns></returns>
|
|
public static Attribute MakeColor (short foreground, short background)
|
|
{
|
|
Curses.InitColorPair (++last_color_pair, foreground, background);
|
|
return new Attribute () { value = Curses.ColorPair (last_color_pair) };
|
|
}
|
|
|
|
int [,] colorPairs = new int [16, 16];
|
|
|
|
public override void SetColors (ConsoleColor foreground, ConsoleColor background)
|
|
{
|
|
int f = (short)foreground;
|
|
int b = (short)background;
|
|
var v = colorPairs [f, b];
|
|
if ((v & 0x10000) == 0) {
|
|
b = b & 0x7;
|
|
bool bold = (f & 0x8) != 0;
|
|
f = f & 0x7;
|
|
|
|
v = MakeColor ((short)f, (short)b) | (bold ? Curses.A_BOLD : 0);
|
|
colorPairs [(int)foreground, (int)background] = v | 0x1000;
|
|
}
|
|
SetAttribute (v & 0xffff);
|
|
}
|
|
|
|
Dictionary<int, int> rawPairs = new Dictionary<int, int> ();
|
|
public override void SetColors (short foreColorId, short backgroundColorId)
|
|
{
|
|
int key = (((ushort)foreColorId << 16)) | (ushort)backgroundColorId;
|
|
if (!rawPairs.TryGetValue (key, out var v)) {
|
|
v = MakeColor (foreColorId, backgroundColorId);
|
|
rawPairs [key] = v;
|
|
}
|
|
SetAttribute (v);
|
|
}
|
|
|
|
static Key MapCursesKey (int cursesKey)
|
|
{
|
|
switch (cursesKey) {
|
|
case Curses.KeyF1: return Key.F1;
|
|
case Curses.KeyF2: return Key.F2;
|
|
case Curses.KeyF3: return Key.F3;
|
|
case Curses.KeyF4: return Key.F4;
|
|
case Curses.KeyF5: return Key.F5;
|
|
case Curses.KeyF6: return Key.F6;
|
|
case Curses.KeyF7: return Key.F7;
|
|
case Curses.KeyF8: return Key.F8;
|
|
case Curses.KeyF9: return Key.F9;
|
|
case Curses.KeyF10: return Key.F10;
|
|
case Curses.KeyUp: return Key.CursorUp;
|
|
case Curses.KeyDown: return Key.CursorDown;
|
|
case Curses.KeyLeft: return Key.CursorLeft;
|
|
case Curses.KeyRight: return Key.CursorRight;
|
|
case Curses.KeyHome: return Key.Home;
|
|
case Curses.KeyEnd: return Key.End;
|
|
case Curses.KeyNPage: return Key.PageDown;
|
|
case Curses.KeyPPage: return Key.PageUp;
|
|
case Curses.KeyDeleteChar: return Key.DeleteChar;
|
|
case Curses.KeyInsertChar: return Key.InsertChar;
|
|
case Curses.KeyBackTab: return Key.BackTab;
|
|
case Curses.KeyBackspace: return Key.Backspace;
|
|
case Curses.ShiftKeyUp: return Key.CursorUp | Key.ShiftMask;
|
|
case Curses.ShiftKeyDown: return Key.CursorDown | Key.ShiftMask;
|
|
case Curses.ShiftKeyLeft: return Key.CursorLeft | Key.ShiftMask;
|
|
case Curses.ShiftKeyRight: return Key.CursorRight | Key.ShiftMask;
|
|
case Curses.ShiftKeyHome: return Key.Home | Key.ShiftMask;
|
|
case Curses.ShiftKeyEnd: return Key.End | Key.ShiftMask;
|
|
case Curses.ShiftKeyNPage: return Key.PageDown | Key.ShiftMask;
|
|
case Curses.ShiftKeyPPage: return Key.PageUp | Key.ShiftMask;
|
|
case Curses.AltKeyUp: return Key.CursorUp | Key.AltMask;
|
|
case Curses.AltKeyDown: return Key.CursorDown | Key.AltMask;
|
|
case Curses.AltKeyLeft: return Key.CursorLeft | Key.AltMask;
|
|
case Curses.AltKeyRight: return Key.CursorRight | Key.AltMask;
|
|
case Curses.AltKeyHome: return Key.Home | Key.AltMask;
|
|
case Curses.AltKeyEnd: return Key.End | Key.AltMask;
|
|
case Curses.AltKeyNPage: return Key.PageDown | Key.AltMask;
|
|
case Curses.AltKeyPPage: return Key.PageUp | Key.AltMask;
|
|
case Curses.CtrlKeyUp: return Key.CursorUp | Key.CtrlMask;
|
|
case Curses.CtrlKeyDown: return Key.CursorDown | Key.CtrlMask;
|
|
case Curses.CtrlKeyLeft: return Key.CursorLeft | Key.CtrlMask;
|
|
case Curses.CtrlKeyRight: return Key.CursorRight | Key.CtrlMask;
|
|
case Curses.CtrlKeyHome: return Key.Home | Key.CtrlMask;
|
|
case Curses.CtrlKeyEnd: return Key.End | Key.CtrlMask;
|
|
case Curses.CtrlKeyNPage: return Key.PageDown | Key.CtrlMask;
|
|
case Curses.CtrlKeyPPage: return Key.PageUp | Key.CtrlMask;
|
|
case Curses.ShiftCtrlKeyUp: return Key.CursorUp | Key.ShiftMask | Key.CtrlMask;
|
|
case Curses.ShiftCtrlKeyDown: return Key.CursorDown | Key.ShiftMask | Key.CtrlMask;
|
|
case Curses.ShiftCtrlKeyLeft: return Key.CursorLeft | Key.ShiftMask | Key.CtrlMask;
|
|
case Curses.ShiftCtrlKeyRight: return Key.CursorRight | Key.ShiftMask | Key.CtrlMask;
|
|
case Curses.ShiftCtrlKeyHome: return Key.Home | Key.ShiftMask | Key.CtrlMask;
|
|
case Curses.ShiftCtrlKeyEnd: return Key.End | Key.ShiftMask | Key.CtrlMask;
|
|
case Curses.ShiftCtrlKeyNPage: return Key.PageDown | Key.ShiftMask | Key.CtrlMask;
|
|
case Curses.ShiftCtrlKeyPPage: return Key.PageUp | Key.ShiftMask | Key.CtrlMask;
|
|
default: return Key.Unknown;
|
|
}
|
|
}
|
|
|
|
static MouseEvent ToDriverMouse (Curses.MouseEvent cev)
|
|
{
|
|
return new MouseEvent () {
|
|
X = cev.X,
|
|
Y = cev.Y,
|
|
Flags = (MouseFlags)cev.ButtonState
|
|
};
|
|
}
|
|
|
|
void ProcessInput (Action<KeyEvent> keyHandler, Action<KeyEvent> keyUpHandler, Action<MouseEvent> mouseHandler)
|
|
{
|
|
int wch;
|
|
var code = Curses.get_wch (out wch);
|
|
if (code == Curses.ERR)
|
|
return;
|
|
if (code == Curses.KEY_CODE_YES) {
|
|
if (wch == Curses.KeyResize) {
|
|
if (Curses.CheckWinChange ()) {
|
|
TerminalResized?.Invoke ();
|
|
return;
|
|
}
|
|
}
|
|
if (wch == Curses.KeyMouse) {
|
|
Curses.MouseEvent ev;
|
|
Curses.getmouse (out ev);
|
|
mouseHandler (ToDriverMouse (ev));
|
|
return;
|
|
}
|
|
keyHandler (new KeyEvent (MapCursesKey (wch)));
|
|
keyUpHandler (new KeyEvent (MapCursesKey (wch)));
|
|
return;
|
|
}
|
|
|
|
// Special handling for ESC, we want to try to catch ESC+letter to simulate alt-letter as well as Alt-Fkey
|
|
if (wch == 27) {
|
|
Curses.timeout (200);
|
|
|
|
code = Curses.get_wch (out int wch2);
|
|
if (code == Curses.KEY_CODE_YES)
|
|
keyHandler (new KeyEvent (Key.AltMask | MapCursesKey (wch)));
|
|
if (code == 0) {
|
|
KeyEvent key;
|
|
|
|
// The ESC-number handling, debatable.
|
|
// Simulates the AltMask itself by pressing Alt + Space.
|
|
if (wch2 == (int)Key.Space)
|
|
key = new KeyEvent (Key.AltMask);
|
|
else if (wch2 - (int)Key.Space >= 'A' && wch2 - (int)Key.Space <= 'Z')
|
|
key = new KeyEvent ((Key)((uint)Key.AltMask + (wch2 - (int)Key.Space)));
|
|
else if (wch2 >= '1' && wch <= '9')
|
|
key = new KeyEvent ((Key)((int)Key.F1 + (wch2 - '0' - 1)));
|
|
else if (wch2 == '0')
|
|
key = new KeyEvent (Key.F10);
|
|
else if (wch2 == 27)
|
|
key = new KeyEvent ((Key)wch2);
|
|
else
|
|
key = new KeyEvent (Key.AltMask | (Key)wch2);
|
|
keyHandler (key);
|
|
} else {
|
|
keyHandler (new KeyEvent (Key.Esc));
|
|
}
|
|
} else {
|
|
keyHandler (new KeyEvent ((Key)wch));
|
|
}
|
|
// Cause OnKeyUp and OnKeyPressed. Note that the special handling for ESC above
|
|
// will not impact KeyUp.
|
|
keyUpHandler (new KeyEvent ((Key)wch));
|
|
}
|
|
|
|
public override void PrepareToRun (MainLoop mainLoop, Action<KeyEvent> keyHandler, Action<KeyEvent> keyDownHandler, Action<KeyEvent> keyUpHandler, Action<MouseEvent> mouseHandler)
|
|
{
|
|
// Note: Curses doesn't support keydown/up events and thus any passed keyDown/UpHandlers will never be called
|
|
Curses.timeout (-1);
|
|
|
|
(mainLoop.Driver as Mono.Terminal.UnixMainLoop).AddWatch (0, Mono.Terminal.UnixMainLoop.Condition.PollIn, x => {
|
|
ProcessInput (keyHandler, keyUpHandler, mouseHandler);
|
|
return true;
|
|
});
|
|
|
|
}
|
|
|
|
Curses.Event oldMouseEvents, reportableMouseEvents;
|
|
public override void Init (Action terminalResized)
|
|
{
|
|
if (window != null)
|
|
return;
|
|
|
|
try {
|
|
window = Curses.initscr ();
|
|
} catch (Exception e) {
|
|
Console.WriteLine ("Curses failed to initialize, the exception is: " + e);
|
|
}
|
|
Curses.raw ();
|
|
Curses.noecho ();
|
|
|
|
Curses.Window.Standard.keypad (true);
|
|
reportableMouseEvents = Curses.mousemask (Curses.Event.AllEvents | Curses.Event.ReportMousePosition, out oldMouseEvents);
|
|
TerminalResized = terminalResized;
|
|
if (reportableMouseEvents.HasFlag (Curses.Event.ReportMousePosition))
|
|
StartReportingMouseMoves ();
|
|
|
|
HLine = Curses.ACS_HLINE;
|
|
VLine = Curses.ACS_VLINE;
|
|
Stipple = Curses.ACS_CKBOARD;
|
|
Diamond = Curses.ACS_DIAMOND;
|
|
ULCorner = Curses.ACS_ULCORNER;
|
|
LLCorner = Curses.ACS_LLCORNER;
|
|
URCorner = Curses.ACS_URCORNER;
|
|
LRCorner = Curses.ACS_LRCORNER;
|
|
LeftTee = Curses.ACS_LTEE;
|
|
RightTee = Curses.ACS_RTEE;
|
|
TopTee = Curses.ACS_TTEE;
|
|
BottomTee = Curses.ACS_BTEE;
|
|
|
|
Colors.Base = new ColorScheme ();
|
|
Colors.Dialog = new ColorScheme ();
|
|
Colors.Menu = new ColorScheme ();
|
|
Colors.Error = new ColorScheme ();
|
|
Clip = new Rect (0, 0, Cols, Rows);
|
|
if (Curses.HasColors) {
|
|
Curses.StartColor ();
|
|
Curses.UseDefaultColors ();
|
|
|
|
Colors.Base.Normal = MakeColor (Curses.COLOR_WHITE, Curses.COLOR_BLUE);
|
|
Colors.Base.Focus = MakeColor (Curses.COLOR_BLACK, Curses.COLOR_CYAN);
|
|
Colors.Base.HotNormal = Curses.A_BOLD | MakeColor (Curses.COLOR_YELLOW, Curses.COLOR_BLUE);
|
|
Colors.Base.HotFocus = Curses.A_BOLD | MakeColor (Curses.COLOR_YELLOW, Curses.COLOR_CYAN);
|
|
|
|
// Focused,
|
|
// Selected, Hot: Yellow on Black
|
|
// Selected, text: white on black
|
|
// Unselected, hot: yellow on cyan
|
|
// unselected, text: same as unfocused
|
|
Colors.Menu.HotFocus = Curses.A_BOLD | MakeColor (Curses.COLOR_YELLOW, Curses.COLOR_BLACK);
|
|
Colors.Menu.Focus = Curses.A_BOLD | MakeColor (Curses.COLOR_WHITE, Curses.COLOR_BLACK);
|
|
Colors.Menu.HotNormal = Curses.A_BOLD | MakeColor (Curses.COLOR_YELLOW, Curses.COLOR_CYAN);
|
|
Colors.Menu.Normal = Curses.A_BOLD | MakeColor (Curses.COLOR_WHITE, Curses.COLOR_CYAN);
|
|
Colors.Menu.Disabled = MakeColor (Curses.COLOR_WHITE, Curses.COLOR_CYAN);
|
|
|
|
Colors.Dialog.Normal = MakeColor (Curses.COLOR_BLACK, Curses.COLOR_WHITE);
|
|
Colors.Dialog.Focus = MakeColor (Curses.COLOR_BLACK, Curses.COLOR_CYAN);
|
|
Colors.Dialog.HotNormal = MakeColor (Curses.COLOR_BLUE, Curses.COLOR_WHITE);
|
|
Colors.Dialog.HotFocus = MakeColor (Curses.COLOR_BLUE, Curses.COLOR_CYAN);
|
|
|
|
Colors.Error.Normal = Curses.A_BOLD | MakeColor (Curses.COLOR_WHITE, Curses.COLOR_RED);
|
|
Colors.Error.Focus = MakeColor (Curses.COLOR_BLACK, Curses.COLOR_WHITE);
|
|
Colors.Error.HotNormal = Curses.A_BOLD | MakeColor (Curses.COLOR_YELLOW, Curses.COLOR_RED);
|
|
Colors.Error.HotFocus = Colors.Error.HotNormal;
|
|
} else {
|
|
Colors.Base.Normal = Curses.A_NORMAL;
|
|
Colors.Base.Focus = Curses.A_REVERSE;
|
|
Colors.Base.HotNormal = Curses.A_BOLD;
|
|
Colors.Base.HotFocus = Curses.A_BOLD | Curses.A_REVERSE;
|
|
Colors.Menu.Normal = Curses.A_REVERSE;
|
|
Colors.Menu.Focus = Curses.A_NORMAL;
|
|
Colors.Menu.HotNormal = Curses.A_BOLD;
|
|
Colors.Menu.HotFocus = Curses.A_NORMAL;
|
|
Colors.Dialog.Normal = Curses.A_REVERSE;
|
|
Colors.Dialog.Focus = Curses.A_NORMAL;
|
|
Colors.Dialog.HotNormal = Curses.A_BOLD;
|
|
Colors.Dialog.HotFocus = Curses.A_NORMAL;
|
|
Colors.Error.Normal = Curses.A_BOLD;
|
|
Colors.Error.Focus = Curses.A_BOLD | Curses.A_REVERSE;
|
|
Colors.Error.HotNormal = Curses.A_BOLD | Curses.A_REVERSE;
|
|
Colors.Error.HotFocus = Curses.A_REVERSE;
|
|
}
|
|
Colors.TopLevel = new ColorScheme ();
|
|
|
|
Colors.TopLevel.Normal = MakeColor (Curses.COLOR_GREEN, Curses.COLOR_BLACK);
|
|
Colors.TopLevel.Focus = MakeColor (Curses.COLOR_WHITE, Curses.COLOR_CYAN);
|
|
Colors.TopLevel.HotNormal = MakeColor (Curses.COLOR_YELLOW, Curses.COLOR_BLACK);
|
|
Colors.TopLevel.HotFocus = MakeColor (Curses.COLOR_YELLOW, Curses.COLOR_CYAN);
|
|
}
|
|
|
|
static int MapColor (Color color)
|
|
{
|
|
switch (color) {
|
|
case Color.Black:
|
|
return Curses.COLOR_BLACK;
|
|
case Color.Blue:
|
|
return Curses.COLOR_BLUE;
|
|
case Color.Green:
|
|
return Curses.COLOR_GREEN;
|
|
case Color.Cyan:
|
|
return Curses.COLOR_CYAN;
|
|
case Color.Red:
|
|
return Curses.COLOR_RED;
|
|
case Color.Magenta:
|
|
return Curses.COLOR_MAGENTA;
|
|
case Color.Brown:
|
|
return Curses.COLOR_YELLOW;
|
|
case Color.Gray:
|
|
return Curses.COLOR_WHITE;
|
|
case Color.DarkGray:
|
|
return Curses.COLOR_BLACK | Curses.A_BOLD;
|
|
case Color.BrightBlue:
|
|
return Curses.COLOR_BLUE | Curses.A_BOLD;
|
|
case Color.BrightGreen:
|
|
return Curses.COLOR_GREEN | Curses.A_BOLD;
|
|
case Color.BrighCyan:
|
|
return Curses.COLOR_CYAN | Curses.A_BOLD;
|
|
case Color.BrightRed:
|
|
return Curses.COLOR_RED | Curses.A_BOLD;
|
|
case Color.BrightMagenta:
|
|
return Curses.COLOR_MAGENTA | Curses.A_BOLD;
|
|
case Color.BrightYellow:
|
|
return Curses.COLOR_YELLOW | Curses.A_BOLD;
|
|
case Color.White:
|
|
return Curses.COLOR_WHITE | Curses.A_BOLD;
|
|
}
|
|
throw new ArgumentException ("Invalid color code");
|
|
}
|
|
|
|
public override Attribute MakeAttribute (Color fore, Color back)
|
|
{
|
|
var f = MapColor (fore);
|
|
return MakeColor ((short)(f & 0xffff), (short)MapColor (back)) | ((f & Curses.A_BOLD) != 0 ? Curses.A_BOLD : 0);
|
|
}
|
|
|
|
public override void Suspend ()
|
|
{
|
|
if (reportableMouseEvents.HasFlag (Curses.Event.ReportMousePosition))
|
|
StopReportingMouseMoves ();
|
|
Platform.Suspend ();
|
|
Curses.Window.Standard.redrawwin ();
|
|
Curses.refresh ();
|
|
if (reportableMouseEvents.HasFlag (Curses.Event.ReportMousePosition))
|
|
StartReportingMouseMoves ();
|
|
}
|
|
|
|
public override void StartReportingMouseMoves ()
|
|
{
|
|
Console.Out.Write ("\x1b[?1003h");
|
|
Console.Out.Flush ();
|
|
}
|
|
|
|
public override void StopReportingMouseMoves ()
|
|
{
|
|
Console.Out.Write ("\x1b[?1003l");
|
|
Console.Out.Flush ();
|
|
}
|
|
|
|
int lastMouseInterval;
|
|
bool mouseGrabbed;
|
|
|
|
public override void UncookMouse ()
|
|
{
|
|
if (mouseGrabbed)
|
|
return;
|
|
lastMouseInterval = Curses.mouseinterval (0);
|
|
mouseGrabbed = true;
|
|
}
|
|
|
|
public override void CookMouse ()
|
|
{
|
|
mouseGrabbed = false;
|
|
Curses.mouseinterval (lastMouseInterval);
|
|
}
|
|
}
|
|
|
|
internal static class Platform {
|
|
[DllImport ("libc")]
|
|
static extern int uname (IntPtr buf);
|
|
|
|
[DllImport ("libc")]
|
|
static extern int killpg (int pgrp, int pid);
|
|
|
|
static int suspendSignal;
|
|
|
|
static int GetSuspendSignal ()
|
|
{
|
|
if (suspendSignal != 0)
|
|
return suspendSignal;
|
|
|
|
IntPtr buf = Marshal.AllocHGlobal (8192);
|
|
if (uname (buf) != 0) {
|
|
Marshal.FreeHGlobal (buf);
|
|
suspendSignal = -1;
|
|
return suspendSignal;
|
|
}
|
|
try {
|
|
switch (Marshal.PtrToStringAnsi (buf)) {
|
|
case "Darwin":
|
|
case "DragonFly":
|
|
case "FreeBSD":
|
|
case "NetBSD":
|
|
case "OpenBSD":
|
|
suspendSignal = 18;
|
|
break;
|
|
case "Linux":
|
|
// TODO: should fetch the machine name and
|
|
// if it is MIPS return 24
|
|
suspendSignal = 20;
|
|
break;
|
|
case "Solaris":
|
|
suspendSignal = 24;
|
|
break;
|
|
default:
|
|
suspendSignal = -1;
|
|
break;
|
|
}
|
|
return suspendSignal;
|
|
} finally {
|
|
Marshal.FreeHGlobal (buf);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Suspends the process by sending SIGTSTP to itself
|
|
/// </summary>
|
|
/// <returns>The suspend.</returns>
|
|
static public bool Suspend ()
|
|
{
|
|
int signal = GetSuspendSignal ();
|
|
if (signal == -1)
|
|
return false;
|
|
killpg (0, signal);
|
|
return true;
|
|
}
|
|
#pragma warning restore CS1591 // Missing XML comment for publicly visible type or member
|
|
}
|
|
|
|
}
|