Skip to content

Conversation

@gnodet
Copy link
Member

@gnodet gnodet commented Jul 9, 2025

Overview

This PR introduces two new terminal implementations built on top of the existing ScreenTerminal class, enabling JLine to be used in web applications and desktop GUI applications.

New Features

🌐 WebTerminal

An HTTP-based terminal implementation that serves a web interface:

  • Uses JDK's built-in HttpServer (no external dependencies)
  • Real-time terminal updates via AJAX polling
  • ANSI escape sequence rendering in HTML/CSS
  • Full keyboard support including special keys (arrows, function keys, Ctrl combinations)
  • GZIP compression for better performance
  • Session management for multiple concurrent users
  • Browser compatibility: Chrome 60+, Firefox 55+, Safari 12+, Edge 79+

🖥️ SwingTerminal

A Swing JComponent-based terminal for desktop applications:

  • Custom painting for terminal characters and attributes
  • ANSI color support (16 standard colors)
  • Font configuration with monospace fonts
  • Keyboard and mouse input handling
  • Cursor blinking with configurable timing
  • Thread-safe input/output operations
  • Can be embedded in any Swing application

Implementation Details

Architecture

  • Both implementations extend ScreenTerminal and inherit full ANSI escape sequence support
  • Thread-safe design with proper synchronization
  • Clean separation of concerns between terminal logic and presentation
  • Follows existing JLine patterns and conventions

Code Quality

  • Comprehensive JavaDoc documentation
  • Complete test suite with unit tests
  • Demo applications showing various usage patterns
  • Integration examples with shell processes
  • Error handling and edge case coverage

Files Added

Core Implementation

  • builtins/src/main/java/org/jline/builtins/WebTerminal.java - Web-based terminal
  • builtins/src/main/java/org/jline/builtins/SwingTerminal.java - Swing-based terminal
  • builtins/src/main/java/org/jline/builtins/TerminalDemo.java - Demo applications

Testing

  • builtins/src/test/java/org/jline/builtins/TerminalTest.java - Comprehensive test suite
  • builtins/src/test/java/org/jline/builtins/SimpleTerminalTest.java - Basic functionality tests

Documentation

  • website/docs/advanced/web-swing-terminals.md - Complete user documentation with examples

Files Modified

  • builtins/src/main/java/org/jline/builtins/ScreenTerminal.java - Added getWidth() and getHeight() public methods
  • website/docs/modules/builtins.md - Added section about terminal implementations
  • website/sidebars.ts - Added new documentation page to navigation

Usage Examples

WebTerminal

WebTerminal webTerminal = new WebTerminal("localhost", 8080, 80, 24);
webTerminal.write("Welcome to JLine WebTerminal!\n$ ");
webTerminal.start();
// Access at http://localhost:8080

SwingTerminal

SwingTerminal swingTerminal = new SwingTerminal(80, 24);
JFrame frame = swingTerminal.createFrame("My Terminal");
frame.setVisible(true);
swingTerminal.write("Welcome to JLine SwingTerminal!\n$ ");

Demo Applications

The TerminalDemo class provides several demo modes:

  • web - Web terminal demo
  • swing - Basic Swing terminal demo
  • advanced - Advanced Swing terminal with menu bar and font selection
  • both - Both terminals running simultaneously

Testing

  • All new code is covered by unit tests
  • Tests verify terminal creation, I/O operations, ANSI sequence handling, and error conditions
  • Manual testing performed on multiple browsers and operating systems
  • Integration testing with shell processes

Backward Compatibility

  • No breaking changes to existing APIs
  • Only additive changes to ScreenTerminal (new public getter methods)
  • All existing functionality remains unchanged

Performance

  • WebTerminal uses efficient AJAX polling with GZIP compression
  • SwingTerminal uses optimized repainting and font metric caching
  • Both implementations handle concurrent access safely
  • Memory usage scales appropriately with terminal size and session count

Future Enhancements

Potential improvements identified for future versions:

  • WebSocket support for WebTerminal
  • 256-color support for SwingTerminal
  • Scrollback buffer with search functionality
  • Terminal recording and playback capabilities

Documentation

Comprehensive documentation has been added to the website including:

  • API reference with examples
  • Integration patterns
  • Performance considerations
  • Browser compatibility information
  • Known limitations and workarounds

This feature significantly expands JLine's capabilities, enabling it to be used in web applications and desktop GUI applications while maintaining the same powerful terminal functionality that JLine is known for.


Pull Request opened by Augment Code with guidance from the PR author

@gnodet gnodet changed the title Add Web and Swing Terminal Implementations feat: add Web and Swing Terminal Implementations Jul 16, 2025
@gnodet gnodet added the feature label Jul 16, 2025
@gnodet gnodet marked this pull request as draft July 18, 2025 21:56
@gnodet gnodet force-pushed the feature/web-swing-terminals branch from 89d5e30 to 91428cc Compare August 5, 2025 21:23
@gnodet gnodet added this to the 4.0.0 milestone Aug 6, 2025
@gnodet gnodet force-pushed the feature/web-swing-terminals branch from 91428cc to 4343e1c Compare August 6, 2025 21:45
This commit introduces two new terminal implementations built on top of ScreenTerminal:

1. WebTerminal - HTTP-based terminal with web interface
   - Uses JDK's built-in HttpServer
   - Real-time updates via AJAX polling
   - ANSI escape sequence rendering in HTML/CSS
   - Full keyboard support including special keys
   - GZIP compression for better performance
   - Session management for multiple users

2. SwingTerminal - Swing JComponent-based terminal for desktop apps
   - Custom painting for terminal characters and attributes
   - ANSI color support (16 standard colors)
   - Font configuration with monospace fonts
   - Keyboard and mouse input handling
   - Cursor blinking and thread-safe operations
   - Can be embedded in any Swing application

Features:
- Both extend ScreenTerminal and support full ANSI escape sequences
- Thread-safe implementations with proper synchronization
- Comprehensive demo applications showing usage patterns
- Integration examples with shell processes
- Complete test suite covering functionality
- Detailed documentation with examples

Files added:
- builtins/src/main/java/org/jline/builtins/WebTerminal.java
- builtins/src/main/java/org/jline/builtins/SwingTerminal.java
- builtins/src/main/java/org/jline/builtins/TerminalDemo.java
- builtins/src/test/java/org/jline/builtins/TerminalTest.java
- builtins/src/test/java/org/jline/builtins/SimpleTerminalTest.java
- website/docs/advanced/web-swing-terminals.md

Files modified:
- builtins/src/main/java/org/jline/builtins/ScreenTerminal.java (added getWidth/getHeight methods)
- website/docs/modules/builtins.md (added terminal implementations section)
- website/sidebars.ts (added new documentation page)

The implementations are production-ready and provide a foundation for
building web-based and desktop terminal applications using JLine.
@gnodet gnodet force-pushed the feature/web-swing-terminals branch from 4343e1c to 6268b33 Compare August 7, 2025 00:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants