Class InteractiveConsole

    • Field Detail

      • CONSOLE_FILENAME

        public static java.lang.String CONSOLE_FILENAME
        Note: This field is actually final; don't modify.

        To work around an issue in javadoc with Java 8 we cannot have it final for now, see issue 2539 for details.

      • filename

        public java.lang.String filename
    • Constructor Detail

      • InteractiveConsole

        public InteractiveConsole()
        Construct an interactive console, which will "run" when interact() is called. The name of the console (e.g. in error messages) will be .
      • InteractiveConsole

        public InteractiveConsole​(PyObject locals)
        Construct an interactive console, which will "run" when interact() is called. The name of the console (e.g. in error messages) will be .
        Parameters:
        locals - dictionary to use, or if null, a new empty one will be created
      • InteractiveConsole

        public InteractiveConsole​(PyObject locals,
                                  java.lang.String filename)
        Construct an interactive console, which will "run" when interact() is called.
        Parameters:
        locals - dictionary to use, or if null, a new empty one will be created
        filename - name with which to label this console input (e.g. in error messages).
      • InteractiveConsole

        public InteractiveConsole​(PyObject locals,
                                  java.lang.String filename,
                                  boolean replaceRawInput)
        Full-feature constructor for an interactive console, which will "run" when interact() is called. This version allows the caller to replace the built-in raw_input() methods with raw_input(PyObject) and raw_input(PyObject, PyObject), which may be overridden in a sub-class.
        Parameters:
        locals - dictionary to use, or if null, a new empty one will be created
        filename - name with which to label this console input
        replaceRawInput - if true, hook this class's raw_input into the built-ins.
    • Method Detail

      • getDefaultBanner

        public static java.lang.String getDefaultBanner()
        Returns the banner to print before the first interaction: "Jython on ".
        Returns:
        the banner.
      • interact

        public void interact​(java.lang.String banner,
                             PyObject file)
        Operate a Python console by repeatedly calling raw_input(PyObject, PyObject) and interpreting the lines read. An end of file causes the method to return.
        Parameters:
        banner - to print before accepting input, or if null, no banner.
        file - from which to read commands, or if null, read the console.
      • _interact

        public void _interact​(java.lang.String banner,
                              PyObject file)
      • push

        public boolean push​(java.lang.String line)
        Push a line to the interpreter. The line should not have a trailing newline; it may have internal newlines. The line is appended to a buffer and the interpreter's runsource() method is called with the concatenated contents of the buffer as source. If this indicates that the command was executed or invalid, the buffer is reset; otherwise, the command is incomplete, and the buffer is left as it was after the line was appended. The return value is 1 if more input is required, 0 if the line was dealt with in some way (this is the same as runsource()).
      • raw_input

        public java.lang.String raw_input​(PyObject prompt)
        Write a prompt and read a line from standard input. The returned line does not include the trailing newline. When the user enters the EOF key sequence, EOFError is raised. The base implementation uses the built-in function raw_input(); a subclass may replace this with a different implementation.
      • raw_input

        public java.lang.String raw_input​(PyObject prompt,
                                          PyObject file)
        Write a prompt and read a line from a file.