console mode - Ctrl+C handler - #480

This commit is contained in:
Vadim Lopatin 2017-10-12 15:54:43 +03:00
parent cc85663ac3
commit e928aae901
2 changed files with 32 additions and 1 deletions

View File

@ -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();

View File

@ -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) {