mirror of https://github.com/buggins/dlangui.git
console mode - Ctrl+C handler - #480
This commit is contained in:
parent
cc85663ac3
commit
e928aae901
|
@ -98,6 +98,9 @@ class ConsolePlatform : Platform {
|
||||||
_drawBuf = new ConsoleDrawBuf(_console);
|
_drawBuf = new ConsoleDrawBuf(_console);
|
||||||
}
|
}
|
||||||
~this() {
|
~this() {
|
||||||
|
//Log.d("Destroying console");
|
||||||
|
//destroy(_console);
|
||||||
|
Log.d("Destroying drawbuf");
|
||||||
destroy(_drawBuf);
|
destroy(_drawBuf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -240,6 +243,9 @@ class ConsolePlatform : Platform {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Log.i("Message loop finished - closing windows");
|
||||||
|
_windowsToClose ~= _windowList;
|
||||||
|
checkClosedWindows();
|
||||||
Log.i("Exiting from message loop");
|
Log.i("Exiting from message loop");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -263,6 +269,13 @@ class ConsolePlatform : Platform {
|
||||||
override void requestLayout() {
|
override void requestLayout() {
|
||||||
// TODO
|
// 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
|
/// 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):
|
//version (none):
|
||||||
// entry point for console app
|
// entry point for console app
|
||||||
extern(C) int DLANGUImain(string[] args) {
|
extern(C) int DLANGUImain(string[] args) {
|
||||||
|
@ -471,6 +493,10 @@ extern(C) int DLANGUImain(string[] args) {
|
||||||
version (Windows) {
|
version (Windows) {
|
||||||
import core.sys.windows.winuser;
|
import core.sys.windows.winuser;
|
||||||
DOUBLE_CLICK_THRESHOLD_MS = GetDoubleClickTime();
|
DOUBLE_CLICK_THRESHOLD_MS = GetDoubleClickTime();
|
||||||
|
} else {
|
||||||
|
// set Ctrl+C handler
|
||||||
|
import core.sys.posix.signal;
|
||||||
|
sigset(SIGINT, &mySignalHandler);
|
||||||
}
|
}
|
||||||
|
|
||||||
currentTheme = createDefaultTheme();
|
currentTheme = createDefaultTheme();
|
||||||
|
|
|
@ -292,7 +292,7 @@ class Console {
|
||||||
if (res < 0) {
|
if (res < 0) {
|
||||||
auto err = errno;
|
auto err = errno;
|
||||||
while (err == EAGAIN) {
|
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);
|
res = cast(int)write(STDOUT_FILENO, s.ptr, s.length);
|
||||||
if (res >= 0)
|
if (res >= 0)
|
||||||
return (res > 0);
|
return (res > 0);
|
||||||
|
@ -835,6 +835,11 @@ class Console {
|
||||||
protected ButtonDetails _mbutton;
|
protected ButtonDetails _mbutton;
|
||||||
protected ButtonDetails _rbutton;
|
protected ButtonDetails _rbutton;
|
||||||
|
|
||||||
|
void stop() {
|
||||||
|
// set stopped flag
|
||||||
|
_stopped = true;
|
||||||
|
}
|
||||||
|
|
||||||
/// wait for input, handle input
|
/// wait for input, handle input
|
||||||
bool pollInput() {
|
bool pollInput() {
|
||||||
if (_stopped) {
|
if (_stopped) {
|
||||||
|
|
Loading…
Reference in New Issue