Skip to main content

Overview

Glass includes a fully-featured integrated terminal built on Alacritty’s terminal emulator. The terminal provides a native terminal experience with advanced features like hyperlink detection, shell integration, and seamless editor integration.

Terminal Actions

Available Commands

// From crates/terminal/src/terminal.rs
actions!(
    terminal,
    [
        Clear,
        Copy,
        Paste,
        ShowCharacterPalette,
        SearchTest,
        ScrollLineUp,
        ScrollLineDown,
        ScrollPageUp,
        ScrollPageDown,
        ScrollHalfPageUp,
        ScrollHalfPageDown,
        ScrollToTop,
        ScrollToBottom,
        SelectAll,
    ]
);
  • Copy: Copy selected text to clipboard
  • Paste: Paste from clipboard
  • SelectAll: Select all terminal content

Terminal Configuration

Environment Variables

// From insert_zed_terminal_env
pub fn insert_zed_terminal_env(
    env: &mut HashMap<String, String>,
    version: &impl std::fmt::Display,
) {
    env.insert("ZED_TERM".to_string(), "true".to_string());
    env.insert("TERM_PROGRAM".to_string(), "zed".to_string());
    env.insert("TERM".to_string(), "xterm-256color".to_string());
    env.insert("COLORTERM".to_string(), "truecolor".to_string());
    env.insert("TERM_PROGRAM_VERSION".to_string(), version.to_string());
}
Glass automatically sets terminal environment variables:

Terminal Identity

  • ZED_TERM=true: Identifies Glass terminal
  • TERM_PROGRAM=zed: Program name
  • TERM_PROGRAM_VERSION: Glass version

Capabilities

  • TERM=xterm-256color: 256 color support
  • COLORTERM=truecolor: True color support

Terminal Bounds

pub struct TerminalBounds {
    pub cell_width: Pixels,
    pub line_height: Pixels,
    pub bounds: Bounds<Pixels>,
}

impl TerminalBounds {
    pub fn num_lines(&self) -> usize
    pub fn num_columns(&self) -> usize
}
Terminal dimensions are calculated from:
  • Cell width and line height
  • Available viewport bounds
  • Font metrics from settings

Shell Integration

Task Spawning

use task::{HideStrategy, Shell, SpawnInTerminal};
Run tasks in the terminal:
  • Shell Selection: Choose bash, zsh, fish, or custom shells
  • Hide Strategy: Control terminal visibility
  • Environment: Custom environment variables
  • Working Directory: Set task working directory

Shell Environment

async fn shell_env(&self) -> Vec<(String, String)>
Glass provides shell environment through the worktree delegate:
  • Inherits system PATH
  • Includes project-specific environment
  • Merges user shell configuration
// From terminal_hyperlinks
pub struct RegexSearches {
    // URL and path detection
}

pub enum MaybeNavigationTarget {
    Url(String),
    PathLike(PathLikeTarget),
}
The terminal automatically detects:
1

URLs

HTTP, HTTPS, git, and other protocol URLs
2

File Paths

Absolute and relative file paths, including line numbers
3

Opening

Click or use Open event to navigate to links

Path Navigation

pub struct PathLikeTarget {
    pub maybe_path: String,
    pub terminal_dir: Option<PathBuf>,
}
Path detection supports:
  • Relative paths (resolved from terminal working directory)
  • Absolute paths
  • Line and column numbers: file.rs:10:5
  • Non-existent paths (for creating new files)
Cmd/Ctrl+Click on file paths to open them directly in the editor.

Terminal Events

Event System

pub enum Event {
    TitleChanged,
    BreadcrumbsChanged,
    CloseTerminal,
    Bell,
    Wakeup,
    BlinkChanged(bool),
    SelectionsChanged,
    NewNavigationTarget(Option<MaybeNavigationTarget>),
    Open(MaybeNavigationTarget),
}
The terminal emits events for:

Display Updates

  • Title changes (from shell)
  • Breadcrumb navigation changes
  • Cursor blink state changes

