diff --git a/src/dlangui/platforms/console/consoleapp.d b/src/dlangui/platforms/console/consoleapp.d index 16a98bfc..020668c8 100644 --- a/src/dlangui/platforms/console/consoleapp.d +++ b/src/dlangui/platforms/console/consoleapp.d @@ -98,6 +98,9 @@ class ConsolePlatform : Platform { _drawBuf = new ConsoleDrawBuf(_console); } ~this() { + //Log.d("Destroying console"); + //destroy(_console); + Log.d("Destroying drawbuf"); destroy(_drawBuf); } @@ -240,6 +243,9 @@ class ConsolePlatform : Platform { break; } } + Log.i("Message loop finished - closing windows"); + _windowsToClose ~= _windowList; + checkClosedWindows(); Log.i("Exiting from message loop"); return 0; } @@ -263,6 +269,13 @@ class ConsolePlatform : Platform { override void requestLayout() { // TODO } + + private void onCtrlC() { + Log.w("Ctrl+C pressed - stopping application"); + if (_console) { + _console.stop(); + } + } } /// drawing buffer - image container which allows to perform some drawing operations @@ -459,6 +472,15 @@ class ConsoleDrawBuf : DrawBuf { } } + +extern(C) void mySignalHandler(int value) { + Log.i("Signal handler - signal=", value); + ConsolePlatform platform = cast(ConsolePlatform)Platform.instance; + if (platform) { + platform.onCtrlC(); + } +} + //version (none): // entry point for console app extern(C) int DLANGUImain(string[] args) { @@ -471,6 +493,10 @@ extern(C) int DLANGUImain(string[] args) { version (Windows) { import core.sys.windows.winuser; DOUBLE_CLICK_THRESHOLD_MS = GetDoubleClickTime(); + } else { + // set Ctrl+C handler + import core.sys.posix.signal; + sigset(SIGINT, &mySignalHandler); } currentTheme = createDefaultTheme(); diff --git a/src/dlangui/platforms/console/dconsole.d b/src/dlangui/platforms/console/dconsole.d index 309f31e4..6e9a9e50 100644 --- a/src/dlangui/platforms/console/dconsole.d +++ b/src/dlangui/platforms/console/dconsole.d @@ -292,7 +292,7 @@ class Console { if (res < 0) { auto err = errno; while (err == EAGAIN) { - debug Log.d("rawWrite error EAGAIN - will retry"); + //debug Log.d("rawWrite error EAGAIN - will retry"); res = cast(int)write(STDOUT_FILENO, s.ptr, s.length); if (res >= 0) return (res > 0); @@ -835,6 +835,11 @@ class Console { protected ButtonDetails _mbutton; protected ButtonDetails _rbutton; + void stop() { + // set stopped flag + _stopped = true; + } + /// wait for input, handle input bool pollInput() { if (_stopped) {