Class TerminalTab

All Implemented Interfaces:
ContextProvider, PropertyChangeSource, Rebindable

public class TerminalTab extends BasicContextProvider
A hierarchical context provider representing an active terminal tab in NetBeans. Each tab actively participates in the RAG pipeline by capturing its text scrollback buffer thread-safely off the EDT and rendering it via a local, fully serializable TextViewportSettings.
Author:
anahata
  • Field Details

    • viewportSettings

      private final TextViewportSettings viewportSettings
      Persistent viewport configuration for this terminal tab.
    • viewport

      private transient TextViewport viewport
      In-memory text viewport engine for line slicing, tailing, and grepping.
    • term

      private transient org.netbeans.lib.terminalemulator.Term term
      The active rendering JComponent. Marked transient as Swing UI elements cannot be serialized directly.
  • Constructor Details

    • TerminalTab

      public TerminalTab(long tabId, String name, org.netbeans.lib.terminalemulator.Term term)
      Constructs a new TerminalTab context provider.
      Parameters:
      tabId - The transient identity hashcode of the Term component.
      name - The display title of the tab.
      term - The active Swing Term component.
  • Method Details

    • getViewport

      private TextViewport getViewport()
    • getTabId

      public long getTabId()
      Resolves the transient identity hash code of the Term component.
      Returns:
      The identity hash code, or -1 if the Term is null.
    • populateMessage

      public void populateMessage(RagMessage ragMessage) throws Exception
      Populates the given RagMessage with dynamic, just-in-time context parts. These parts are appended to the end of the user's prompt (RAG).

      Reconstructs the terminal's text buffer completely thread-safe and off the EDT, processes it via our local viewports, and injects a formatted Markdown code block directly into the RAG prompt.

      Parameters:
      ragMessage - The message to be augmented with context.
      Throws:
      Exception - if an error occurs during context generation.
    • getTermContent

      public String getTermContent()
      Safely reads the terminal scrollback buffer completely off the EDT thread using raw line getters.
      Returns:
      The reconstructed terminal buffer as a String.
    • selectTab

      public void selectTab()
      Activates the TerminalContainerTopComponent and selects this tab in its parent tabbed container.
    • typeCommand

      Types a command sequence into the terminal via reflection on the Term instance.

      Automatically activates and selects this tab before sending the command, ensuring it is brought into focus in the IDE layout.

      Parameters:
      command - The command sequence to execute.
      Throws:
      IllegalAccessException - If access to the fireChars method is denied.
      InvocationTargetException - If invoking the fireChars method throws an exception.
      NoSuchMethodException - If the fireChars method cannot be found on Term.