Overview | Package | Class
| FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## groovy.ui
Class InteractiveShell

A simple interactive shell for evaluating groovy expressions on the command line (aka. groovysh).

author:
  James Strachan

author:
  Chris Poirier

author:
  Yuri Schimke

author:
  Brian McCallistair

author:
  Guillaume Laforge

author:
  Dierk Koenig, include the inspect command, June 2005

author:
  Jason Dillon

version:
  $Revision: 7922 $

Field Summary
`def` | `COMMANDS`
`Map` | `COMMAND_HELP`
`int` | `COMMAND_ID_BINDING`
`int` | `COMMAND_ID_DISCARD`
`int` | `COMMAND_ID_DISCARD_LOADED_CLASSES`
`int` | `COMMAND_ID_DISPLAY`
`int` | `COMMAND_ID_EXECUTE`
`int` | `COMMAND_ID_EXIT`
`int` | `COMMAND_ID_EXPLAIN`
`int` | `COMMAND_ID_HELP`
`int` | `COMMAND_ID_INSPECT`
`Map` | `COMMAND_MAPPINGS`
`int` | `LAST_COMMAND_ID`
`MessageSource` | `MESSAGES`
`String` | `NEW_LINE`
`StringBuffer` | `accepted`
`Closure` | `afterExecution`
`Closure` | `beforeExecution`
`PrintStream` | `err`
`Exception` | `error`
`InputStream` | `in`
`Object` | `lastResult`
`int` | `line`
`PrintStream` | `out`
`SourceUnit` | `parser`
`String` | `pending`
`ConsoleReader` | `reader`
`GroovyShell` | `shell`
`boolean` | `stale`

Constructor Summary
`InteractiveShell()` Default constructor, initializes uses new binding and system streams.
`InteractiveShell(InputStream in, PrintStream out, PrintStream err)` Constructs a new InteractiveShell instance
`InteractiveShell(Binding binding, InputStream in, PrintStream out, PrintStream err)` Constructs a new InteractiveShell instance
`InteractiveShell(ClassLoader parent, Binding binding, InputStream in, PrintStream out, PrintStream err)` Constructs a new InteractiveShell instance

Method Summary
`void` | `accept()` Accepts the pending text into the statement.
`String` | `accepted(boolean complete)` Returns the accepted statement as a string.
`String` | `current()` Returns the current statement, including pending text.
`void` | `displayBinding()` Displays the current binding used when instanciating the shell.
`void` | `displayHelp()` Displays help text about available commands.
`void` | `displayStatement()` Displays the accepted statement.
`void` | `explainStatement()` Attempts to parse the accepted statement and display the parse tree for it.
`void` | `filterAndPrintStackTrace(Throwable cause)` Filter stacktraces to show only relevant lines of the exception thrown.
`void` | `freshen()` Clears accepted if stale.
`void` | `inspect()`
`static void` | `main(def args)` Entry point when called directly.
`boolean` | `parse(String code, int tolerance)` Attempts to parse the specified code with the specified tolerance.
`boolean` | `parse(String code)`
`static void` | `processCommandLineArguments(def args)` Process cli args when the shell is invoked via main().
`String` | `read()` Reads a single statement from the command line.
`void` | `report()` Reports the last parsing error to the user.
`void` | `reset()` The statement text accepted to date
`void` | `resetLoadedClasses()`
`void` | `run()` Reads commands and statements from input stream and processes them.
`void` | `setAfterExecution(Closure afterExecution)` A closure that is executed after the execution of the last script.
`void` | `setBeforeExecution(Closure beforeExecution)` A closure that is executed before the exection of a given script

Constructor Detail

### InteractiveShell

    public InteractiveShell()

  Default constructor, initializes uses new binding and system streams.

### InteractiveShell

    public InteractiveShell(InputStream in, PrintStream out, PrintStream err)

  Constructs a new InteractiveShell instance
  param:
    in The input stream to use
  param:
    out The output stream to use
  param:
    err The error stream to use

### InteractiveShell

    public InteractiveShell(Binding binding, InputStream in, PrintStream out, PrintStream err)

  Constructs a new InteractiveShell instance
  param:
    binding The binding instance
  param:
    in The input stream to use
  param:
    out The output stream to use
  param:
    err The error stream to use

### InteractiveShell

    public InteractiveShell(ClassLoader parent, Binding binding, InputStream in, PrintStream out, PrintStream err)

  Constructs a new InteractiveShell instance
  param:
    parent The parent ClassLoader
  param:
    binding The binding instance
  param:
    in The input stream to use
  param:
    out The output stream to use
  param:
    err The error stream to use

Method Detail

### accept

    void accept()

  Accepts the pending text into the statement.

### accepted

    String accepted(boolean complete)

  Returns the accepted statement as a string. If not complete, returns empty string.

### current

    String current()

  Returns the current statement, including pending text.

### displayBinding

    void displayBinding()

  Displays the current binding used when instanciating the shell.

### displayHelp

    void displayHelp()

  Displays help text about available commands.

### displayStatement

    void displayStatement()

  Displays the accepted statement.

### explainStatement

    void explainStatement()

  Attempts to parse the accepted statement and display the parse tree for it.

### filterAndPrintStackTrace

    void filterAndPrintStackTrace(Throwable cause)

  Filter stacktraces to show only relevant lines of the exception thrown.
  param:
    cause the throwable whose stacktrace needs to be filtered

### freshen

    void freshen()

  Clears accepted if stale.

### inspect

    void inspect()

### main

    public static void main(def args)

  Entry point when called directly.

### parse

    boolean parse(String code, int tolerance)

  Attempts to parse the specified code with the specified tolerance. Updates the `parser` and `error` members appropriately. Returns true if the text parsed, false otherwise. The attempts to identify and suppress errors resulting from the unfinished source text.

### parse

    boolean parse(String code)

### processCommandLineArguments

    static void processCommandLineArguments(def args)

  Process cli args when the shell is invoked via main().
  noinspection:
    AccessStaticViaInstance

### read

    String read()

  Reads a single statement from the command line. Also identifies and processes command shell commands. Returns the command text on success, or null when command processing is complete. NOTE: Changed, for now, to read until 'execute' is issued. At 'execute', the statement must be complete.

### report

    void report()

  Reports the last parsing error to the user.

### reset

    void reset()

  The statement text accepted to date

### resetLoadedClasses

    void resetLoadedClasses()

### run

    public void run()

  Reads commands and statements from input stream and processes them.

### setAfterExecution

    public void setAfterExecution(Closure afterExecution)

  A closure that is executed after the execution of the last script. The result of the execution is passed as the first argument to the closure (the value of 'it')
  param:
    afterExecution The closure to execute

### setBeforeExecution

    public void setBeforeExecution(Closure beforeExecution)

  A closure that is executed before the exection of a given script
  param:
    beforeExecution The closure to execute