CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/maven-org-codehaus-groovy--groovy-console

A Swing-based interactive console for evaluating Groovy expressions and scripts with syntax highlighting, code completion, and an integrated AST browser.

Pending
Overview
Eval results
Files

console-application.mddocs/

Console Application

The main Console class provides an interactive Groovy development environment with script execution, file management, debugging tools, and comprehensive IDE-like features.

Core Console Class

class Console implements CaretListener, HyperlinkListener, ComponentListener, FocusListener {
    // Constructors
    Console()
    Console(Binding binding)
    Console(ClassLoader parent, Binding binding, CompilerConfiguration baseConfig)
    
    // Application Entry Points
    static void main(String[] args)
    void run()
    void run(Map defaults)
    void run(JApplet applet) // @Deprecated
    
    // Script Execution
    void runScript(EventObject evt = null)
    void runSelectedScript(EventObject evt = null)
    void compileScript(EventObject evt = null)
    
    // File Operations
    void fileNewFile(EventObject evt = null)
    void fileNewWindow(EventObject evt = null)
    void fileOpen(EventObject evt = null)
    void loadScriptFile(File file)
    
    // Development Tools
    void inspectLast(EventObject evt = null)
    void inspectVariables(EventObject evt = null)
    void inspectAst(EventObject evt = null)
    void inspectCst(EventObject evt = null)
    void inspectTokens(EventObject evt = null)
    
    // UI Management
    void clearOutput(EventObject evt = null)
    void showAbout(EventObject evt = null)
    void preferences(EventObject evt = null)
    
    // Public Fields
    static URL ICON_PATH
    static URL NODE_ICON_PATH
}

Parameters

Constructor Parameters:

  • binding (Binding, optional): Variable binding context for script execution. Defaults to new Binding()
  • parent (ClassLoader, optional): Parent class loader for script compilation
  • baseConfig (CompilerConfiguration, optional): Base compiler configuration. Defaults to new CompilerConfiguration()

run() Method Parameters:

  • defaults (Map, optional): Configuration map with UI defaults like title, size, etc.
  • applet (JApplet, optional): Parent applet when running as applet

Returns

  • main(): void - Launches the console application
  • run(): void - Starts the console UI
  • Other methods return void and are typically called by UI event handlers

Applet Support

class ConsoleApplet extends JApplet {
    // Constructor
    ConsoleApplet()
    
    // Applet Lifecycle Methods  
    void init()
    void start()
    void stop()
    void destroy()
    
    // Console Integration
    Console getConsole()
}

The ConsoleApplet class provides applet-compatible console functionality for web browser integration. It wraps the main Console functionality in an applet container for deployment in web browsers.

Note: Applet support is deprecated as modern browsers no longer support Java applets.

Legacy API (Deprecated)

Warning: The groovy.ui package is deprecated. Use groovy.console.ui for new code.

// Legacy imports (same API as groovy.console.ui but deprecated)
import groovy.ui.Console // @Deprecated
import groovy.ui.ConsoleApplet // @Deprecated

Usage Examples

Basic Console Launch

// Launch console with default settings
groovy.console.ui.Console.main([] as String[])

// Or programmatically
def console = new groovy.console.ui.Console()
console.run()

Custom Console Configuration

// With custom binding
def binding = new Binding()
binding.setVariable('name', 'World')
binding.setVariable('data', [1, 2, 3, 4, 5])

def console = new groovy.console.ui.Console(binding)
console.run([
    title: 'My Groovy Console',
    size: [800, 600]
])

Programmatic Script Loading

def console = new groovy.console.ui.Console()
console.loadScriptFile(new File('my-script.groovy'))
console.run()

With Custom ClassLoader

def customClassLoader = new GroovyClassLoader()
def binding = new Binding()
def config = new CompilerConfiguration()

def console = new groovy.console.ui.Console(customClassLoader, binding, config)
console.run()

Integration Points

File Type Associations

The console includes built-in file filtering for Groovy scripts:

// Internal file filter for .groovy files
class GroovyFileFilter extends FileFilter {
    // Filters for *.groovy files in file dialogs
}

Event Handling

The Console implements multiple listener interfaces for comprehensive UI interaction:

  • CaretListener - Text cursor position changes
  • HyperlinkListener - Hyperlink navigation in output
  • ComponentListener - Window resizing and positioning
  • FocusListener - Focus gain/loss events

Execution Context

Scripts executed in the console have access to:

  • Binding variables set during construction
  • Console instance itself (for advanced integration)
  • Full Groovy runtime and standard library
  • Any additional dependencies in the classpath

Install with Tessl CLI

npx tessl i tessl/maven-org-codehaus-groovy--groovy-console

docs

ast-browser.md

console-application.md

index.md

object-inspector.md

system-integration.md

text-editing.md

tile.json