use of org.jcryptool.commands.core.evaluator.CommandEvaluator in project core by jcryptool.
the class CommandsUiStartup method earlyStartup.
public void earlyStartup() {
final IOConsole ioConsole = new IOConsole(Messages.CommandsUiStartup_consolename, null);
ioConsole.setConsoleWidth(0);
ConsolePlugin.getDefault().getConsoleManager().addConsoles(new IConsole[] { ioConsole });
CommandsUIPlugin.getDefault().setIoConsole(ioConsole);
final CommandEvaluator evaluator = new CommandEvaluator();
final IOConsolePromptShell monitor = new IOConsolePromptShell(ioConsole) {
@Override
protected void sendPrompt(final IOConsoleOutputStream o) throws IOException {
Display.getDefault().syncExec(new Runnable() {
public void run() {
Color prevColor = o.getColor();
int prevStyle = o.getFontStyle();
o.setColor(Display.getDefault().getSystemColor(SWT.COLOR_RED));
try {
o.write(PROMPT);
} catch (IOException e) {
LogUtil.logError(CommandsUIPlugin.PLUGIN_ID, e);
}
o.setColor(prevColor);
o.setFontStyle(prevStyle);
}
});
}
@Override
protected void initializeConsole(IOConsoleOutputStream o) {
super.initializeConsole(o);
try {
o.write(Messages.CommandsUiStartup_welcome + Messages.CommandsUiStartup_welcome_tip);
} catch (IOException e) {
LogUtil.logError(CommandsUIPlugin.PLUGIN_ID, e);
}
}
};
Observer monitorObserver = new Observer() {
public void update(Observable o, Object arg) {
String line = monitor.getLine();
String result = Messages.CommandsUiStartup_eval_error;
try {
result = evaluator.evaluate(line).getResult();
} catch (ParseException e) {
LogUtil.logError(CommandsUIPlugin.PLUGIN_ID, e);
}
IOConsoleOutputStream outStream = ioConsole.newOutputStream();
try {
// $NON-NLS-1$
outStream.write(result + "\n\n");
} catch (IOException e) {
LogUtil.logError(CommandsUIPlugin.PLUGIN_ID, e);
}
try {
outStream.close();
} catch (IOException e) {
LogUtil.logError(CommandsUIPlugin.PLUGIN_ID, e);
}
}
};
monitor.addObserver(monitorObserver);
monitor.startMonitoring();
}
Aggregations