Search in sources :

Example 1 with IOConsolePromptShell

use of org.jcryptool.commands.ui.eclipseconsole.console.IOConsolePromptShell 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();
}
Also used : CommandEvaluator(org.jcryptool.commands.core.evaluator.CommandEvaluator) IOConsoleOutputStream(org.eclipse.ui.console.IOConsoleOutputStream) IOConsolePromptShell(org.jcryptool.commands.ui.eclipseconsole.console.IOConsolePromptShell) Color(org.eclipse.swt.graphics.Color) Observer(java.util.Observer) IOException(java.io.IOException) ParseException(org.apache.commons.cli.ParseException) IOConsole(org.eclipse.ui.console.IOConsole) Observable(java.util.Observable)

Aggregations

IOException (java.io.IOException)1 Observable (java.util.Observable)1 Observer (java.util.Observer)1 ParseException (org.apache.commons.cli.ParseException)1 Color (org.eclipse.swt.graphics.Color)1 IOConsole (org.eclipse.ui.console.IOConsole)1 IOConsoleOutputStream (org.eclipse.ui.console.IOConsoleOutputStream)1 CommandEvaluator (org.jcryptool.commands.core.evaluator.CommandEvaluator)1 IOConsolePromptShell (org.jcryptool.commands.ui.eclipseconsole.console.IOConsolePromptShell)1