java,来自插件控制台的readline

时间:2017-02-01 12:26:56

标签: java plugins eclipse-plugin

要在我开发的插件的控制台中写入,我使用之前找到的这种方法。 我的工作

private static MessageConsole findConsole(String name) {

    if (ConsolePlugin.getDefault() == null)
        return null;
    ConsolePlugin plugin = ConsolePlugin.getDefault();
    IConsoleManager conMan = plugin.getConsoleManager();
    IConsole[] existing = conMan.getConsoles();
    for (int i = 0; i < existing.length; i++)
        if (name.equals(existing[i].getName())) {
            conMan.showConsoleView(existing[i]);
            return (MessageConsole) existing[i];
        }
    // no console found, so create a new one
    MessageConsole myConsole = new MessageConsole(name, null);
    conMan.addConsoles(new IConsole[] { myConsole });
    return myConsole;
}

public static MessageConsoleStream getMessageStream() {
    MessageConsole myConsole = findConsole("console");
    if (myConsole != null) {
        IWorkbench wb = PlatformUI.getWorkbench();
        String id = IConsoleConstants.ID_CONSOLE_VIEW;
        return myConsole.newMessageStream();
    }
    return null;
}

我这样使用:

MessageConsoleStream out = Application.getMessageStream();
out.print("AB");

现在我想从控制台读取。 我该怎么做?

1 个答案:

答案 0 :(得分:0)

尝试从getInputStream()返回的MessageConsole实例上调用findConsole并从那里开始。 Read more about the input stream that's returned here.