CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/maven-org-apache-groovy--groovy-groovysh

Interactive command-line shell (REPL) for Apache Groovy with scripting engine and rich command system

Pending
Overview
Eval results
Files

console-integration.mddocs/

Console Integration

Advanced console features including syntax highlighting, auto-completion, custom command registration, and integration with JLine3 terminal capabilities. These components provide the rich interactive experience of the Groovy shell.

Capabilities

Console Engine

Enhanced console engine with Groovy-specific printing capabilities and command support.

/**
 * Enhanced console engine extending JLine's ConsoleEngineImpl
 */
class GroovyConsoleEngine {
    /**
     * Enhanced printing with formatting options
     * @param options Map of printing options for formatting control
     * @param object Object to print
     */
    void println(Map<String, Object> options, Object object)
    
    /**
     * Set console configuration option
     * @param option Option name
     * @param value Option value
     */
    void setConsoleOption(String option, Object value)
}

Usage Examples:

import org.apache.groovy.groovysh.jline.GroovyConsoleEngine

// Create console engine
GroovyConsoleEngine console = new GroovyConsoleEngine(
    scriptEngine, printer, workDir, configPath, reader
)

// Configure console options
console.setConsoleOption("docs", new DocFinder())

// Enhanced printing with options
Map<String, Object> printOptions = [
    color: true,
    format: "json",
    indent: 2
]
console.println(printOptions, ["name": "Alice", "age": 25])

System Registry

Enhanced command execution system with Groovy syntax support and custom operators.

/**
 * System registry extending SystemRegistryImpl with Groovy enhancements
 */
class GroovySystemRegistry {
    /**
     * Execute command or script with Groovy enhancements
     * @param line Command/script line to execute
     * @return Execution result
     */
    Object execute(String line)
    
    /**
     * Determine if input is command or script
     * @param command Input string to analyze
     * @return true if command, false if script
     */
    boolean isCommandOrScript(String command)
    
    /**
     * Set command registries for the system
     * @param registries Command registry instances
     */
    void setCommandRegistries(CommandRegistry... registries)
    
    /**
     * Add completer for auto-completion
     * @param completer Completer instance
     */
    void addCompleter(Completer completer)
    
    /**
     * Set script description provider
     * @param provider Function to provide script descriptions
     */
    void setScriptDescription(Function<String, String> provider)
    
    /**
     * Group commands in help display
     * @param group Whether to group commands
     */
    void groupCommandsInHelp(boolean group)
    
    /**
     * Rename local command
     * @param oldName Current command name
     * @param newName New command name
     */
    void renameLocal(String oldName, String newName)
    
    /**
     * Create command alias
     * @param aliasName Alias name
     * @param targetName Target command name
     */
    void invoke(String aliasCommand, String aliasName, String targetName)
    
    /**
     * Set console option
     * @param option Option name
     * @param value Option value
     */
    void setConsoleOption(String option, Object value)
}

Usage Examples:

import org.apache.groovy.groovysh.jline.GroovySystemRegistry

// Create system registry
GroovySystemRegistry systemRegistry = new GroovySystemRegistry(
    parser, terminal, workDir, configPath
)

// Configure registry
systemRegistry.groupCommandsInHelp(false)
systemRegistry.setCommandRegistries(extraCommands, consoleEngine, builtins, groovyCommands)
systemRegistry.addCompleter(scriptEngine.getScriptCompleter())
systemRegistry.setScriptDescription(scriptEngine::scriptDescription)

// Set up command aliases
systemRegistry.renameLocal('exit', '/exit')
systemRegistry.renameLocal('help', '/help')
systemRegistry.invoke('/alias', '/x', '/exit')
systemRegistry.invoke('/alias', '/q', '/exit')

// Configure options
systemRegistry.setConsoleOption("ignoreUnknownPipes", true)

// Execute commands/scripts
Object result = systemRegistry.execute("def x = 42; x * 2")
boolean isCommand = systemRegistry.isCommandOrScript("/help")

Custom Pipe Operators

Support for enhanced pipe operations beyond standard shell pipes.

// Conditional execution pipe
command1 |&& command2    // Execute command2 only if command1 succeeds

// Alternative execution pipe  
command1 ||| command2    // Execute command2 only if command1 fails

// Output redirection pipes
command |> filename      // Redirect output to file (overwrite)
command |>> filename     // Redirect output to file (append)

Usage Examples:

groovy> def result = calculate() |&& processResult()
groovy> loadConfig() ||| useDefaults()
groovy> /vars |> variables.txt
groovy> getCurrentState() |>> state.log

Command Registration

Register custom commands and command handlers within the shell environment.

/**
 * Command registry for managing custom commands
 */
class ExtraConsoleCommands {
    /**
     * Register custom command methods
     * @param commands Map of command names to method implementations
     */
    void registerCommands(Map<String, CommandMethods> commands)
    
    /**
     * Get current working directory
     * @return Current directory path
     */
    Path currentDir()
}

/**
 * Command methods wrapper for command implementations
 */
