### JediTermWidget Usage Example Source: https://context7.com/jetbrains/jediterm/llms.txt Demonstrates how to create, configure, start, and manage the lifecycle of a JediTermWidget within a Swing application. It shows how to attach a TtyConnector and handle session closing. ```APIDOC ## JediTermWidget - Main Embeddable Terminal Widget ### Description The `JediTermWidget` is the primary class for embedding a terminal emulator into a Swing application. It integrates the terminal model, rendering panel, scrollbar, and type-ahead manager into a single component. It provides the core API for managing the terminal session lifecycle. ### Class `com.jediterm.terminal.ui.JediTermWidget` ### Constructor `JediTermWidget(int columns, int rows, SettingsProvider settings)` - Creates a new `JediTermWidget` with the specified dimensions and settings. ### Methods - `setTtyConnector(TtyConnector ttyConnector)`: Attaches a `TtyConnector` to manage the terminal's input/output. - `start()`: Starts the terminal emulator thread and the session. - `close()`: Releases all resources associated with the widget and terminates the session. - `isSessionRunning()`: Returns `true` if the terminal session is currently active, `false` otherwise. - `getTtyConnector()`: Returns the `TtyConnector` currently associated with the widget. - `getTerminalTextBuffer()`: Accesses the terminal's screen buffer for reading. - `getTerminalPanel()`: Accesses the underlying Swing `TerminalPanel`. - `requestFocus()`: Sets focus to the terminal widget. ### Lifecycle Listener - `addListener(WidgetListener listener)`: Adds a listener that is called when the terminal session ends. The listener typically calls `widget.close()` to clean up resources. ``` -------------------------------- ### Embed JediTerm Widget in Swing Application Source: https://context7.com/jetbrains/jediterm/llms.txt Use this snippet to create and display a JediTerm widget within a Swing JFrame. It initializes the widget with specified dimensions and settings, attaches a TtyConnector, starts the terminal session, and handles window closing events to ensure proper resource cleanup. ```java import com.jediterm.terminal.TtyConnector; import com.jediterm.terminal.ui.JediTermWidget; import com.jediterm.terminal.ui.settings.DefaultSettingsProvider; import javax.swing.*; public class EmbedExample { public static void main(String[] args) { SwingUtilities.invokeLater(() -> { // Create widget: 80 columns × 24 rows with default settings JediTermWidget widget = new JediTermWidget(80, 24, new DefaultSettingsProvider()); // Attach a TtyConnector (PTY shell shown below) widget.setTtyConnector(createShellConnector()); // Start the emulator thread widget.start(); // Add lifecycle listener – called when the session ends widget.addListener(w -> { w.close(); // release all resources SwingUtilities.invokeLater(() -> System.exit(0)); }); JFrame frame = new JFrame("My Terminal"); frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); frame.addWindowListener(new java.awt.event.WindowAdapter() { @Override public void windowClosing(java.awt.event.WindowEvent e) { widget.getTtyConnector().close(); // kill the process } }); frame.setContentPane(widget); frame.pack(); frame.setVisible(true); }); } // Check widget state static void checkState(JediTermWidget widget) { boolean running = widget.isSessionRunning(); // true while emulator runs TtyConnector conn = widget.getTtyConnector(); // access underlying connector widget.getTerminalTextBuffer(); // read the screen buffer widget.getTerminalPanel(); // access the Swing panel widget.requestFocus(); // focus the terminal } } ``` -------------------------------- ### Create Hyperlink Styles in JediTerm Source: https://context7.com/jetbrains/jediterm/llms.txt Demonstrates creating basic, always-underlined, and rich hyperlinks using `HyperlinkStyle` and `LinkInfoEx`. Use `LinkInfoEx.Builder` for advanced features like hover callbacks and popup menus. ```java import com.jediterm.terminal.HyperlinkStyle; import com.jediterm.terminal.TerminalColor; import com.jediterm.terminal.TextStyle; import com.jediterm.terminal.model.hyperlinks.LinkInfo; import com.jediterm.terminal.ui.hyperlinks.LinkInfoEx; // Basic link: inherit colors from previous style, show underline on hover TextStyle prevStyle = new TextStyle(TerminalColor.rgb(100, 149, 237), TerminalColor.index(0)); LinkInfo link = new LinkInfo(() -> System.out.println("Navigating to link!")); HyperlinkStyle hoverLink = new HyperlinkStyle(prevStyle, link); // Always-underlined link with explicit colors HyperlinkStyle alwaysLink = new HyperlinkStyle( TerminalColor.rgb(0, 102, 204), TerminalColor.index(0), link, HyperlinkStyle.HighlightMode.ALWAYS, prevStyle ); // Rich link with hover callbacks and right-click menu (Swing-specific) LinkInfo richLink = new LinkInfoEx.Builder() .setNavigateCallback(() -> openBrowser("https://example.com")) .setHoverConsumer(new LinkInfoEx.HoverConsumer() { public void onMouseEntered(javax.swing.JComponent host, java.awt.Rectangle bounds) { showTooltip(host, bounds); } public void onMouseExited() { hideTooltip(); } }) .setPopupMenuGroupProvider(event -> List.of(/* TerminalAction items */)) .build(); ``` ```java // Register a filter so the widget automatically linkifies text patterns widget.addHyperlinkFilter(info -> { String text = info.getText(); if (text.startsWith("https://")) { return new LinkResult(new LinkResultItem( new LinkInfo(() -> openBrowser(text)), 0, text.length())); } return null; // no match }); ``` -------------------------------- ### Customize JediTerm Settings Source: https://context7.com/jetbrains/jediterm/llms.txt Extends `DefaultSettingsProvider` to customize terminal appearance and behavior, including font, colors, buffer size, and hyperlink highlighting. Override methods to tailor specific settings. ```java import com.jediterm.terminal.HyperlinkStyle; import com.jediterm.terminal.TerminalColor; import com.jediterm.terminal.TextStyle; import com.jediterm.terminal.emulator.ColorPalette; import com.jediterm.terminal.emulator.ColorPaletteImpl; import com.jediterm.terminal.model.TerminalTypeAheadSettings; import com.jediterm.terminal.ui.settings.DefaultSettingsProvider; import org.jetbrains.annotations.NotNull; import java.awt.*; public class MySettings extends DefaultSettingsProvider { @Override public Font getTerminalFont() { return new Font("JetBrains Mono", Font.PLAIN, (int) getTerminalFontSize()); } @Override public float getTerminalFontSize() { return 15.0f; } @Override public float getLineSpacing() { return 1.2f; } @Override public @NotNull TerminalColor getDefaultForeground() { return TerminalColor.rgb(204, 204, 204); // light grey text } @Override public @NotNull TerminalColor getDefaultBackground() { return TerminalColor.rgb(30, 30, 30); // dark background } @Override public ColorPalette getTerminalColorPalette() { return ColorPaletteImpl.XTERM_PALETTE; // or WINDOWS_PALETTE } @Override public int getBufferMaxLinesCount() { return 10_000; } @Override public boolean copyOnSelect() { return true; } // X11-style copy @Override public boolean scrollToBottomOnTyping() { return true; } @Override public HyperlinkStyle.HighlightMode getHyperlinkHighlightingMode() { return HyperlinkStyle.HighlightMode.HOVER; } @Override public @NotNull TerminalTypeAheadSettings getTypeAheadSettings() { // Enable predictive echo with 80ms latency threshold return new TerminalTypeAheadSettings(true, 80); } } ``` -------------------------------- ### TerminalStarter Source: https://context7.com/jetbrains/jediterm/llms.txt Manages the VT100 emulator loop on a background thread, routing data from the TtyConnector into the JediTerminal model and handling resize coordination. ```APIDOC ## TerminalStarter ### Description Runs the VT100 emulator loop on a background thread, routing data from the `TtyConnector` into the `JediTerminal` model. Manages resize coordination (debounced to avoid race conditions between screen buffer and process), key-byte forwarding through `sendBytes`/`sendString`, and graceful stop. Normally created internally by `JediTermWidget`, but can be used directly for headless or custom rendering scenarios. ### Methods #### `postResize(TermSize size, RequestOrigin origin)` Resizes the terminal. Updates the terminal model and schedules a PTY resize. #### `sendBytes(byte[] bytes, boolean userInput)` Sends raw bytes to the connected process. `userInput` indicates if the bytes should be fed through the type-ahead manager. #### `sendString(String string, boolean userInput)` Sends a string to the connected process. `userInput` indicates if the string should be fed through the type-ahead manager. #### `requestEmulatorStop()` Stops the emulator loop without closing the connected process. #### `isLastSentByteEscape()` Checks if the last sent byte was an ESC character. ### Usage ```java import com.jediterm.terminal.TerminalStarter; import com.jediterm.terminal.RequestOrigin; import com.jediterm.core.util.TermSize; // Programmatic resize: updates terminal model + schedules PTY resize TerminalStarter starter = widget.getTerminalStarter(); // via JediTermWidget (deprecated getter) // Preferred: use the protected doWithTerminalStarter callback // starter.postResize(new TermSize(200, 50), RequestOrigin.User); // Send raw bytes to the connected process (e.g. simulate pressing Ctrl+C) byte[] ctrlC = new byte[]{3}; starter.sendBytes(ctrlC, true); // userInput=true feeds the type-ahead manager // Send a string starter.sendString("ls -la\n", true); // Stop the emulator loop without closing the process starter.requestEmulatorStop(); // Check if last sent byte was ESC (useful for key-sequence handling) boolean lastWasEsc = starter.isLastSentByteEscape(); ``` ``` -------------------------------- ### Create and Modify TextStyle Source: https://context7.com/jetbrains/jediterm/llms.txt Represents text rendering attributes including foreground color, background color, and option flags. Use the builder pattern for incremental construction. ```java import com.jediterm.terminal.TextStyle; import com.jediterm.terminal.TerminalColor; import java.util.EnumSet; // Direct construction TextStyle redOnBlack = new TextStyle( TerminalColor.rgb(255, 80, 80), // bright red fg TerminalColor.index(0) // palette index 0 = black bg ); // Builder: start from EMPTY, add options TextStyle boldUnderline = new TextStyle.Builder() .setForeground(TerminalColor.WHITE) .setBackground(TerminalColor.rgb(30, 30, 30)) .setOption(TextStyle.Option.BOLD, true) .setOption(TextStyle.Option.UNDERLINED, true) .build(); // Derive a variant: copy then modify TextStyle dimVariant = boldUnderline.toBuilder() .setOption(TextStyle.Option.DIM, true) .setOption(TextStyle.Option.BOLD, false) .build(); System.out.println(boldUnderline.hasOption(TextStyle.Option.BOLD)); // true System.out.println(boldUnderline.getForeground()); // TerminalColor(WHITE) System.out.println(TextStyle.EMPTY.equals(new TextStyle())); // true ``` -------------------------------- ### ColorPalette / ColorPaletteImpl Source: https://context7.com/jetbrains/jediterm/llms.txt Abstract base class for managing 16-color and 256-color palettes. It maps color indices to foreground/background `Color` values, supporting xterm-256 color cube and grayscale ramp. ```APIDOC ## ColorPalette / ColorPaletteImpl — 16-color and 256-color palette Abstract base mapping 0–15 color indices to foreground/background `Color` values, with built-in support for xterm-256 color cube (indices 16–231) and grayscale ramp (232–255). Two concrete palettes are provided: `XTERM_PALETTE` and `WINDOWS_PALETTE`. ```java import com.jediterm.terminal.TerminalColor; import com.jediterm.terminal.emulator.ColorPalette; import com.jediterm.terminal.emulator.ColorPaletteImpl; import com.jediterm.core.Color; ColorPalette palette = ColorPaletteImpl.XTERM_PALETTE; // Resolve indexed color to RGB for rendering Color fg = palette.getForeground(TerminalColor.index(1)); // standard red Color bg = palette.getBackground(TerminalColor.index(2)); // standard green // Resolve 256-color index (>15 is handled via static utility) TerminalColor orange256 = ColorPalette.getIndexedTerminalColor(208); // xterm orange // Custom palette: subclass ColorPalette and override the two abstract methods ColorPalette solarized = new ColorPalette() { private final Color[] FG = { /* 16 solarized foreground colors */ }; private final Color[] BG = { /* 16 solarized background colors */ }; @Override protected Color getForegroundByColorIndex(int index) { return FG[index]; } @Override protected Color getBackgroundByColorIndex(int index) { return BG[index]; } }; ``` ``` -------------------------------- ### Minimal No-Op TerminalDisplay for Headless Use Source: https://context7.com/jetbrains/jediterm/llms.txt Implement the TerminalDisplay interface for headless rendering or testing. This minimal implementation provides no-op methods for all interface functions. ```java import com.jediterm.core.Color; import com.jediterm.core.util.TermSize; import com.jediterm.terminal.CursorShape; import com.jediterm.terminal.RequestOrigin; import com.jediterm.terminal.TerminalDisplay; import com.jediterm.terminal.emulator.mouse.MouseFormat; import com.jediterm.terminal.emulator.mouse.MouseMode; import com.jediterm.terminal.model.TerminalSelection; // Minimal no-op display for headless use / testing TerminalDisplay headless = new TerminalDisplay() { @Override public void setCursor(int x, int y) {} @Override public void setCursorShape(CursorShape shape) {} @Override public void beep() { System.out.println("[BEEP]"); } @Override public void scrollArea(int top, int size, int dy) {} @Override public void setCursorVisible(boolean visible) {} @Override public void useAlternateScreenBuffer(boolean alt) {} @Override public String getWindowTitle() { return "Headless"; } @Override public void setWindowTitle(String title) {} @Override public TerminalSelection getSelection() { return null; } @Override public void terminalMouseModeSet(MouseMode mode) {} @Override public void setMouseFormat(MouseFormat format) {} @Override public boolean ambiguousCharsAreDoubleWidth() { return false; } @Override public void onResize(TermSize newSize, RequestOrigin origin) { System.out.println("Resize: " + newSize); } }; ``` -------------------------------- ### Create Local Shell Connector with Pty4J Source: https://context7.com/jetbrains/jediterm/llms.txt Wraps a Pty4J PtyProcess to provide TtyConnector functionality for local shell sessions. Handles PTY window-size signalling. ```java import com.jediterm.pty.PtyProcessTtyConnector; import com.jediterm.terminal.TtyConnector; import com.pty4j.PtyProcess; import com.pty4j.PtyProcessBuilder; import java.nio.charset.StandardCharsets; import java.util.HashMap; import java.util.Map; TtyConnector createShellConnector() throws Exception { Map envs = new HashMap<>(System.getenv()); String[] command; String os = System.getProperty("os.name").toLowerCase(); if (os.contains("win")) { command = new String[]{"cmd.exe"}; } else { command = new String[]{"/bin/bash", "--login"}; envs.put("TERM", "xterm-256color"); // enable 256-color support } PtyProcess process = new PtyProcessBuilder() .setCommand(command) .setEnvironment(envs) .start(); // PtyProcessTtyConnector bridges PtyProcess to TtyConnector return new PtyProcessTtyConnector(process, StandardCharsets.UTF_8); } ``` -------------------------------- ### Configure Terminal Type-Ahead Manager Source: https://context7.com/jetbrains/jediterm/llms.txt Optimize input echoing for low latency by configuring the TerminalTypeAheadManager. Settings like enabled status and latency threshold are managed via SettingsProvider. The manager can be accessed for monitoring or testing, and predictions can be manually flushed or cleared on resize. ```java import com.jediterm.core.typeahead.TerminalTypeAheadManager; import com.jediterm.terminal.model.TerminalTypeAheadSettings; // Configuration is done through SettingsProvider.getTypeAheadSettings() TerminalTypeAheadSettings settings = new TerminalTypeAheadSettings( /* enabled= */ true, /* latencyThresholdMs= */ 100 ); // The manager is created automatically inside JediTermWidget. // Access it for monitoring or testing: TerminalTypeAheadManager mgr = widget.getTypeAheadManager(); // Manually flush predictions (e.g., on explicit paste): mgr.debounce(); // Notify about a resize (clears all predictions): mgr.onResize(); // Convert raw key bytes to TypeAheadEvents for unit testing: byte[] leftArrow = {27, '[', 'D'}; var events = TerminalTypeAheadManager.TypeAheadEvent.fromByteArray(leftArrow); // events.get(0).myEventType == TypeAheadEvent.EventType.LeftArrow ``` -------------------------------- ### Create and Use TermSize Source: https://context7.com/jetbrains/jediterm/llms.txt Represents terminal grid size in columns and rows. Used for passing size information to various terminal operations. ```java import com.jediterm.core.util.TermSize; TermSize size = new TermSize(220, 50); System.out.println(size.getColumns()); // 220 System.out.println(size.getRows()); // 50 System.out.println(size); // "columns=220, rows=50" // Equality is value-based TermSize a = new TermSize(80, 24); TermSize b = new TermSize(80, 24); assert a.equals(b); assert a.hashCode() == b.hashCode(); // Trigger a programmatic resize after session start widget.getTerminalPanel().getTerminalStarter() .postResize(new TermSize(132, 43), RequestOrigin.User); ``` -------------------------------- ### Manage Terminal Emulator Thread with TerminalStarter Source: https://context7.com/jetbrains/jediterm/llms.txt Manages the VT100 emulator loop on a background thread. Use for programmatic resizing, sending raw bytes or strings, and stopping the emulator loop. ```java import com.jediterm.terminal.TerminalStarter; import com.jediterm.terminal.RequestOrigin; import com.jediterm.core.util.TermSize; // Programmatic resize: updates terminal model + schedules PTY resize TerminalStarter starter = widget.getTerminalStarter(); // via JediTermWidget (deprecated getter) // Preferred: use the protected doWithTerminalStarter callback // starter.postResize(new TermSize(200, 50), RequestOrigin.User); // Send raw bytes to the connected process (e.g. simulate pressing Ctrl+C) byte[] ctrlC = new byte[]{3}; starter.sendBytes(ctrlC, true); // userInput=true feeds the type-ahead manager // Send a string starter.sendString("ls -la\n", true); // Stop the emulator loop without closing the process starter.requestEmulatorStop(); // Check if last sent byte was ESC (useful for key-sequence handling) boolean lastWasEsc = starter.isLastSentByteEscape(); ``` -------------------------------- ### Simple Process Connector for Standard Java Processes Source: https://context7.com/jetbrains/jediterm/llms.txt Extends ProcessTtyConnector for processes launched via ProcessBuilder. Does not support PTY resizing. ```java import com.jediterm.core.util.TermSize; import com.jediterm.terminal.ProcessTtyConnector; import java.nio.charset.StandardCharsets; import java.util.List; public class SimpleProcessConnector extends ProcessTtyConnector { public SimpleProcessConnector(Process process) { super(process, StandardCharsets.UTF_8, List.of("/bin/sh", "-c", "cat")); } @Override public String getName() { return "SimpleProcess"; } @Override public void resize(TermSize termSize) { // No PTY – resize is a no-op for plain Process } @Override public boolean isConnected() { return getProcess().isAlive(); } } // Usage Process process = new ProcessBuilder("/bin/sh", "-c", "echo hello && sleep 5").start(); SimpleProcessConnector connector = new SimpleProcessConnector(process); JediTermWidget widget = new JediTermWidget(80, 24, new DefaultSettingsProvider()); widget.setTtyConnector(connector); widget.start(); ``` -------------------------------- ### Minimal Custom TtyConnector with Piped Streams Source: https://context7.com/jetbrains/jediterm/llms.txt Implement TtyConnector using piped streams for testing or scripting. Requires a PipedWriter to send data. ```java import com.jediterm.core.util.TermSize; import com.jediterm.terminal.TtyConnector; import java.io.*; // Minimal custom TtyConnector backed by piped streams (useful for testing / scripting) public class PipedTtyConnector implements TtyConnector { private final PipedReader reader; public PipedTtyConnector(PipedWriter writer) throws IOException { this.reader = new PipedReader(writer); } @Override public int read(char[] buf, int offset, int length) throws IOException { return reader.read(buf, offset, length); } @Override public void write(byte[] bytes) throws IOException { /* send to remote */ } @Override public void write(String string) throws IOException { /* send to remote */ } @Override public boolean isConnected() { return true; } @Override public boolean ready() throws IOException { return reader.ready(); } @Override public int waitFor() { return 0; } @Override public String getName() { return "Piped"; } @Override public void close() {} // Called when the terminal viewport is resized @Override public void resize(TermSize termSize) { System.out.println("New size: " + termSize.getColumns() + "x" + termSize.getRows()); } } // Usage: inject ANSI escape sequences from a writer PipedWriter writer = new PipedWriter(); PipedTtyConnector connector = new PipedTtyConnector(writer); JediTermWidget widget = new JediTermWidget(80, 24, new DefaultSettingsProvider()); widget.setTtyConnector(connector); widget.start(); char ESC = 27; writer.write(ESC + "%G"); // switch to UTF-8 writer.write(ESC + "[31m"); // red foreground writer.write("Error text\r\n"); writer.write(ESC + "[0m"); // reset writer.close(); ``` -------------------------------- ### JediTerm Color Palette Management Source: https://context7.com/jetbrains/jediterm/llms.txt Utilize ColorPalette and ColorPaletteImpl to manage terminal colors, supporting 16-color, 256-color, and custom palettes. Resolve indexed colors to RGB values for rendering. Subclass ColorPalette to implement custom color mappings. ```java import com.jediterm.terminal.TerminalColor; import com.jediterm.terminal.emulator.ColorPalette; import com.jediterm.terminal.emulator.ColorPaletteImpl; import com.jediterm.core.Color; ColorPalette palette = ColorPaletteImpl.XTERM_PALETTE; // Resolve indexed color to RGB for rendering Color fg = palette.getForeground(TerminalColor.index(1)); // standard red Color bg = palette.getBackground(TerminalColor.index(2)); // standard green // Resolve 256-color index (>15 is handled via static utility) TerminalColor orange256 = ColorPalette.getIndexedTerminalColor(208); // xterm orange // Custom palette: subclass ColorPalette and override the two abstract methods ColorPalette solarized = new ColorPalette() { private final Color[] FG = { /* 16 solarized foreground colors */ }; private final Color[] BG = { /* 16 solarized background colors */ }; @Override protected Color getForegroundByColorIndex(int index) { return FG[index]; } @Override protected Color getBackgroundByColorIndex(int index) { return BG[index]; } }; ``` -------------------------------- ### TextStyle and TextStyle.Builder Source: https://context7.com/jetbrains/jediterm/llms.txt Represents the complete rendering style for a cell, including foreground color, background color, and text style options. The builder pattern facilitates incremental construction. ```APIDOC ## TextStyle and TextStyle.Builder ### Description Represents the complete rendering style for a cell: foreground color, background color, and a set of `Option` flags (BOLD, ITALIC, UNDERLINED, DIM, INVERSE, SLOW_BLINK, RAPID_BLINK, HIDDEN). The builder pattern allows incremental construction; the immutable style is shared across buffer cells. ### Usage ```java import com.jediterm.terminal.TextStyle; import com.jediterm.terminal.TerminalColor; import java.util.EnumSet; // Direct construction TextStyle redOnBlack = new TextStyle( TerminalColor.rgb(255, 80, 80), // bright red fg TerminalColor.index(0) // palette index 0 = black bg ); // Builder: start from EMPTY, add options TextStyle boldUnderline = new TextStyle.Builder() .setForeground(TerminalColor.WHITE) .setBackground(TerminalColor.rgb(30, 30, 30)) .setOption(TextStyle.Option.BOLD, true) .setOption(TextStyle.Option.UNDERLINED, true) .build(); // Derive a variant: copy then modify TextStyle dimVariant = boldUnderline.toBuilder() .setOption(TextStyle.Option.DIM, true) .setOption(TextStyle.Option.BOLD, false) .build(); System.out.println(boldUnderline.hasOption(TextStyle.Option.BOLD)); // true System.out.println(boldUnderline.getForeground()); // TerminalColor(WHITE) System.out.println(TextStyle.EMPTY.equals(new TextStyle())); // true ``` ``` -------------------------------- ### Represent Colors with TerminalColor Source: https://context7.com/jetbrains/jediterm/llms.txt Abstracts colors using palette indices, direct RGB values, or dynamic suppliers. Use static factories for preferred construction. ```java import com.jediterm.terminal.TerminalColor; import com.jediterm.core.Color; // Named palette entries TerminalColor black = TerminalColor.BLACK; // index(0) TerminalColor white = TerminalColor.WHITE; // index(15) // Palette index (0–15 basic, 16–231 xterm 6×6×6 cube, 232–255 grayscale) TerminalColor green256 = TerminalColor.index(46); // bright green in xterm-256 // True-color RGB TerminalColor coral = TerminalColor.rgb(255, 127, 80); // Dynamic — computed at paint time (useful for theme-reactive colors) TerminalColor themed = new TerminalColor(() -> new Color(0, 120, 212)); // Check type before calling toColor() if (!green256.isIndexed()) { Color actual = green256.toColor(); // would throw if indexed } // Null-safe factory TerminalColor maybeNull = TerminalColor.color(someNullableAwtColor); // null → null ``` -------------------------------- ### TerminalColor Source: https://context7.com/jetbrains/jediterm/llms.txt An abstraction for colors, supporting palette indices, RGB values, or dynamic suppliers. Provides static factories for easy creation. ```APIDOC ## TerminalColor ### Description Wraps a color as either a palette index (0–255 xterm), a direct RGB `Color`, or a dynamic supplier. The `isIndexed()` / `toColor()` / `getColorIndex()` accessors distinguish between them. Static factories `index(n)`, `rgb(r,g,b)`, and `color(Color)` are the preferred construction paths. ### Usage ```java import com.jediterm.terminal.TerminalColor; import com.jediterm.core.Color; // Named palette entries TerminalColor black = TerminalColor.BLACK; // index(0) TerminalColor white = TerminalColor.WHITE; // index(15) // Palette index (0–15 basic, 16–231 xterm 6×6×6 cube, 232–255 grayscale) TerminalColor green256 = TerminalColor.index(46); // bright green in xterm-256 // True-color RGB TerminalColor coral = TerminalColor.rgb(255, 127, 80); // Dynamic — computed at paint time (useful for theme-reactive colors) TerminalColor themed = new TerminalColor(() -> new Color(0, 120, 212)); // Check type before calling toColor() if (!green256.isIndexed()) { Color actual = green256.toColor(); // would throw if indexed } // Null-safe factory TerminalColor maybeNull = TerminalColor.color(someNullableAwtColor); // null → null ``` ``` -------------------------------- ### TermSize Source: https://context7.com/jetbrains/jediterm/llms.txt Represents the terminal grid size in columns and rows. It's an immutable value type used for passing terminal dimensions. ```APIDOC ## TermSize ### Description Immutable value type representing the terminal grid size in columns and rows. Used everywhere that a size must be passed: `TtyConnector.resize`, `TerminalStarter.postResize`, and widget construction. ### Usage ```java import com.jediterm.core.util.TermSize; TermSize size = new TermSize(220, 50); System.out.println(size.getColumns()); // 220 System.out.println(size.getRows()); // 50 System.out.println(size); // "columns=220, rows=50" // Equality is value-based TermSize a = new TermSize(80, 24); TermSize b = new TermSize(80, 24); assert a.equals(b); assert a.hashCode() == b.hashCode(); // Trigger a programmatic resize after session start widget.getTerminalPanel().getTerminalStarter() .postResize(new TermSize(132, 43), RequestOrigin.User); ``` ``` -------------------------------- ### Set Cursor Shape in JediTerm Source: https://context7.com/jetbrains/jediterm/llms.txt Configure the cursor's appearance using the CursorShape enum. This can be set programmatically on the terminal panel or controlled by escape sequences from the connected process. Available shapes include blinking and steady block, underline, and vertical bar. ```java import com.jediterm.terminal.CursorShape; // Set cursor shape before starting the session widget.getTerminalPanel().setDefaultCursorShape(CursorShape.BLINK_UNDERLINE); // All available shapes: // CursorShape.BLINK_BLOCK – classic blinking block // CursorShape.STEADY_BLOCK – non-blinking block // CursorShape.BLINK_UNDERLINE – blinking underline // CursorShape.STEADY_UNDERLINE – non-blinking underline // CursorShape.BLINK_VERTICAL_BAR – blinking bar (modern default) // CursorShape.STEADY_VERTICAL_BAR – non-blinking bar // Check if shape is blinking boolean blinks = CursorShape.BLINK_VERTICAL_BAR.isBlinking(); // true boolean steady = CursorShape.STEADY_BLOCK.isBlinking(); // false ``` -------------------------------- ### TerminalWidgetListener for Session End Callbacks Source: https://context7.com/jetbrains/jediterm/llms.txt Implement the TerminalWidgetListener interface to receive callbacks when all sessions within a JediTermWidget have closed. This is useful for releasing resources or restarting sessions. ```java import com.jediterm.terminal.ui.TerminalWidgetListener; // Lambda form (single abstract method) TerminalWidgetListener listener = terminalWidget -> { System.out.println("Session ended"); terminalWidget.close(); // release resources }; widget.addListener(listener); // Remove when no longer needed widget.removeListener(listener); ``` -------------------------------- ### TerminalTypeAheadManager Source: https://context7.com/jetbrains/jediterm/llms.txt Manages predictive local echo for sub-latency keypress echoing by predicting shell responses before they arrive. It automatically activates based on network latency and manages a prediction queue. ```APIDOC ## TerminalTypeAheadManager — predictive local echo Provides sub-latency keypress echoing by predicting how the shell will respond before the remote response arrives. Automatically activates when median round-trip latency exceeds the configured threshold and deactivates when latency falls below 50% of the threshold. Manages a prediction queue keyed on `TypeAheadEvent` types (Character, Backspace, LeftArrow, RightArrow, Delete, Home, End, …). ```java import com.jediterm.core.typeahead.TerminalTypeAheadManager; import com.jediterm.terminal.model.TerminalTypeAheadSettings; // Configuration is done through SettingsProvider.getTypeAheadSettings() TerminalTypeAheadSettings settings = new TerminalTypeAheadSettings( /* enabled= */ true, /* latencyThresholdMs= */ 100 ); // The manager is created automatically inside JediTermWidget. // Access it for monitoring or testing: TerminalTypeAheadManager mgr = widget.getTypeAheadManager(); // Manually flush predictions (e.g., on explicit paste): mgr.debounce(); // Notify about a resize (clears all predictions): mgr.onResize(); // Convert raw key bytes to TypeAheadEvents for unit testing: byte[] leftArrow = {27, '[', 'D'}; var events = TerminalTypeAheadManager.TypeAheadEvent.fromByteArray(leftArrow); // events.get(0).myEventType == TypeAheadEvent.EventType.LeftArrow ``` ``` -------------------------------- ### CursorShape Enumeration Source: https://context7.com/jetbrains/jediterm/llms.txt Defines the six cursor shapes supported by DECSCUSR (VT510). These can be set programmatically on the terminal panel or controlled via escape sequences from the connected process. ```APIDOC ## CursorShape — cursor style enumeration Enum of the six cursor shapes defined by DECSCUSR (VT510). Set programmatically on the terminal panel or driven by escape sequences from the connected process. ```java import com.jediterm.terminal.CursorShape; // Set cursor shape before starting the session widget.getTerminalPanel().setDefaultCursorShape(CursorShape.BLINK_UNDERLINE); // All available shapes: // CursorShape.BLINK_BLOCK – classic blinking block // CursorShape.STEADY_BLOCK – non-blinking block // CursorShape.BLINK_UNDERLINE – blinking underline // CursorShape.STEADY_UNDERLINE – non-blinking underline // CursorShape.BLINK_VERTICAL_BAR – blinking bar (modern default) // CursorShape.STEADY_VERTICAL_BAR – non-blinking bar // Check if shape is blinking boolean blinks = CursorShape.BLINK_VERTICAL_BAR.isBlinking(); // true boolean steady = CursorShape.STEADY_BLOCK.isBlinking(); // false ``` ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.