User Interaction

  • Selection changes
  • Navigation target detection
  • Open requests
  • Bell notifications

Terminal Lifecycle

Process Management

pub struct PtyProcessInfo {
    // Process information tracking
}

pub trait ProcessIdGetter {
    // Get process ID for terminal
}
Terminal lifecycle:
1

Spawn

Shell process is spawned with PTY
2

Active

Terminal processes input/output
3

Exit

Process exit is detected and reported
4

Cleanup

Terminal can be closed or restarted

Exit Status

pub struct TerminalError {
    pub directory: Option<PathBuf>,
    pub program: Option<String>,
    pub args: Option<Vec<String>>,
    pub title_override: Option<String>,
    pub source: std::io::Error,
}
Terminal errors provide context:
  • Working directory
  • Program and arguments
  • Custom title (if set)
  • Underlying IO error

Mouse and Keyboard

Mouse Support

// From mappings/mouse
alt_scroll,
grid_point,
mouse_button_report,
mouse_moved_report,
scroll_report,
Mouse features:
  • Click and Drag: Text selection
  • Scroll: Navigate terminal history
  • Button Reports: Mouse events sent to shell programs
  • Alt+Scroll: Alternative scrolling mode

Keyboard Input

// From mappings/keys
to_esc_str
Keyboard handling:
  • Full keyboard input support
  • Escape sequence generation
  • Modifier key support
  • Application keypad mode

Terminal Settings

Configuration Options

// From terminal_settings
pub struct TerminalSettings {
    // Terminal configuration
}

pub enum AlternateScroll {
    // Scroll behavior configuration
}

pub enum CursorShape {
    // Cursor appearance
}
Customizable settings:
  • Cursor shape (block, beam, underline)
  • Font family and size
  • Color scheme
  • Cursor blinking

Selection

Selection Types

// From Alacritty integration
use alacritty_terminal::selection::{
    Selection,
    SelectionRange,
    SelectionType,
};
Selection modes:
  • Simple: Click and drag
  • Semantic: Double-click for words
  • Lines: Triple-click for lines
  • Block: Rectangular selection

Copy Behavior

InternalEvent::Copy(Option<bool>)
  • Copy selection to clipboard
  • Optional: keep selection after copy
  • Automatic newline handling
  • Trimming whitespace

Advanced Features

Search within terminal output:
use alacritty_terminal::term::search::{
    Match,
    RegexIter,
    RegexSearch,
};
  • Regex search support
  • Navigate between matches
  • Highlight search results
  • Case-sensitive and insensitive modes

Scrollback Buffer

The terminal maintains a scrollback buffer:
  • Configurable buffer size
  • Efficient memory usage
  • Fast search and navigation
  • Persistent across clear operations

Color Support

// From mappings/colors
to_alac_rgb
Comprehensive color support:
  • 256 color palette
  • True color (24-bit RGB)
  • Theme integration
  • Custom color schemes

Integration with Editor

Working Directory

The terminal tracks the current working directory:
  • Used for relative path resolution
  • Hyperlink navigation
  • Task spawning
  • Editor-terminal synchronization
Event::BreadcrumbsChanged
Breadcrumb navigation shows:
  • Current working directory
  • Active shell
  • Running processes

Opening Files

Seamless integration with the editor:
1

Detect

Terminal detects file paths in output
2

Hover

Paths are highlighted on hover
3

Click

Click to open file in editor
4

Navigate

Jump to specific line/column if specified
File paths like src/main.rs:42:10 will open the file at line 42, column 10.

Best Practices

Terminal Usage

  • Use multiple terminal instances for different tasks
  • Leverage shell integration for tasks
  • Configure shell RC files to customize environment
  • Use hyperlinks for quick file navigation

Performance

  • Terminal rendering is optimized for large outputs
  • Scrollback buffer is memory-efficient
  • Regex search is lazy and fast
  • Color rendering uses GPU acceleration
Very long lines (>1024 characters) may impact terminal performance.

Build docs developers (and LLMs) love