A Java-based GUI application for executing Kotlin scripts with live output display, syntax highlighting, and interactive error navigation.
This application provides an integrated development environment for writing and running Kotlin scripts. It features a split-pane interface with a code editor and output console, allowing real-time script execution and debugging.
-
Java Development Kit (JDK) 11 or higher
- Check installation:
java -version - Download from: official sources
- Check installation:
-
Kotlin Compiler
- Check installation:
kotlinc -version - Install on macOS:
brew install kotlin - Install on Linux: Download from official sources
- The tool uses
/usr/bin/env kotlincto locate the compiler
- Check installation:
macOS/Linux:
cd kotlin-script-runner
chmod +x build.sh
./build.shWindows:
cd kotlin-script-runner
build.batThe script compiles the Java source code and launches the application automatically.
cd kotlin-script-runner
javac -d bin src/ScriptRunner.java
java -cp bin ScriptRunner- Open the project in IntelliJ IDEA or any Java IDE
- Add
srcas a source folder - Run
ScriptRunner.javaas a Java application
kotlin-script-runner/
├── src/
│ └── ScriptRunner.java # Main application (single file)
├── bin/ # Compiled classes (auto-generated)
├── samples/ # Example Kotlin scripts
│ ├── hello.kts
│ ├── loop.kts
│ ├── error.kts
│ └── edge-cases/
├── build.sh # Build script for Unix systems
├── build.bat # Build script for Windows
├── README.md # This file
└── UI_DESCRIPTION.md # Detailed UI documentation
The application features a split-pane layout:
Editor Pane (Left):
- Editable text area for writing Kotlin scripts
- Line numbers displayed in the left gutter for easy reference
- Syntax highlighting with color-coded keywords, strings, and comments
- Monospaced font optimized for code editing
- Standard text editing shortcuts (copy, paste, undo, select all)
Output Pane (Right):
- Read-only console displaying script execution output
- Dark theme with high contrast for readability
- Auto-scrolling to show latest output
- Clickable error messages that navigate to source locations
- Combines both stdout and stderr streams
Toolbar (Top):
- Run Button: Starts script execution (green, disabled while running)
- Stop Button: Terminates running scripts (red, enabled only while running)
- Status Indicator: Shows current execution state (Idle, Running, Stopped, Error)
- Exit Code Display: Shows success (✓ Exit Code: 0) or failure (✗ Exit Code: N)
For detailed UI specifications, see UI_DESCRIPTION.md.
-
Write Script: Enter your Kotlin code in the editor pane
- The editor comes pre-loaded with a sample script
- Syntax highlighting updates automatically as you type
-
Execute Script: Click the "▶ Run" button
- Status changes to "Running" with a green indicator
- Output appears in real-time in the output pane
- The UI remains responsive during execution
-
View Results: Watch the output stream live
- Script output displays line-by-line as it executes
- Errors show in the output with file location information
-
Check Status: After completion, verify the exit code
- Green "✓ Exit Code: 0" indicates successful execution
- Red "✗ Exit Code: N" indicates failure with error code N
-
Stop Execution: Use the "⬛ Stop" button for long-running scripts
- Immediately terminates the running process
- Status changes to "Stopped" with orange indicator
Error Navigation:
- Click on any error line in the output pane (shows line number in format:
file.kts:LINE:COL:) - The editor automatically jumps to the error location
- Status bar displays which line was navigated to
- Works with Kotlin compiler error format:
file.kts:LINE:COL: error message
Syntax Highlighting:
- Keywords highlighted in blue with bold formatting
- String literals displayed in green
- Comments shown in gray with italic formatting
- Real-time updates with 300ms debounce for performance
Language: Java 11+
GUI Framework: Swing (javax.swing)
Script Execution: Kotlin compiler via ProcessBuilder
Threading: ExecutorService for concurrent execution
Text Processing: StyledDocument for syntax highlighting
ScriptRunner.java - Main application class containing:
initializeUI(): Constructs the GUI layout with split panes and line numberssetupStyles(): Configures text styles for syntax highlightingupdateLineNumbers(): Updates the line number gutter when text changesapplySyntaxHighlighting(): Applies real-time syntax coloring using regexrunScript(): Manages script execution in background threadsstopScript(): Terminates running processeshandleOutputClick(): Parses error locations from output (including line numbers)navigateToPosition(): Moves editor cursor to specific line/column
-
Script Execution Flow:
- User clicks Run button
- Script content is written to a temporary
.ktsfile - ProcessBuilder spawns
kotlinc -scriptcommand - Output is streamed line-by-line using BufferedReader
- Temporary file is deleted after execution completes
-
Live Output Streaming:
- Runs in a background thread to keep UI responsive
- Reads process output continuously
- Updates output pane in real-time via SwingUtilities.invokeLater
- Captures both standard output and error streams
-
Process Management:
- Stores reference to running process
- Stop button calls destroyForcibly() to terminate
- Proper cleanup of resources in finally blocks
- Thread-safe execution state management
-
Syntax Highlighting:
- Uses regex patterns to match Kotlin keywords, strings, and comments
- StyledDocument applies text attributes (color, font style)
- DocumentListener triggers highlighting on text changes
- Debounce timer prevents excessive re-rendering during typing
-
Error Parsing:
- Regex pattern matches
file.kts:LINE:COL:format - Extracts line and column numbers from error messages
- Calculates character offset in editor document
- Highlights error line and moves cursor to location
- Regex pattern matches
The samples/ directory contains example scripts:
hello.kts: Simple hello world exampleloop.kts: Demonstrates live output streamingerror.kts: Shows error handling and clickable navigationfeatures.kts: Comprehensive demonstration of various capabilitiesedge-cases/: Scripts testing various edge cases