Groovysh (Groovy 4.0.15)

Package: org.apache.groovy.groovysh

## [Groovy] Class Groovysh

- org.apache.groovy.groovysh.Groovysh

-     @AutoFinal
      @CompileStatic
      class Groovysh
      extends Shell

  An interactive shell for evaluating Groovy code from the command-line (aka. groovysh). The set of available commands can be modified by placing a file in the classpath named `org/codehaus/groovy/tools/shell/commands.xml`

  See Also:
    XmlCommandRegistrar

- - ### Field Summary

    Fields
    Modifiers | Name | Description
    --- | --- | ---
    `static String` | `AUTOINDENT_PREFERENCE_KEY` |
    `static String` | `COLLECTED_BOUND_VARS_MAP_VARNAME` |
    `static String` | `COLORS_PREFERENCE_KEY` |
    `static String` | `INTERPRETER_MODE_PREFERENCE_KEY` |
    `static String` | `METACLASS_COMPLETION_PREFIX_LENGTH_PREFERENCE_KEY` |
    `static String` | `SANITIZE_PREFERENCE_KEY` |
    `static String` | `SHOW_LAST_RESULT_PREFERENCE_KEY` |

  - Inherited fields
    Fields inherited from class | Fields
    --- | ---
    `class Shell` | `log`

  - ### Properties Summary

    Properties
    Type | Name and description
    --- | ---
    `BufferManager` | `buffers`
    `Closure` | `defaultErrorHook`
    `Closure` | `defaultResultHook`
    `Closure` | `errorHook`
    `String` | `evictedLine`
    `jline.console.history.FileHistory` | `history`
    `boolean` | `historyFull`
    `List<String>` | `imports`
    `int` | `indentSize`
    `Interpreter` | `interp`
    `PackageHelper` | `packageHelper`
    `Parser` | `parser`
    `Closure` | `resultHook`
    `InteractiveShellRunner` | `runner`

  - ### Constructor Summary

    Constructors
    Constructor and description
    `Groovysh(ClassLoader classLoader, Binding binding, IO io, Closure registrar, CompilerConfiguration configuration, Interpreter interpreter)`
    `Groovysh(ClassLoader classLoader, Binding binding, IO io, Closure registrar, CompilerConfiguration configuration)`
    `Groovysh(Binding binding, IO io)`
    `Groovysh(IO io, CompilerConfiguration cc)`
    `Groovysh(IO io)`
    `Groovysh()`

  - ### Methods Summary

    Methods
    Type Params | Return Type | Name and description
    --- | --- | ---
    `` | `void` | `displayBuffer(List buffer)` Display the given buffer.
    `` | `void` | `displayWelcomeBanner(InteractiveShellRunner runner)` maybe displays log information and a welcome message
    `` | `Object` | `execute(String line)` Execute a single line, where the line may be a command or Groovy code (complete or incomplete).
    `` | `protected Object` | `executeCommand(String line)`
    `` | `protected String` | `formatLineNumber(int num)` Format the given number suitable for rendering as a line number column.
    `` | `String` | `getImportStatements()`
    `` | `String` | `getIndentPrefix()` Calculate probably desired indentation based on parenthesis balance and last char, as well as what the user used last as indentation.
    `` | `protected String` | `getPreference(String key, String theDefault)`
    `` | `File` | `getUserStateDirectory()`
    `` | `static boolean` | `isTypeOrMethodDeclaration(List<String> buffer)` return true if the buffer can be recognized as a type declaration statement
    `` | `protected void` | `loadUserScript(String filename)` Loads file from within user groovy state directory.
    `` | `protected void` | `maybeRecordError(Throwable cause)`
    `` | `protected void` | `maybeRecordInput(String line)`
    `` | `protected void` | `maybeRecordResult(Object result)`
    `` | `String` | `renderPrompt()`
    `` | `int` | `run(String evalString, List<String> filenames)` Run the Interactive Shell with optional initial script and files to load.
    `` | `int` | `run(String commandLine)` Run the Interactive Shell with initial command.

  - ### Inherited Methods Summary

    Inherited Methods
    Methods inherited from class | Name
    --- | ---
    `class Shell` | `execute, findCommand, isExecutable, leftShift, leftShift, register`

- - ### Field Detail

    - #### public static final String AUTOINDENT_PREFERENCE_KEY

    - #### public static final String COLLECTED_BOUND_VARS_MAP_VARNAME

    - #### public static final String COLORS_PREFERENCE_KEY

    - #### public static final String INTERPRETER_MODE_PREFERENCE_KEY

    - #### public static final String METACLASS_COMPLETION_PREFIX_LENGTH_PREFERENCE_KEY

    - #### public static final String SANITIZE_PREFERENCE_KEY

    - #### public static final String SHOW_LAST_RESULT_PREFERENCE_KEY

  - ### Property Detail

    - #### final BufferManager buffers

    - #### final Closure defaultErrorHook

    - #### final Closure defaultResultHook

    - #### Closure errorHook

    - #### String evictedLine

    - #### jline.console.history.FileHistory history

    - #### boolean historyFull

    - #### final List<String> imports

    - #### int indentSize

    - #### final Interpreter interp

    - #### PackageHelper packageHelper

    - #### final Parser parser

    - #### Closure resultHook

    - #### InteractiveShellRunner runner

  - ### Constructor Detail

    - #### Groovysh(ClassLoader classLoader, Binding binding, IO io, @ClosureParams(value: SimpleType, options: org.apache.groovy.groovysh.Groovysh)
      Closure registrar, CompilerConfiguration configuration, Interpreter interpreter)

    - #### Groovysh(ClassLoader classLoader, Binding binding, IO io, @ClosureParams(value: SimpleType, options: org.apache.groovy.groovysh.Groovysh)
      Closure registrar, CompilerConfiguration configuration)

    - #### Groovysh(Binding binding, IO io)

    - #### Groovysh(IO io, CompilerConfiguration cc)

    - #### Groovysh(IO io)

    - #### Groovysh()

  - ### Method Detail

    - #### void displayBuffer(List buffer)

      Display the given buffer.

    - #### void displayWelcomeBanner(InteractiveShellRunner runner)

      maybe displays log information and a welcome message

      Parameters:
        term

    - #### @Override
      Object execute(String line)

      Execute a single line, where the line may be a command or Groovy code (complete or incomplete).

    - #### protected Object executeCommand(String line)

    - #### protected String formatLineNumber(int num)

      Format the given number suitable for rendering as a line number column.

    - #### String getImportStatements()

    - #### String getIndentPrefix()

      Calculate probably desired indentation based on parenthesis balance and last char, as well as what the user used last as indentation.

      Returns:
        a string to indent the next line in the buffer

    - #### protected String getPreference(String key, String theDefault)

    - #### File getUserStateDirectory()

    - #### static boolean isTypeOrMethodDeclaration(List<String> buffer)

      return true if the buffer can be recognized as a type declaration statement @return

      Parameters:
        strings

    - #### @CompileDynamic
      protected void loadUserScript(String filename)

      Loads file from within user groovy state directory.

    - #### protected void maybeRecordError(Throwable cause)

    - #### protected void maybeRecordInput(String line)

    - #### protected void maybeRecordResult(Object result)

    - #### String renderPrompt()

    - #### int run(String evalString, List<String> filenames)

      Run the Interactive Shell with optional initial script and files to load.

    - #### int run(String commandLine)

      Run the Interactive Shell with initial command.