JediTerm Documentation

repository·master·Indexed 21 days ago

https://github.com/jetbrains/jediterm

A pure Java terminal widget for embedding in IDEs, featuring VT100/Xterm emulation and support for local PTY and SSH sessions. It provides a Java Swing-based terminal panel UI and is used by JetBrains IDEs such as IntelliJ IDEA, PyCharm, and CLion. Key features include Xterm 256 color support, terminal resizing, and cross-platform local terminal support via Pty4J.

Tokens
1.1K
Snippets
4
Records
7
Agent score
75%

What's inside JediTerm

  1. Overview of JediTerm

    master
    JediTerm is a pure Java terminal widget designed to be embedded into IDEs. It provides a VT100 compatible terminal emulator and a Java Swing-based terminal panel UI. It supports terminal sessions for both SSH connections and local PTY on macOS, Linux, and Windows. The library is used by various JetBrains IDEs including PyCharm, IntelliJ IDEA, PhpStorm, WebStorm, AppCode, CLion, and Rider.
  2. Project Structure and Sub-projects

    master

    JediTerm is built using Gradle and is organized into four main sub-projects:

    • terminal: The core library containing the VT100 compatible terminal emulator and the Java Swing terminal panel UI implementation.
    • pty: The jediterm-pty.jar library which uses Pty4J to enable local PTY terminal sessions.
    • JediTerm: The standalone terminal application distributed as a .dmg for macOS.
    • (Implicitly) Build/Distribution: The project uses Gradle for the build lifecycle.
  3. Run the standalone JediTerm terminal

    master

    To run the standalone version of the JediTerm terminal from the source code, execute the provided shell or batch scripts. Alternatively, you can download the pre-built binary distribution from the GitHub Releases page. For macOS users, a standalone .dmg distribution is available.

    ./jediterm.sh
    jediterm.bat
  4. Key Features of JediTerm

    master

    JediTerm provides the following terminal capabilities:

    • Local Terminal Support: Works on Unix, Mac, and Windows using the Pty4J library.
    • Xterm Emulation: Supports Xterm emulation (passes most vttest tests).
    • Color Support: Xterm 256 colours.
    • UI Features: Scrolling, Copy/Paste, Mouse support, and Terminal tabs.
    • Resizing: Supports terminal resizing from both the client and server sides.
  5. Use TerminalDataStream for terminal data communication

    master

    The TerminalDataStream interface provides a mechanism for bidirectional character-based communication with a terminal. It supports reading individual characters, pushing characters back into the stream, and bulk reading of non-control ASCII characters for performance. Implement this interface to bridge a terminal session with a data source or buffer.

    // Example of interacting with a TerminalDataStream implementation
    void processStream(TerminalDataStream stream) throws IOException {
        char c = stream.getChar();
        stream.pushChar(c);
        
        // Bulk read non-control characters for efficiency
        String chunk = stream.readNonControlCharacters(1024);
        
        // Push a buffer of characters back into the stream
        char[] buffer = {'a', 'b', 'c'};
        stream.pushBackBuffer(buffer, 3);
    }
  6. Handle EOF in TerminalDataStream

    master

    The TerminalDataStream.EOF exception is a specialized IOException used to signal that the terminal data stream has reached the end-of-file or that the connection has been lost. When implementing or consuming a TerminalDataStream, catch this exception to gracefully handle stream termination.

    try {
        char c = stream.getChar();
    } catch (TerminalDataStream.EOF e) {
        // Handle end of stream or lost connection
    }
  7. Use CellPosition to represent terminal grid coordinates

    master

    The CellPosition class is used to represent a specific coordinate within a terminal grid. It uses a one-based indexing system for both columns (x) and rows (y).

    When instantiating CellPosition, both x and y must be greater than or equal to 1. Providing a value less than 1 will result in an IllegalArgumentException.

    // Example of creating a position at column 1, row 1
    val position = CellPosition(x = 1, y = 1)
    
    // Accessing coordinates
    println(position.x) // 1
    println(position.y) // 1
    
    // String representation
    println(position.toString()) // "column=1, row=1"