Search in sources :

Example 1 with InterpreterResponse

use of com.jetbrains.python.console.pydev.InterpreterResponse in project intellij-community by JetBrains.

the class PythonDebugConsoleCommunication method execInterpreter.

public void execInterpreter(ConsoleCodeFragment code, final Function<InterpreterResponse, Object> callback) {
    if (waitingForInput) {
        final OutputStream processInput = myDebugProcess.getProcessHandler().getProcessInput();
        if (processInput != null) {
            try {
                final Charset defaultCharset = EncodingProjectManager.getInstance(myDebugProcess.getProject()).getDefaultCharset();
                processInput.write((code.getText()).getBytes(defaultCharset));
                processInput.flush();
            } catch (IOException e) {
                LOG.error(e.getMessage());
            }
        }
        myNeedsMore = false;
        waitingForInput = false;
        notifyCommandExecuted(waitingForInput);
    } else {
        exec(new ConsoleCodeFragment(code.getText(), false), new PyDebugCallback<Pair<String, Boolean>>() {

            @Override
            public void ok(Pair<String, Boolean> executed) {
                boolean more = executed.second;
                myNeedsMore = more;
                notifyCommandExecuted(more);
                callback.fun(new InterpreterResponse(more, isWaitingForInput()));
            }

            @Override
            public void error(PyDebuggerException exception) {
                myNeedsMore = false;
                notifyCommandExecuted(false);
                callback.fun(new InterpreterResponse(false, isWaitingForInput()));
            }
        });
    }
}
Also used : OutputStream(java.io.OutputStream) InterpreterResponse(com.jetbrains.python.console.pydev.InterpreterResponse) Charset(java.nio.charset.Charset) IOException(java.io.IOException) PyDebuggerException(com.jetbrains.python.debugger.PyDebuggerException) Pair(com.intellij.openapi.util.Pair)

Aggregations

Pair (com.intellij.openapi.util.Pair)1 InterpreterResponse (com.jetbrains.python.console.pydev.InterpreterResponse)1 PyDebuggerException (com.jetbrains.python.debugger.PyDebuggerException)1 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 Charset (java.nio.charset.Charset)1