Installation
Enable theterminal feature in your Cargo.toml:
Basic Usage
Features
- PTY Integration: Spawn and interact with shell processes
- VT100 Rendering: Full terminal emulation with cursor, colors, and text attributes
- 256-Color Support: ANSI 16 colors, 6x6x6 RGB cube, and 24-level grayscale
- Keyboard Input: Handle all standard terminal key sequences
- Auto-resize: Terminal automatically resizes based on available space
- Mouse Support: Full mouse event handling (click, drag, scroll)
- Text Selection: Select and copy terminal text
Setting Up a Terminal
Creating a Terminal Handle
Different Shells
Handling Terminal Events
Keyboard Input
Handle keyboard events and send input to the terminal:Mouse Events
Detecting Terminal Exit
Useuse_future to detect when the terminal process exits:
Window Title Integration
Update the window title based on terminal output:Multiple Terminals
Create multiple terminal instances using unique IDs:Key Types
TerminalHandle
Manages the terminal process and PTY:write(bytes)- Send input to the terminalclosed()- Future that resolves when terminal exitstitle()- Get current terminal titletitle_changed()- Future that resolves on title changeget_selected_text()- Get currently selected textmouse_down(),mouse_up(),mouse_move()- Mouse interactionshift_pressed(bool)- Track shift key state for selection
TerminalId
Unique identifier for terminal instances:CommandBuilder
From theportable_pty crate, used to configure the shell:
Example: Full Terminal Application
See thefeature_terminal.rs example in the repository for a complete implementation with:
- Keyboard handling (including copy/paste)
- Mouse support (selection, clicking, scrolling)
- Window title updates
- Terminal exit detection
- Focus management