This is a lightweight code editor built with Kotlin and JavaFX, designed to let users write, execute, and debug Kotlin scripts within a simple graphical interface. The application provides a code area for script input, an output console for viewing execution results, and features like syntax highlighting and error navigation. It’s an ideal tool for developers experimenting with Kotlin scripts or building educational tools.
- Syntax Highlighting: Highlights Kotlin keywords (e.g.,
fun,val,if) for improved readability. - Error Highlighting: Marks compilation errors in the code with clickable links to jump to the error’s location.
- Output Console: Displays script execution output and error messages in a list view below the code area.
- Script Execution: Run Kotlin scripts with a single click and see results instantly.
- Cancel Functionality: Script execution can be cancelled (implemented in the backend but not yet exposed in the UI).
To run this project, ensure you have the following installed:
- JDK 11 or higher: Required for JavaFX and Kotlin compatibility.
- Kotlin Compiler (
kotlinc): Must be available in your system’s PATH to compile and run scripts. - JavaFX SDK: Provides the UI framework (download from GluonHQ).
- RichTextFX Library: Powers the code area with advanced text editing features (available on GitHub).
- An IDE (Recommended): IntelliJ IDEA with the Kotlin plugin is suggested for the easiest setup.
Follow these steps to set up the project on your machine:
-
Clone the Repository
Clone this project to your local machine using Git:git clone https://github.com/cedbanana/KCodeEditor.git
-
Navigate to the Project Directory
Move into the project folder:cd KCodeEditor -
Set Up Your IDE (Recommended: IntelliJ IDEA)
- Open IntelliJ IDEA and select
File > Open, then choose the project folder. - Ensure the Kotlin plugin is installed (go to
File > Settings > Pluginsand search for "Kotlin"). - Add the JavaFX SDK:
- Go to
File > Project Structure > Libraries. - Click
+, selectJava, and navigate to thelibfolder of your JavaFX SDK (e.g.,path/to/javafx-sdk/lib).
- Go to
- Add the RichTextFX library:
- Download the JAR from GitHub or use a dependency manager (see below).
- In
Project Structure > Libraries, click+, selectJava, and add the RichTextFX JAR.
- Open IntelliJ IDEA and select
-
Optional: Dependency Management with Gradle
If you prefer using Gradle, create abuild.gradlefile with these dependencies:dependencies { implementation "org.openjfx:javafx-controls:17" implementation "org.fxmisc.richtext:richtextfx:0.10.5" }Adjust versions as needed based on the latest releases.
-
Verify
kotlincin PATH
Open a terminal and run:kotlinc -version
If it’s not recognized, add the Kotlin compiler to your system’s PATH (consult Kotlin’s installation guide).
You can run the project either through an IDE or the command line.
- Open the project in IntelliJ IDEA.
- Ensure JavaFX and RichTextFX are configured in the project structure (see Installation step 3).
- Locate the
CodeEditorAppclass insrc/com/app. - Click the green "Run" button next to the
mainfunction, or right-click and selectRun 'CodeEditorApp'.
-
Compile the Kotlin files:
kotlinc -cp "path/to/javafx-sdk/lib/*;path/to/richtextfx.jar" -d out src/com/app/*.kt
- Replace
path/to/javafx-sdk/lib/*with the path to your JavaFX SDK’slibfolder. - Replace
path/to/richtextfx.jarwith the path to the RichTextFX JAR. - On Unix-like systems (Linux/macOS), use
:instead of;as the classpath separator.
- Replace
-
Run the application:
java -cp "out;path/to/javafx-sdk/lib/*;path/to/richtextfx.jar" com.app.CodeEditorAppAgain, adjust the separator (
;or:) based on your OS.
Once the application is running, here’s how to use it:
-
Write a Script
Type your Kotlin script in the code area (e.g.,println("Hello, World!")). -
Run the Script
Click the "Submit" button to execute the script. The output (or errors) will appear in the list view below. -
Navigate Errors
If errors occur, they’ll be highlighted in the code area. Click an error message in the output console while holdingCtrl(Windows/Linux) orCmd(macOS) to jump to the error’s location. -
Cancel Execution
The backend supports cancelling scripts (viaScriptRunner.cancel()), but this isn’t yet available in the UI. To add this, extend theCodeEditorControllerto include a "Cancel" button.
- Kotlin Compiler: The app relies on
kotlincto execute scripts, so it must be accessible in your PATH. - Syntax Highlighting: Currently highlights keywords only. Modify the
Highlighterclass to add support for strings, comments, etc. - Extensibility: The modular design (e.g.,
ScriptRunner,Highlighter) makes adding new features like additional languages or UI enhancements easy. - Windows Support: Unfortunately, the project is not yet ready to run on Windows Machines.