Terminus for Sublime Text

repository·master·Indexed 23 days ago

https://github.com/randy3k/terminus

A cross-platform terminal emulator for Sublime Text that supports unicode, 256 colors, and imgcat. It provides a real terminal experience directly within the editor, including a Python API for programmatic control, a drop-in replacement for the default build system via terminus_exec, and a comprehensive set of commands for terminal management, shell execution, and UI rendering.

Tokens
2K
Snippets
6
Records
10
Agent score
31%

What's inside Terminus

  1. Add Terminus commands to the Command Palette

    master

    You can add custom Terminus commands to your Command Palette by running Preferences: Terminus Command Palette. This allows you to trigger specific shell configurations or custom commands (like ipython) with a title and specific working directory.

    [
        {
            "caption": "Terminus: Open iPython",
            "command": "terminus_open",
            "args": { "cmd": "ipython", "cwd": "${file_path:${folder}}", "title": "iPython" }
        }
    ]
  2. Use Terminus as a Sublime Text Build System

    master

    Terminus provides terminus_exec as a drop-in replacement for the default exec target. It accepts the same arguments as terminus_open. To allow users to cancel a running build (e.g., via ctrl+c), use the terminus_cancel_build command assigned to the cancel key.

    You can define these in your project settings or in a .sublime-build file. You can use either cmd or shell_cmd (which invokes bash on Unix and cmd.exe on Windows).

    {
        "target": "terminus_exec",
        "cancel": "terminus_cancel_build",
        "shell_cmd": "python helloworld.py",
        "working_dir": "$folder"
    }
  3. Configure User Key Bindings for Terminus

    master

    You can customize how you interact with Terminus by adding key bindings. To edit them, run Preferences: Terminus Key Bindings.

    Common useful bindings include:

    • Toggle terminal panel: Uses toggle_terminus_panel.
    • Open terminal at current file directory: Uses terminus_open with the cwd argument set to ${file_path:${folder}}.
    • Close terminal: Use terminus_close with a context check for terminus_view to allow using ctrl+w specifically for terminals.
    // Toggle terminal panel
    [
        { "keys": ["alt+`"], "command": "toggle_terminus_panel" }
    ]
    
    // Open terminal at current file directory
    [
        { 
            "keys": ["ctrl+alt+t"], 
            "command": "terminus_open", 
            "args": { "cwd": "${file_path:${folder}}" } 
        }
    ]
    
    // Close terminal with ctrl+w (only when in a terminus view)
    {
        "keys": ["ctrl+w"],
        "command": "terminus_close",
        "context": [{ "key": "terminus_view" }]
    }
  4. Enable Alt-Left/Right word movement in Bash and Zsh

    master

    To enable standard Unix word movement (Alt+Left/Right) within Terminus, add the following snippets to your shell configuration files. This checks if the terminal program is Terminus-Sublime before applying the bindings.

    # Add to .bash_profile or .bashrc
    if [ "$TERM_PROGRAM" == "Terminus-Sublime" ]; then
        bind '"\e[1;3C": forward-word'
        bind '"\e[1;3D": backward-word'
    fi
    
    # Add to .zshrc
    if [ "$TERM_PROGRAM" = "Terminus-Sublime" ]; then
        bindkey "\e[1;3C" forward-word
        bindkey "\e[1;3D" backward-word
    fi
  5. Troubleshoot Terminus memory and color issues

    master

    Memory Usage

    Terminus may consume significant memory due to Sublime Text's infinite undo stack. If memory usage becomes too high, run Terminus: Reset to release it. (Note: This issue is addressed in Sublime Text >= 4114 and Terminus v0.3.20).

    Color Loss

    Colors in the scrollback history may be lost when maximizing or minimizing the terminal panel. This is a known limitation.

    Terminal Panel Background (DA UI)

    If using DA UI and the terminal panel has incorrect background colors, adjust the following settings in DA UI: Theme Settings:

    • panel_background_color
    • panel_text_output_background_color (to keep Find/Replace panels unchanged)
    {
        "panel_background_color": "$background_color"
    }
  6. Use the Terminus Python API

    master

    Terminus can be controlled via the Sublime Text Python API using window.run_command.

    Open a terminal with terminus_open

    Use this to programmatically launch shells with specific configurations, environments, or tags.

    Send text with terminus_send_string

    Send strings (including newlines) to a specific terminal using its tag.

    Identify and target specific terminals

    Use view.settings().get("terminus_view.tag") to retrieve the tag of a view. You can then use this tag in key bindings to target specific terminals.

    # Open a terminal
    window.run_command(
        "terminus_open", {
            "cmd": None,
            "shell_cmd": None,
            "cwd": None,
            "env": {},
            "title": "My Terminal",
            "tag": "MY_TAG",
            "auto_close": False
        }
    )
    
    # Send text to a specific tagged terminal
    window.run_command(
        "terminus_send_string", 
        {
            "string": "ls\n",
            "tag": "MY_TAG"
        }
    )
  7. Terminus Sublime Text Commands

    master

    Terminus provides a wide range of Sublime Text commands to manage terminal views, shell execution, and terminal-specific interactions. These commands can be invoked via the Command Palette, Key Bindings, or the Context Menu.

    Terminal Management

    • terminus_open: Opens a new terminal view.
    • terminus_activate: Activates a terminal view.
    • terminus_close: Closes the current terminal view.
    • terminus_close_all: Closes all open terminal views across all windows.
    • terminus_maximize: Maximizes the terminal view.
    • terminus_minimize: Minimizes the terminal view.
    • terminus_toggle_panel: Toggles the Terminus panel.
    • terminus_reset: Resets the terminal view.
    • terminus_nuke: Forcefully destroys a terminal view.

    Shell and Execution

    • terminus_exec: Executes a command in a terminal.
    • terminus_send_string: Sends a string of text to the terminal.
    • terminus_cancel_build: Cancels the current build process.
    • terminus_initialize_view: Initializes a view for terminal use.

    Clipboard and Text Interaction

    • terminus_copy: Copies text from the terminal.
    • terminus_paste: Pastes text into the terminal.
    • terminus_paste_from_history: Pastes text from the Terminus clipboard history.
    • terminus_paste_text: Pastes specific text into the terminal.
    • terminus_insert: Inserts text into the terminal.
    • terminus_delete_word: Deletes the word at the cursor (Unix-style).
    • terminus_trim_trailing_lines: Trims trailing lines in the view.

    Rendering and UI

    • terminus_render: Triggers a terminal render.
    • terminus_show_cursor: Controls cursor visibility.
    • terminus_cleanup: Performs cleanup operations.
    • terminus_rename_title: Renames the terminal title.
    • terminus_select_theme: Opens the theme selection interface.
    • terminus_generate_theme: Generates a new theme.

    Mouse and Context

    • terminus_click: Handles mouse clicks within the terminal.
    • terminus_open_context_url: Opens a URL found in the terminal context.
    • terminus_open_image: Opens an image found in the terminal context.