class CommandMethods {
    /**
     * Create command methods
     * @param function Command execution function
     * @param completer Command completer function
     */
    CommandMethods(Function function, Function completer)
}

Usage Examples:

// Create custom command registry
ExtraConsoleCommands extraCommands = new ExtraConsoleCommands(
    workDir, scriptEngine, reader
)

// Define custom commands
Map<String, CommandMethods> customCommands = [
    '/mycommand': new CommandMethods(
        this::myCommandHandler,
        this::myCommandCompleter
    )
]

// Register commands
extraCommands.registerCommands(customCommands)

Syntax Highlighting

Advanced syntax highlighting system with support for multiple languages and contexts.

/**
 * System syntax highlighter with context-aware highlighting
 */
class SystemHighlighter {
    /**
     * Set highlighter for specific commands
     * @param command Command name
     * @param highlighter Syntax highlighter instance
     */
    void setSpecificHighlighter(String command, SyntaxHighlighter highlighter)
    
    /**
     * Add file highlighting for commands
     * @param commands Commands that work with files
     */
    void addFileHighlight(String... commands)
    
    /**
     * Add external highlighter refresh callback
     * @param refreshCallback Callback function for refresh
     */
    void addExternalHighlighterRefresh(Runnable refreshCallback)
}

Usage Examples:

SystemHighlighter highlighter = new SystemHighlighter(
    commandHighlighter, argsHighlighter, groovyHighlighter
)

// Configure specific command highlighting
if (!OSUtils.IS_WINDOWS) {
    highlighter.setSpecificHighlighter("/!", 
        SyntaxHighlighter.build(jnanorc, "SH-REPL"))
}

// Add file highlighting for file operations
highlighter.addFileHighlight('/nano', '/less', '/slurp', '/load', '/save')
highlighter.addFileHighlight('/classloader', null, ['-a', '--add'])

// Set up refresh callbacks
highlighter.addExternalHighlighterRefresh(printer::refresh)
highlighter.addExternalHighlighterRefresh(scriptEngine::refresh)

Auto-completion System

Comprehensive auto-completion system with context-aware suggestions and multi-level completion.

/**
 * Get completer for the system registry
 * @return Combined completer for all registered completers
 */
Completer completer()

/**
 * Maven coordinate completer for dependency management
 */
class MavenCoordinateCompleter {
    // Auto-completion for Maven artifact coordinates
}

/**
 * Option completer for command options
 */
class OptionCompleter {
    /**
     * Create option completer
     * @param fileCompleter Base file completer
     * @param optionProvider Function providing command options
     * @param maxOptions Maximum number of options to show
     */
    OptionCompleter(Completer fileCompleter, Function optionProvider, int maxOptions)
}

Usage Examples:

// Set up reader with completion
LineReader reader = LineReaderBuilder.builder()
    .terminal(terminal)
    .parser(parser)
    .build()

// Configure completion
reader.setCompleter(systemRegistry.completer())

// Completion will work for:
// - Command names and options
// - File paths
// - Maven coordinates
// - Variable names
// - Groovy language constructs

Terminal Integration

Deep integration with JLine3 terminal capabilities for cross-platform compatibility.

// Terminal configuration
Terminal terminal = TerminalBuilder.builder()
    .type(terminalType)
    .encoding(encoding)
    .color(colorEnabled)
    .name('groovysh')
    .build()

// Configure terminal size for redirected output
if (terminal.width == 0 || terminal.height == 0) {
    terminal.size = new Size(120, 40)
}

// Handle interrupt signals
Thread executeThread = Thread.currentThread()
terminal.handle(Signal.INT, signal -> executeThread.interrupt())

Widget System

Advanced widgets for enhanced user interaction including suggestions and tooltips.

/**
 * Tail tip widgets for command descriptions
 */
class TailTipWidgets {
    /**
     * Create tail tip widgets
     * @param reader Line reader instance
     * @param descriptionProvider Function providing descriptions
     * @param maxTips Maximum number of tips to show
     * @param tipType Type of tips to display
     */
    TailTipWidgets(LineReader reader, Function descriptionProvider, 
                   int maxTips, TipType tipType)
}

/**
 * Auto-suggestion widgets for completion
 */
class AutosuggestionWidgets {
    /**
     * Create auto-suggestion widgets
     * @param reader Line reader instance
     */
    AutosuggestionWidgets(LineReader reader)
}

Usage Examples:

// Set up widgets
new TailTipWidgets(reader, systemRegistry::commandDescription, 5, TipType.COMPLETER)
new AutosuggestionWidgets(reader)

// Bind widget toggle keys
KeyMap<Binding> keyMap = reader.getKeyMaps().get("main")
keyMap.bind(new Reference(Widgets.TAILTIP_TOGGLE), KeyMap.alt("s"))
keyMap.bind(new Reference(Widgets.AUTOSUGGEST_TOGGLE), KeyMap.alt("v"))

Install with Tessl CLI

npx tessl i tessl/maven-org-apache-groovy--groovy-groovysh

docs

console-integration.md

documentation-inspection.md

index.md

interactive-commands.md

script-engine.md

tile.json