Class GroovyshOptions

java.lang.Object
org.apache.groovy.groovysh.GroovyshOptions

@Incubating public final class GroovyshOptions extends Object
Configuration for embedding groovysh programmatically via Main.start(GroovyshOptions, String[]).

Where a setting has an equivalent on JLine's ShellBuilder, this class deliberately uses the same name and parameter type, so that a future move of groovysh onto org.jline.shell is re-plumbing rather than a break in Groovy's API. The Groovy-specific settings — compiler configuration, engine, bindings, banner, and the result/error handlers a language REPL needs and a command shell does not — have no such equivalent.

Binding variables stay in getBindings(); they are not mixed with embedding hooks. Construct with builder().

Since:
7.0.0
  • Method Details

    • builder

      public static GroovyshOptions.Builder builder()
      Creates a builder for embedding options.
      Returns:
      a new builder with default values
    • getCompilerConfiguration

      public CompilerConfiguration getCompilerConfiguration()
      Compiler configuration used when this object does not already hold an engine. null means CompilerConfiguration.DEFAULT.
      Returns:
      the compiler configuration, or null
    • getEngine

      public GroovyEngine getEngine()
      Pre-built engine. When non-null, getCompilerConfiguration() is ignored because the engine already carries its configuration.
      Returns:
      the engine, or null to let Main construct one
    • getBindings

      public Map<String,Object> getBindings()
      Binding variables installed on the engine before the REPL starts.
      Returns:
      an unmodifiable map, never null
    • getGroups

      public List<org.jline.shell.CommandGroup> getGroups()
      Command groups contributed by the embedder. They are resolved before groovysh's own commands, so a group may override a built-in command name.
      Returns:
      an unmodifiable list, never null
    • getPrompt

      public Supplier<String> getPrompt()
      Prompt supplier invoked on each REPL iteration. null means "groovy> ".
      Returns:
      the prompt supplier, or null
    • getRightPrompt

      public Supplier<String> getRightPrompt()
      Right-hand prompt supplier invoked on each REPL iteration.
      Returns:
      the right prompt supplier, or null for none
    • getResultHandler

      public GroovyshOptions.ResultHandler getResultHandler()
      Result renderer. null means print result?.toString() via the printer.
      Returns:
      the result handler, or null
    • getErrorHandler

      public GroovyshOptions.ErrorHandler getErrorHandler()
      Error renderer. null means groovysh's own trace.
      Returns:
      the error handler, or null
    • isShowBanner

      public boolean isShowBanner()
      Whether Main should print the groovysh banner (or the quiet version line).
      Returns:
      true to print the banner
    • getTerminal

      public org.jline.terminal.Terminal getTerminal()
      Terminal to use instead of the one Main would build from CLI flags.
      Returns:
      the terminal, or null to build the default
    • getHistoryFile

      public Path getHistoryFile()
      History file for the session. null means groovysh's own groovysh_history in the user state directory.
      Returns:
      the history file, or null
    • getOnReaderReady

      public BiConsumer<org.jline.reader.LineReader,org.apache.groovy.groovysh.jline.GroovySystemRegistry> getOnReaderReady()
      Callback invoked once the reader and the command registry are both wired, immediately before the REPL starts, for settings this class does not model — the secondary prompt pattern, key bindings, reader options, and the completer.
      Returns:
      the callback, or null