use of com.laytonsmith.PureUtilities.SignalHandler in project CommandHelper by EngineHub.
the class Interpreter method doStartup.
private void doStartup() throws IOException, DataSourceException, URISyntaxException, Profiles.InvalidProfileException {
Installer.Install(MethodScriptFileLocations.getDefault().getConfigDirectory());
Installer.InstallCmdlineInterpreter();
env = Static.GenerateStandaloneEnvironment(false);
env.getEnv(GlobalEnv.class).SetCustom("cmdline", true);
if (Prefs.UseColors()) {
TermColors.EnableColors();
} else {
TermColors.DisableColors();
}
String auto_include = FileUtil.read(MethodScriptFileLocations.getDefault().getCmdlineInterpreterAutoIncludeFile());
try {
MethodScriptCompiler.execute(auto_include, MethodScriptFileLocations.getDefault().getCmdlineInterpreterAutoIncludeFile(), true, env, null, null, null);
} catch (ConfigCompileException ex) {
ConfigRuntimeException.HandleUncaughtException(ex, "Interpreter will continue to run, however.", null);
} catch (ConfigCompileGroupException ex) {
ConfigRuntimeException.HandleUncaughtException(ex, null);
}
// Install our signal handlers.
SignalHandler.SignalCallback signalHandler = new SignalHandler.SignalCallback() {
@Override
public boolean handle(SignalType type) {
if (isExecuting) {
env.getEnv(GlobalEnv.class).SetInterrupt(true);
if (scriptThread != null) {
scriptThread.interrupt();
}
for (Thread t : env.getEnv(GlobalEnv.class).GetDaemonManager().getActiveThreads()) {
t.interrupt();
}
} else {
ctrlCcount++;
if (ctrlCcount > MAX_CTRL_C_MASHES) {
// Ok, ok, we get the hint.
StreamUtils.GetSystemOut().println();
StreamUtils.GetSystemOut().flush();
// Standard Ctrl+C exit code
System.exit(130);
}
pl(YELLOW + "\nUse exit() to exit the shell." + reset());
p(getPrompt());
}
return true;
}
};
try {
SignalHandler.addHandler(Signals.SIGTERM, signalHandler);
} catch (IllegalArgumentException ex) {
// Oh well.
}
try {
SignalHandler.addHandler(Signals.SIGINT, signalHandler);
} catch (IllegalArgumentException ex) {
// Oh well again.
}
}
Aggregations