Class Terminals

All Implemented Interfaces:
ContextProvider, PropertyChangeSource, Rebindable

public class Terminals extends AnahataToolkit
A toolkit for opening, driving and closing IntelliJ terminal tabs.

This is the IntelliJ port of the NetBeans NbTerminal. Where NetBeans crawls the dlight terminal container and reflects into a private Term.fireChars, IntelliJ offers first-class APIs: TerminalToolWindowManager.createLocalShellWidget(String, String) to open a shell and ShellTerminalWidget.executeCommand(String) to run a command. Opened widgets are tracked by identity id in a transient map so subsequent calls can address them; the map is rebuilt on session activation (terminals do not survive a restart).

Author:
anahata
  • Field Details

    • widgets

      private transient Map<Long, org.jetbrains.plugins.terminal.ShellTerminalWidget> widgets
      Identity-keyed registry of terminals opened by this toolkit. Transient: terminals are live UI resources that do not survive serialization.
  • Constructor Details

    • Terminals

      public Terminals()
      Constructs the Terminals toolkit (instantiated reflectively via its public no-arg constructor).
  • Method Details

    • rebind

      public void rebind()
      Rebinds the toolkit after deserialization.

      This method is called by the framework during session activation to restore transient state, reconnect listeners, or refresh cached project instances. It ensures the propertyChangeSupport is re-initialized.

      Re-initializes the transient terminal registry after deserialization.

      Specified by:
      rebind in interface Rebindable
      Overrides:
      rebind in class AnahataToolkit
    • openLocalTerminal

      public long openLocalTerminal(String title, String workingDirectory) throws AgiToolException
      Opens a new local terminal tab and returns its tracking id.
      Parameters:
      title - the tab title, or null for the default.
      workingDirectory - the initial working directory, or null for the default.
      Returns:
      the identity id used to address this terminal in later calls.
      Throws:
      AgiToolException - if no project is open.
    • typeCommand

      public String typeCommand(long terminalId, String command) throws AgiToolException
      Types a command into a tracked terminal and executes it.
      Parameters:
      terminalId - the id returned by openLocalTerminal(String, String).
      command - the command line to execute.
      Returns:
      a confirmation message.
      Throws:
      AgiToolException - if the terminal id is unknown or the command cannot be written.
    • closeTerminal

      public String closeTerminal(long terminalId) throws AgiToolException
      Closes a tracked terminal tab.
      Parameters:
      terminalId - the id returned by openLocalTerminal(String, String).
      Returns:
      a confirmation message.
      Throws:
      AgiToolException - if the terminal id is unknown.
    • firstOpenProject

      private com.intellij.openapi.project.Project firstOpenProject() throws AgiToolException
      Returns the first open project, which hosts newly created terminals.
      Returns:
      the first open project.
      Throws:
      AgiToolException - if no project is open.