Skip to content

Terminal

Terminal management and interaction.

Terminal

Terminal(client: VSCodeClient, terminal_id: str, name: Optional[str] = None)

VS Code terminal instance.

Initialize a Terminal instance.

Parameters:

Name Type Description Default
client VSCodeClient

The VSCodeClient instance

required
terminal_id str

Unique identifier for this terminal

required
name Optional[str]

Optional name of the terminal

None
Source code in vscode_sockpuppet/terminal.py
def __init__(
    self,
    client: "VSCodeClient",
    terminal_id: str,
    name: Optional[str] = None,
):
    """
    Initialize a Terminal instance.

    Args:
        client: The VSCodeClient instance
        terminal_id: Unique identifier for this terminal
        name: Optional name of the terminal
    """
    self.client = client
    self.terminal_id = terminal_id
    self.name = name

send_text

send_text(text: str, add_new_line: bool = True) -> dict

Send text to the terminal.

Parameters:

Name Type Description Default
text str

Text to send to the terminal

required
add_new_line bool

Whether to add a new line after the text

True

Returns:

Type Description
dict

Success status

Example

terminal.send_text("echo 'Hello, World!'") terminal.send_text("cd /path/to/dir", add_new_line=True)

Source code in vscode_sockpuppet/terminal.py
def send_text(self, text: str, add_new_line: bool = True) -> dict:
    """
    Send text to the terminal.

    Args:
        text: Text to send to the terminal
        add_new_line: Whether to add a new line after the text

    Returns:
        Success status

    Example:
        terminal.send_text("echo 'Hello, World!'")
        terminal.send_text("cd /path/to/dir", add_new_line=True)
    """
    return self.client._send_request(
        "terminal.sendText",
        {
            "terminalId": self.terminal_id,
            "text": text,
            "addNewLine": add_new_line,
        },
    )

show

show(preserve_focus: bool = True) -> dict

Show the terminal in the UI.

Parameters:

Name Type Description Default
preserve_focus bool

If true, the terminal will not take focus

True

Returns:

Type Description
dict

Success status

Example

terminal.show(preserve_focus=False) # Show and focus terminal.show() # Show without taking focus

Source code in vscode_sockpuppet/terminal.py
def show(self, preserve_focus: bool = True) -> dict:
    """
    Show the terminal in the UI.

    Args:
        preserve_focus: If true, the terminal will not take focus

    Returns:
        Success status

    Example:
        terminal.show(preserve_focus=False)  # Show and focus
        terminal.show()  # Show without taking focus
    """
    return self.client._send_request(
        "terminal.show",
        {
            "terminalId": self.terminal_id,
            "preserveFocus": preserve_focus,
        },
    )

hide

hide() -> dict

Hide the terminal from the UI.

Returns:

Type Description
dict

Success status

Example

terminal.hide()

Source code in vscode_sockpuppet/terminal.py
def hide(self) -> dict:
    """
    Hide the terminal from the UI.

    Returns:
        Success status

    Example:
        terminal.hide()
    """
    return self.client._send_request(
        "terminal.hide",
        {"terminalId": self.terminal_id},
    )

dispose

dispose() -> dict

Dispose the terminal, closing it permanently.

Returns:

Type Description
dict

Success status

Example

terminal.dispose()

Source code in vscode_sockpuppet/terminal.py
def dispose(self) -> dict:
    """
    Dispose the terminal, closing it permanently.

    Returns:
        Success status

    Example:
        terminal.dispose()
    """
    return self.client._send_request(
        "terminal.dispose",
        {"terminalId": self.terminal_id},
    )

__repr__

__repr__() -> str

String representation of the terminal.

Source code in vscode_sockpuppet/terminal.py
def __repr__(self) -> str:
    """String representation of the terminal."""
    name_str = f", name={self.name!r}" if self.name else ""
    return f"Terminal(id={self.terminal_id!r}{name_str})"