Skip to content

aman224/text-editor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

42 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Terminal Text Editor

Overview

Terminal Text Editor is a lightweight, learning-focused text editor built in Java. It demonstrates low-level terminal manipulation by leveraging JNA (Java Native Access) to interface with C APIs (libc). This allows direct control over terminal behavior, including raw mode handling, input processing, and efficient screen rendering.

This project is designed for developers interested in understanding how tools like vim or nano work under the hood.

Features

  • Raw Mode Terminal: Direct control over terminal input and output without standard line buffering.
  • File Operations: Open, view, edit, and save text files.
  • Navigation: Full cursor movement support (Arrow keys, Page Up/Down, Home, End).
  • Search: Forward and backward search functionality.
  • Scrolling: seamless vertical and horizontal scrolling for large files.
  • Status Bar: Real-time cursor position and message feedback.

Tech Stack

  • Java 17: Core application logic.
  • JNA (Java Native Access): Bridge to native system calls (ioctl, termios).
  • Gradle: Build and dependency management.
  • JUnit 5: Unit testing framework.
  • Mockito: Mocking framework for tests.

Prerequisites

  • Java Development Kit (JDK) 17 or higher.
  • Linux/Unix environment (due to reliance on POSIX terminal APIs).

Build and Run

Building the Project

Use Gradle to create a standalone "uber" JAR containing all dependencies:

# Navigate to the root directory of the project
cd text-editor

# Build the application
./gradlew uberJar

The artifact will be created at build/libs/text-editor-1.0-SNAPSHOT-uber.jar.

Running the Editor

To start an empty editor:

java -jar build/libs/text-editor-1.0-SNAPSHOT-uber.jar

To open a specific file:

java -jar build/libs/text-editor-1.0-SNAPSHOT-uber.jar path/to/file.txt

Docker Deployment

The application can be built and run inside a Docker container. We use ttyd to serve the terminal interface over a web browser, making it accessible remotely.

Build the Image:

docker build -t text-editor:latest .

Run the Container:

docker run -p 8080:8080 text-editor:latest

Open your browser http://localhost:8080 to use the editor.

Key Bindings

Category Key Action
Navigation Arrow Keys Move cursor Up/Down/Left/Right
Page Up / Page Down Scroll by page
Home Jump to start of line
End Jump to end of line
Editing Enter Insert new line
Backspace / Delete Delete character
Tab Insert Tab space
Shift + Tab Delete Tab space
Commands Ctrl + S Save current file
Ctrl + F Search (Enter to exit, Arrows to find next/prev)
Ctrl + Q Quit application

Project Structure

The codebase is organized into logical components:

src/main/java/com/github/aman224/
├── Application.java      # Entry point
├── content/              # Core data models
│   ├── ContentBuffer.java    # Manages file content (lines of text)
│   ├── Cursor.java           # Manages cursor position and scrolling
│   ├── Status.java           # Manages status bar state
│   └── SearchHandler.java    # Implements search logic
├── editor/               # Main application logic
│   └── TextEditor.java       # Coordinates input, rendering, and logic
├── input/                # Input handling
│   ├── InputDecoder.java     # Parses raw bytes into key codes
│   └── InputKeys.java        # Key constants
└── terminal/             # Native interface layer
    ├── Terminal.java         # JNA setup for raw mode
    ├── TerminalRenderer.java # Draws content to screen using escape codes
    ├── LibC.java             # JNA mapping for standard C library
    └── syntax                # Syntax highlighting
         ├── JavaSyntaxHighlighter.java # Syntax highlighting specification for JAVA
         ├── StyleSpan.java             # Contains style information for highlighting tokens
         ├── SyntaxColourCodes.java     # ENUM for ANSI colour codes
         └── SyntaxHighlighter          # Interface for syntax highlighting logic

Running Tests

The project includes unit and integration tests to ensure stability.

./gradlew test

License

This project is open source and available for educational purposes.

About

Terminal text editor built using Java

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published